Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

InfluxDB: Parse data for table view to have parity with frontend parser #78365

Merged
merged 10 commits into from
Nov 22, 2023

Conversation

itsmylife
Copy link
Contributor

@itsmylife itsmylife commented Nov 18, 2023

What is this feature?

InfluxDB has a frontend response parser which will be not used as we are moving towards backend migration. This means the query will be fetched and parsed on the backend and will return as DataFrame.
The current data format is compatible with timeseries but not with the table view %100.
Users have to use transformations and other techniques to reach to same view as they had before.
This is a tedious process to go through. This PR is resolving that by adding a separate parsing logic for table view.

Part of #65045

Frontend Mode
image

Backend Mode before PR
image

Backend Mode after PR
image

Why do we need this feature?

To have parity with frontend parser and no breaking changes while having influxdbBackendMigration feature toggle enabled.

Who is this feature for?

InfluxDB influxql users who have table views in their dashboards

How to test

dashboard.json for testing
{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 8,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "datasource": {
        "type": "influxdb",
        "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "id": 8,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.5.13",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
          },
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SHOW MEASUREMENTS",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "show measurements",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "id": 7,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.5.13",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
          },
          "query": "SHOW RETENTION POLICIES on \"mybucket\"",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "table"
        }
      ],
      "title": "show retention policies",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 8
      },
      "id": 5,
      "interval": "20m",
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.5.13",
      "targets": [
        {
          "alias": "$tag_cpu",
          "datasource": {
            "type": "influxdb",
            "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
          },
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "cpu::tag"
              ],
              "type": "tag"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"usage_idle\") FROM \"default\".\"cpu\" WHERE (\"host\"::tag = '41c9dcf3b960') AND $timeFilter GROUP BY time($__interval), \"cpu\"::tag fill(null)",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "usage_idle"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host::tag",
              "operator": "=",
              "value": "41c9dcf3b960"
            }
          ]
        }
      ],
      "title": "select mean where host and group by cpu tag",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 8
      },
      "id": 6,
      "interval": "20m",
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.5.13",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
          },
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "usage_idle"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "no tags",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 16
      },
      "id": 4,
      "interval": "1m",
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.5.13",
      "targets": [
        {
          "alias": "fsdsfdsfdsdfsfd",
          "datasource": {
            "type": "influxdb",
            "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
          },
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "processes",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT * FROM \"default\".\"cpu\" WHERE (\"host\"::tag = '41c9dcf3b960') AND $timeFilter",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "load15"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host::tag",
              "operator": "=",
              "value": "41c9dcf3b960"
            }
          ]
        }
      ],
      "title": "select * from cpu where tag is something",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 7,
        "w": 24,
        "x": 0,
        "y": 24
      },
      "id": 3,
      "interval": "1m",
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.5.13",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
          },
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "diskio",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "*"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "name::tag",
              "operator": "=",
              "value": "vda"
            }
          ]
        }
      ],
      "title": "select * with mean",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 31
      },
      "id": 1,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.5.13",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
          },
          "groupBy": [],
          "hide": false,
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"usage_idle\"), min(\"usage_idle\"), PERCENTILE(\"usage_idle\", 90) as p90, PERCENTILE(\"usage_idle\", 95) as p95, max(\"usage_idle\") as max FROM \"cpu\" WHERE (\"host\"::tag = '41c9dcf3b960') and $timeFilter GROUP BY \"cpu\" fill(null)",
          "rawQuery": true,
          "refId": "B",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "usage_idle"
                ],
                "type": "field"
              }
            ],
            [
              {
                "params": [
                  "usage_iowait"
                ],
                "type": "field"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "select with where host and group by cpu (rawQuery)",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 31
      },
      "id": 2,
      "interval": "1m",
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.5.13",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "a712866b-d847-499b-9875-72c06f0eceeb"
          },
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "usage_idle"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              },
              {
                "params": [
                  "idle_mean"
                ],
                "type": "alias"
              }
            ],
            [
              {
                "params": [
                  "usage_iowait"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              },
              {
                "params": [
                  "iowait_mean"
                ],
                "type": "alias"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "two select with alias group by time fill null",
      "type": "table"
    }
  ],
  "refresh": "",
  "schemaVersion": 38,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "2023-11-15T11:00:00.000Z",
    "to": "2023-11-15T12:00:00.000Z"
  },
  "timepicker": {},
  "timezone": "",
  "title": "influx table investigation with frontend parser",
  "uid": "a73e531a-e843-498a-a9e3-29f230a91ee6",
  "version": 14,
  "weekStart": ""
}
  • Set influxdbBackendMigration feature toggle false
  • Create a dashboard with influxql which has table.
    • Make it complex so you might catch something I missed
  • Enable influxdbBackendMigration feature toggle
  • See the view is not same
  • Switch to this branch and refresh
  • The view should be the same as it was before.

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

Copy link
Contributor

Hello @itsmylife!
Backport pull requests need to be either:

  • Pull requests which address bugs,
  • Urgent fixes which need product approval, in order to get merged,
  • Docs changes.

Please, if the current pull request addresses a bug fix, label it with the type/bug label.
If it already has the product approval, please add the product-approved label. For docs changes, please add the type/docs label.
If the pull request modifies CI behaviour, please add the type/ci label.
If none of the above applies, please consider removing the backport label and target the next major/minor release.
Thanks!

@itsmylife itsmylife marked this pull request as ready for review November 19, 2023 15:53
@itsmylife itsmylife requested a review from a team as a code owner November 19, 2023 15:53
@gtk-grafana gtk-grafana requested review from gtk-grafana and kylebrandt and removed request for gtk-grafana November 20, 2023 14:10
@tolzhabayev tolzhabayev added the product-approved Pull requests that are approved by product/managers and are allowed to be backported label Nov 20, 2023
return &v
}

const tableResultFormatInfluxResponse1 = `{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use the pattern we use in prom here for testing with the json test_data files. I don't think it is a blocker on the PR, but we should probably make an issue to update the tests in this DS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good call. I will also refactor the time_series parsing since we have a lot of duplicate code with this PR. When I do that, I will refactor testing too. I'll create an issue for myself to track this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsmylife itsmylife merged commit c5f3ce1 into main Nov 22, 2023
16 checks passed
@itsmylife itsmylife deleted the ismail/influxdb-table-response-data-format branch November 22, 2023 18:27
grafana-delivery-bot bot pushed a commit that referenced this pull request Nov 22, 2023
…er (#78365)

* Use TimeSeriesWide format for table response

* fix group by query result parsing

* handle labels

* provide a test where result has no tags

* parsing results without time column

* clean the code

* remove the comment line

* more cleaning

* lint

(cherry picked from commit c5f3ce1)
itsmylife added a commit that referenced this pull request Nov 22, 2023
…ntend parser (#78551)

InfluxDB: Parse data for table view to have parity with frontend parser (#78365)

* Use TimeSeriesWide format for table response

* fix group by query result parsing

* handle labels

* provide a test where result has no tags

* parsing results without time column

* clean the code

* remove the comment line

* more cleaning

* lint

(cherry picked from commit c5f3ce1)

Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
eleijonmarck pushed a commit that referenced this pull request Nov 27, 2023
…er (#78365)

* Use TimeSeriesWide format for table response

* fix group by query result parsing

* handle labels

* provide a test where result has no tags

* parsing results without time column

* clean the code

* remove the comment line

* more cleaning

* lint
@aangelisc aangelisc modified the milestones: 10.3.x, 10.2.3 Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/backend backport v10.2.x datasource/InfluxDB product-approved Pull requests that are approved by product/managers and are allowed to be backported type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants