Dynamic maxDataPoints based on time ranges

  • What Grafana version and what operating system are you using?
    Grafana v9.0.3 (023f9251a9)

  • What are you trying to achieve?
    Adjust maxDataPoints based on the time range. Currently you can only set maxDataPoints to a fixed value or auto. This is not flexible since I need a maxDataPoints of 100 on high time ranges and 300 on shorter ones. Otherwise if set to auto then the value is much higher than desired and the dashboard fails to load

  • How are you trying to achieve it?
    I use fixed value MaxDataPoints

  • What happened?
    Very slow on long time ranges

  • What did you expect to happen?
    Should load faster

  • Can you copy/paste the configuration(s) that you are having problems with?

{
  "id": 6,
  "gridPos": {
    "h": 8,
    "w": 24,
    "x": 0,
    "y": 9
  },
  "type": "timeseries",
  "title": "Message Rate by Topic",
  "datasource": {
    "type": "elasticsearch"
  },
  "pluginVersion": "9.0.3",
  "maxDataPoints": 200,
  "description": "One Minute Rate",
  "fieldConfig": {
    "defaults": {
      "custom": {
        "drawStyle": "line",
        "lineInterpolation": "linear",
        "barAlignment": 0,
        "lineWidth": 1,
        "fillOpacity": 10,
        "gradientMode": "none",
        "spanNulls": false,
        "showPoints": "never",
        "pointSize": 5,
        "stacking": {
          "mode": "normal",
          "group": "A"
        },
        "axisPlacement": "auto",
        "axisLabel": "Messages Per Second",
        "scaleDistribution": {
          "type": "linear"
        },
        "hideFrom": {
          "tooltip": false,
          "viz": false,
          "legend": false
        },
        "thresholdsStyle": {
          "mode": "off"
        }
      },
      "color": {
        "mode": "palette-classic"
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "decimals": 0,
      "min": 0,
      "unit": "short"
    },
    "overrides": []
  },
  "options": {
    "tooltip": {
      "mode": "multi",
      "sort": "none"
    },
    "legend": {
      "displayMode": "hidden",
      "placement": "right",
      "calcs": []
    }
  },
  "targets": [
    {
      "alias": "",
      "bucketAggs": [
        {
          "field": "labels.topic",
          "id": "2",
          "settings": {
            "min_doc_count": "1",
            "order": "desc",
            "orderBy": "1",
            "size": "20"
          },
          "type": "terms"
        },
        {
          "field": "@timestamp",
          "id": "3",
          "settings": {
            "interval": "auto",
            "min_doc_count": "1",
            "trimEdges": "0"
          },
          "type": "date_histogram"
        }
      ],
      "hide": false,
      "metrics": [
        {
          "field": "kafka.topic.MessagesInPerSec.OneMinuteRate",
          "id": "1",
          "settings": {},
          "type": "sum"
        }
      ],
      "query": "environment:prod AND _exists_:kafka.topic.MessagesInPerSec.OneMinuteRate AND -labels.topic:_* AND labels.topic:$topic",
      "queryType": "randomWalk",
      "refId": "A",
      "timeField": "@timestamp",
      "datasource": {
        "type": "elasticsearch"
      }
    }
  ],
  "timeFrom": null,
  "timeShift": null,
  "transparent": true,
  "interval": null
}
- name: Elastic
  type: elasticsearch
  access: proxy
  url: host
  database: "es-*"
  withCredentials: false
  isDefault: false
  version: 1
  editable: false
  basicAuth: true
  jsonData:
    maxConcurrentShardRequests: 2048
    tlsSkipVerify: true
    timeField: "@timestamp"
    timeout: 900

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    too_many_buckets_exception on longer time ranges. Which I need to lower for those ranges.
  • Did you follow any online instructions? If so, what is the URL?
    N/A