grafanalib icon indicating copy to clipboard operation
grafanalib copied to clipboard

TimeSeries min, max

Open baryluk opened this issue 2 years ago • 1 comments

We are migrating about 40 dashboards from Graph to TimeSeries, and created wrapper that converts things, like this:

def G(*args, **kwargs):
    if OLD_GRAFANA:
        return Graph(*args, **kwargs)
    if "stack" in kwargs:
        if kwargs.pop("stack"):
            kwargs["stacking"] = {"mode": "normal"}
    if "yAxes" in kwargs:
        yAxes = kwargs.pop("yAxes")

        if yAxes.left.label is not None:
            kwargs["axisLabel"] = yAxes.left.label

        if yAxes.left.min is not None:
            pass # ???
        if yAxes.left.max is not None:
            pass # ???

        if yAxes.left.format:
            kwargs["unit"] = yAxes.left.format
        if yAxes.left.logBase and yAxes.left.logBase != 1:
            kwargs["scaleDistributionType"] = "log"
            kwargs["scaleDistributionLog"] = yAxes.left.logBase
    return TimeSeries(*args, **kwargs)

But i noticed that TimeSeries does not provide min, max, softMin and softMax.

If in Grafana UI, I click "Migrate", I got these fieldConfig:

      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "Latency",
            "axisPlacement": "auto",
            "axisSoftMin": 0,
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "stepAfter",
            "lineWidth": 2,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "never",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "links": [],
          "mappings": [],
          "max": 1e-7,
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "s"
        },
        "overrides": []
      },

So I see there are options for these things.

baryluk avatar Mar 15 '22 21:03 baryluk

As a workaround:

...
        if yAxes.left.min is not None:
            kwargs.setdefault("extraJson", {}).setdefault("fieldConfig", {}).setdefault("defaults", {})["min"] = yAxes.left.min

        if yAxes.left.max is not None:
            kwargs.setdefault("extraJson", {}).setdefault("fieldConfig", {}).setdefault("defaults", {})["max"] = yAxes.left.max

...

baryluk avatar Mar 15 '22 22:03 baryluk