Skip to content

Problem fetching Dashboard(s). Error: An item with the same key has already been added. Key: Server #420

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
pryansancsoft opened this issue Nov 23, 2022 · 3 comments · Fixed by #426
Labels
bug Something isn't working
Milestone

Comments

@pryansancsoft
Copy link

I am attempting to get a specific Dashboard by ID and obtain all of the Cell information within it. I am getting a dictionary insert error when trying to get a valid Dashboard by ID.

Steps to reproduce:
Using the following code is enough for me to reproduce.

public async Task QueryAsync(string dashboardId)
{
    using(InfluxDBClient client = InfluxDBClientFactory.Create(_url, _token))
    {
        DashboardsService dashboardService = client.CreateService<DashboardsService>(typeof(DashboardsService));
        // Error occurs here
        Dashboard dashboard = await dashboardService.GetDashboardsIDAsync(dashboardId);
        // Same Error Here
        // Dashboards dashboards = await dashboardService.GetDashboardsAsync(orgID: _org, id: new List<string> { dashboardId }, limit: 1);
        // Dashboard dashboard = dashboards._Dashboards.FirstOrDefault();

        if(dashboard != null)
        {
            foreach(Cell cell in dashboard.Cells)
            {
                // Do Something
            }
        }
    }
}

Expected behavior:
Obtain all Cells for a specific Dashboard.

Actual behavior:
The following error is received:

ArgumentException: An item with the same key has already been added. Key: Server

System.Collections.Generic.Dictionary<TKey, TValue>.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
System.Collections.Generic.Dictionary<TKey, TValue>.Add(TKey key, TValue value)
System.Linq.Enumerable.ToDictionary<TSource, TKey, TElement>(List<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
System.Linq.Enumerable.ToDictionary<TSource, TKey, TElement>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
InfluxDB.Client.Api.Service.DashboardsService.GetDashboardsIDAsyncWithHttpInfo(string dashboardID, string zapTraceSpan, string include, CancellationToken cancellationToken)
InfluxDB.Client.Api.Service.DashboardsService.GetDashboardsIDAsync(string dashboardID, string zapTraceSpan, string include, CancellationToken cancellationToken)
DashboardChartService.Services.InfluxDBService.QueryAsync(QueryViewModel queryViewModel) in InfluxDBService.cs
+
            Dashboard dashboard = await dashboardService.GetDashboardsIDAsync(queryViewModel.DashboardId);
DashboardChartService.Controllers.PDFController.PDF() in PDFController.cs
+
        return View(new PDFViewModel(await _influxDBService.QueryAsync(new QueryViewModel
lambda_method21(Closure , object )
...

Specifications:

  • Client Version: IndluxDB.Client 4.7.0
  • InfluxDB Version: v2.3.0+SNAPSHOT.090f681737
  • Platform: Windows .net core 6.0

I am also using the following code, which does work:

using(InfluxDBClient client = InfluxDBClientFactory.Create(_url, _token))
{
    return await client.GetQueryApi().QueryRawAsync(queryString, org: _org);
}
@bednar
Copy link
Contributor

bednar commented Nov 25, 2022

Hi @pryansancsoft,

thanks for using our client.

I am not able to simulate your error with my dashboards.

Can you export and share your dashboard?

Regards

@bednar bednar added the question Further information is requested label Nov 25, 2022
@pryansancsoft
Copy link
Author

I don't think this will help, but you can find it below. I have also discovered that using other services results in the same issue.

Such as the following:

PingService pingService = client.CreateService<PingService>(typeof(PingService));
pingService.GetPing();

Below is the export of a Dashboard, however this happens for all of them.

{
  "meta": {
    "version": "1",
    "type": "dashboard",
    "name": "Testing (clone 1)-Template",
    "description": "template created from dashboard: Testing (clone 1)"
  },
  "content": {
    "data": {
      "type": "dashboard",
      "attributes": {
        "name": "Testing (clone 1)",
        "description": ""
      },
      "relationships": {
        "label": {
          "data": [
            {
              "type": "label",
              "id": "0a543e6d00c7b000"
            }
          ]
        },
        "cell": {
          "data": [
            {
              "type": "cell",
              "id": "0a5bab634ca66000"
            }
          ]
        },
        "variable": {
          "data": []
        }
      }
    },
    "included": [
      {
        "type": "label",
        "id": "0a543e6d00c7b000",
        "attributes": {
          "name": "test",
          "properties": {
            "color": "#326BBA",
            "description": ""
          }
        }
      },
      {
        "id": "0a5bab634ca66000",
        "type": "cell",
        "attributes": {
          "x": 0,
          "y": 0,
          "w": 4,
          "h": 4
        },
        "relationships": {
          "view": {
            "data": {
              "type": "view",
              "id": "0a5bab634ca66000"
            }
          }
        }
      },
      {
        "type": "view",
        "id": "0a5bab634ca66000",
        "attributes": {
          "name": "HPCV-A SG Mean",
          "properties": {
            "shape": "chronograf-v2",
            "queries": [
              {
                "text": "from(bucket: \"socotec\")\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n  |> filter(fn: (r) => r[\"_measurement\"] == \"SG Mean\")\n  |> filter(fn: (r) => r[\"_field\"] == \"rms\")\n  |> filter(fn: (r) => r[\"channel\"] == \"HPCV-A SG1500\")\n  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n  |> yield(name: \"mean\")",
                "editMode": "advanced",
                "name": "",
                "builderConfig": {
                  "buckets": [],
                  "tags": [
                    {
                      "key": "_measurement",
                      "values": [],
                      "aggregateFunctionType": "filter"
                    }
                  ],
                  "functions": [
                    {
                      "name": "mean"
                    }
                  ],
                  "aggregateWindow": {
                    "period": "auto",
                    "fillValues": false
                  }
                }
              }
            ],
            "axes": {
              "x": {
                "bounds": [
                  "",
                  ""
                ],
                "label": "",
                "prefix": "",
                "suffix": "",
                "base": "10",
                "scale": "linear"
              },
              "y": {
                "bounds": [
                  "",
                  ""
                ],
                "label": "",
                "prefix": "",
                "suffix": "",
                "base": "10",
                "scale": "linear"
              }
            },
            "type": "xy",
            "staticLegend": {
              "colorizeRows": true,
              "opacity": 1,
              "orientationThreshold": 100000000,
              "widthRatio": 1
            },
            "geom": "line",
            "colors": [
              {
                "id": "1a459ca5-3d81-4e74-b69a-547b86afdbab",
                "type": "scale",
                "hex": "#31C0F6",
                "name": "Nineteen Eighty Four",
                "value": 0
              },
              {
                "id": "d8cd3801-b14e-4628-96e8-1125569bce44",
                "type": "scale",
                "hex": "#A500A5",
                "name": "Nineteen Eighty Four",
                "value": 0
              },
              {
                "id": "be1292c4-4656-4cd0-8e9c-2577d59698ec",
                "type": "scale",
                "hex": "#FF7E27",
                "name": "Nineteen Eighty Four",
                "value": 0
              }
            ],
            "note": "",
            "showNoteWhenEmpty": false,
            "xColumn": "_time",
            "generateXAxisTicks": [],
            "xTotalTicks": 0,
            "xTickStart": 0,
            "xTickStep": 0,
            "yColumn": "_value",
            "generateYAxisTicks": [],
            "yTotalTicks": 0,
            "yTickStart": 0,
            "yTickStep": 0,
            "shadeBelow": false,
            "position": "overlaid",
            "timeFormat": "",
            "hoverDimension": "auto",
            "legendColorizeRows": true,
            "legendHide": false,
            "legendOpacity": 1,
            "legendOrientationThreshold": 100000000
          }
        }
      }
    ]
  },
  "labels": []
}

@bednar
Copy link
Contributor

bednar commented Nov 30, 2022

@pryansancsoft thanks for clarification. It looks like that the problem is caused by duplicated HTTP headers in response from InfluxDB.

Do you use a HTTP proxy before the InfluxDB? Can you print out the HTTP headers from response?

curl -i -X GET http://0.0.0.0:9999/ping

@bednar bednar added this to the 4.8.0 milestone Nov 30, 2022
@bednar bednar removed the question Further information is requested label Nov 30, 2022
@bednar bednar added the bug Something isn't working label Nov 30, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants