andymchugh / andrewbmchugh-flow-panel

Apache License 2.0
34 stars 2 forks source link

dataRef AliasTags #55

Closed netforce closed 4 months ago

netforce commented 4 months ago

We have been using the flowcharting plugin for quite some time, but now we want to switch to the flow plugin.

We have a query with tags like 'host' and 'interface' to get measurements from influxdb, instead of doing a query per switch, per interface. But we are unable to reference the wanted tag on a Cell, because the dataRef only expects one result, with maybe a timeline. Not tagged results.

It would be a big inprovement when we can reference a tag after a 'dataRef', or select a tag after the dataRef.

example below;

cells:
 cell-one:
   dataRef: "Query-A-series:InterfaceTag"

Or to use a new yaml definition

cells:
 cell-one:
   dataRef: "Query-A-series"
   tag: "InterfaceTag"

Also within other defenitions in the yaml we would like to be able to use the tags defined in the query, like in URL's.

cells:
  cell-one:
  link:
    url: "https://grafana.com/interfaceDashboard?var-host=[[tag_host]]&var-port=[[tag_port]]"
andymchugh commented 4 months ago

Can you press the 'Debugging Data' button and attach the resulting console log so I can see what your data looks like 'raw' and 'enriched'? I don't have an influxdb setup to explore so need to see what's arriving at the panel to be able to comment.

netforce commented 4 months ago

Both, partial, expanded logs attached. My guess would be that "labels" contain the values used by the "Alias By" from the timeseries query. ScreenShot27052024_082455 In this case i have limited the query to only one host, but the original query was gathering data for all the switches "host" =~ /core-sw1*/ grafana.test.bit.nl-enriched.log grafana.test.bit.nl-raw.log

Let me know if you need something more specific, i'l try to get the full expanded logs without to much crap but the debug console is giving me a hard time.

andymchugh commented 4 months ago

I'm trying to understand how this 'tag' information shows up in the raw data and what it looks like after passing it through grafanas toDataFrame function. I would expect every time-series to have a unique name by the time it gets to me but I think you are saying you have many timeseries with the same name, each with it's own separately defined tag. I can't see that in the data you've sent though.

I guess I'm just not understanding the ask yet. Could you restate it with simpler attachments that show the problem you are facing? i.e. when I search for 'tag' in the attachments I don't see anything. I don't think you say what the tag value should be in the attachments so I can't search for that either.

netforce commented 4 months ago

we have a timeseries influxdb database where 2 devices with almost the same name are writing data. In this example case the devices are named "oeo1.bit-1 and oeo1.bit-2, and writing the same value in this influx database.

We can do a query to select the value, 'oeo.chassis.power1State' for all matching hosts at once; SELECT "value" FROM "oeo.chassis.power1State" WHERE ("host" =~ /^oeo1.bit-*/) AND $timeFilter GROUP BY "host" This query has the 'Alias by' setting of ThisIsATag-[[tag_host]] which tags every result with the string+[[hostname]] from the query. In this case the tags 'ThisIsATag-oeo1.bit-1.oob.dmz.bit.nl' and 'ThisIsATag-oeo1.bit-2a.oob.dmz.bit.nl'

This wil give us the data attached in the CSV

Now we can add this measurement to a panel referring to the complete name/tag 'ThisIsATag-oeo1.bit-1.oob.dmz.bit.nl' of ThisIsATag-oeo1.bit-2a.oob.dmz.bit.nl

I hope the paneldata and dataFrames below are helpfull.

The paneldata json;

    {
      "datasource": {
        "type": "influxdb",
        "uid": "000000010"
      },
      "refId": "C",
      "hide": false,
      "query": "SELECT \"value\" FROM \"oeo.chassis.power1State\" WHERE (\"host\" =~ /^oeo1.bit-*/) AND  $timeFilter GROUP BY \"host\"",
      "rawQuery": true,
      "alias": "ThisIsATag-[[tag_host]]",
      "resultFormat": "time_series",
      "policy": "default",
      "orderByTime": "ASC",
      "tags": [
        {
          "key": "host::tag",
          "value": "^/oeo1.bit-*/",
          "operator": "="
        }
      ],
      "groupBy": [
        {
          "type": "time",
          "params": [
            "$__interval"
          ]
        },
        {
          "type": "tag",
          "params": [
            "host::tag"
          ]
        },
        {
          "type": "fill",
          "params": [
            "null"
          ]
        }
      ],
      "select": [
        [
          {
            "type": "field",
            "params": [
              "value"
            ]
          },
          {
            "type": "mean",
            "params": []
          }
        ]
      ],
      "measurement": "oeo.chassis.power1State"
    },

The Query Inspector output;

{
  "request": {
    "url": "api/ds/query?ds_type=influxdb&requestId=mixed-3-Q594",
    "method": "POST",
    "data": {
      "queries": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "000000010"
          },
          "refId": "C",
          "hide": false,
          "query": "SELECT \"value\" FROM \"oeo.chassis.power1State\" WHERE (\"host\" =~ /^oeo1.bit-*/) AND  $timeFilter GROUP BY \"host\"",
          "rawQuery": true,
          "alias": "ThisIsATag-[[tag_host]]",
          "resultFormat": "time_series",
          "policy": "default",
          "orderByTime": "ASC",
          "tags": [
            {
              "key": "host::tag",
              "value": "^/oeo1.bit-*/",
              "operator": "="
            }
          ],
          "groupBy": [
            {
              "type": "time",
              "params": [
                "$__interval"
              ]
            },
            {
              "type": "tag",
              "params": [
                "host::tag"
              ]
            },
            {
              "type": "fill",
              "params": [
                "null"
              ]
            }
          ],
          "select": [
            [
              {
                "type": "field",
                "params": [
                  "value"
                ]
              },
              {
                "type": "mean",
                "params": []
              }
            ]
          ],
          "measurement": "oeo.chassis.power1State",
          "adhocFilters": [],
          "rawSql": "",
          "limit": "",
          "slimit": "",
          "tz": "",
          "datasourceId": 10,
          "intervalMs": 500,
          "maxDataPoints": 800
        }
      ],
      "from": "1716816600000",
      "to": "1716816900000"
    },
    "hideFromInspector": false
  },
  "response": {
    "results": {
      "C": {
        "status": 200,
        "frames": [
          {
            "schema": {
              "name": "ThisIsATag-oeo1.bit-1.oob.dmz.bit.nl",
              "refId": "C",
              "meta": {
                "typeVersion": [
                  0,
                  0
                ],
                "preferredVisualisationType": "graph",
                "executedQueryString": "SELECT \"value\" FROM \"oeo.chassis.power1State\" WHERE (\"host\" =~ /^oeo1.bit-*/) AND  time >= 1716816600000ms and time <= 1716816900000ms GROUP BY \"host\""
              },
              "fields": [
                {
                  "name": "Time",
                  "type": "time",
                  "typeInfo": {
                    "frame": "time.Time"
                  }
                },
                {
                  "name": "Value",
                  "type": "number",
                  "typeInfo": {
                    "frame": "float64",
                    "nullable": true
                  },
                  "labels": {
                    "host": "oeo1.bit-1.oob.dmz.bit.nl"
                  },
                  "config": {
                    "displayNameFromDS": "ThisIsATag-oeo1.bit-1.oob.dmz.bit.nl"
                  }
                }
              ]
            },
            "data": {
              "values": [
                [
                  1716816600657,
                  1716816628074,
                  1716816653201,
                  1716816678234,
                  1716816705457,
                  1716816730470,
                  1716816757895,
                  1716816782887,
                  1716816808014,
                  1716816833054,
                  1716816857991,
                  1716816885414
                ],
                [
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1
                ]
              ]
            }
          },
          {
            "schema": {
              "name": "ThisIsATag-oeo1.bit-2a.oob.dmz.bit.nl",
              "refId": "C",
              "fields": [
                {
                  "name": "Time",
                  "type": "time",
                  "typeInfo": {
                    "frame": "time.Time"
                  }
                },
                {
                  "name": "Value",
                  "type": "number",
                  "typeInfo": {
                    "frame": "float64",
                    "nullable": true
                  },
                  "labels": {
                    "host": "oeo1.bit-2a.oob.dmz.bit.nl"
                  },
                  "config": {
                    "displayNameFromDS": "ThisIsATag-oeo1.bit-2a.oob.dmz.bit.nl"
                  }
                }
              ]
            },
            "data": {
              "values": [
                [
                  1716816600655,
                  1716816628067,
                  1716816653193,
                  1716816678230,
                  1716816705456,
                  1716816730476,
                  1716816757896,
                  1716816782886,
                  1716816808009,
                  1716816833054,
                  1716816857986,
                  1716816885413
                ],
                [
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1,
                  1
                ]
              ]
            }
          }
        ],
        "refId": "C"
      }
    }
  }
}

[ post updated to identify tag fields]

andymchugh commented 4 months ago

Thanks. That's helpful. Looking at it I'd expect two dataRefs to be available to you named 'oeo1.bit-2a.oob.dmz.bit.nl' and 'oeo1.bit-1.oob.dmz.bit.nl'. That appears to be what you are after and I think that's what I'd expect you to see. So what are the data names that you actually see when you press 'Debugging Data' with the above query?

And can you also confirm you are on the latest panel version. There were changes in this space in version 1.4? If you aren't sure, check you are able to pan/zoom and the controls allow you to enable Pan/Zoom. That turned up in version 1.9

andymchugh commented 4 months ago

Also, an improvement to the docs from Thibault GODOUET regarding how dataRefs are named has just been made:

https://github.com/andymchugh/andrewbmchugh-flow-panel/pull/58/files#diff-12c25df68e8e7b50b90b949c3d7f95037a515cbf42481b9955a173a873af6dbdR137

Just posting as it mentions influxdb and seems related to what you are asking?

netforce commented 4 months ago

well, that explains a lot, and works as expected :dancers:

I had defined "dataRef: "<queryname>-series" which got me only the first value returned by that query, so i needed a way t select the next/tagged value.

This is the clarification in the docs that was missing/misinterpreted :) Together we will get this plugin better :)

netforce commented 4 months ago

Thanks. That's helpful. Looking at it I'd expect two dataRefs to be available to you named 'oeo1.bit-2a.oob.dmz.bit.nl' and 'oeo1.bit-1.oob.dmz.bit.nl'. That appears to be what you are after and I think that's what I'd expect you to see. So what are the data names that you actually see when you press 'Debugging Data' with the above query?

ScreenShot28052024_091128

The "name" are indeed the ones i expected, and can be referenced in the yaml.

And can you also confirm you are on the latest panel version. There were changes in this space in version 1.4? If you aren't sure, check you are able to pan/zoom and the controls allow you to enable Pan/Zoom. That turned up in version 1.9

Yes i have pan/zoom enable option.

ScreenShot28052024_090809

The only thing we are missing (or overlooking) now is the use of the Alias Tags in the yaml to generate dynamic URL's.

andymchugh commented 4 months ago

great, that remaining item is actually covered by https://github.com/andymchugh/andrewbmchugh-flow-panel/issues/49. If that's all that remains can we close this as a duplicate and you put this ask on the other issue. I'm not sure alias tags is viable in that space; it will depend on what grafana dataframe accessors exist. But I can check when looking at the other issue.