grafana / grafonnet

Jsonnet library for generating Grafana dashboards.
https://grafana.github.io/grafonnet/
Apache License 2.0
322 stars 19 forks source link

Error for Unexpected String in dashboard.new title Field #132

Closed sulli204 closed 9 months ago

sulli204 commented 9 months ago

Hiya, I'm not quite sure if this is a jsonnet issue or a grafonnet issue, so I'll start here.

Problem

I'm passing in a title to dashboard.new() like below:

# dashboard.jsonnet

local g = import '../../grafana.libsonnet';
local CONSTANTS = '../constants.libsonnet';
local uids = import '../uids.libsonnet';
local ec2 = import './panels/ec2_metrics.libsonnet';

local create_dashboard(region = "multi_staging_marketing") =
  local region_constants = CONSTANTS.regions[region];
  {
    folderUid: uids.regions[region].folder,
    overwrite: true,
    dashboard: g.dashboard.new(region_constants.name + " - EC2 Metrics")
    + g.dashboard.withTimezone("browser")
    + g.dashboard.graphTooltip.withSharedCrosshair()
    + g.dashboard.withPanels(
      ec2.cpu(region)
    )
  };

{
  "multi-staging-marketing-ec2.json": create_dashboard("multi_staging_marketing")
}

and I'm getting an error that I'm passing in an unexpected string and that it expects a number:

Screenshot 2023-09-26 at 2 19 56 PM

NOTE: The way in which I'm passing through the name of the region and env has been done in other dashboard.jsonnet files and they compile and run just fine. This seems to be an exception of some sort.

I have a constants.libsonnet file that holds all of the identifying information for each region and environment that gets passed through to our dashboard.jsonnet files. It looks like this (the ellipsis redacting sensitive info):

# constants.libsonnet

{
  regions: {
    prod_apac: {
      name: "Prod-APAC",
      ...
    },
    staging_apac: {
      name: "Staging-APAC",
      ...
    },
    staging_eu: {
      name: "Staging-EU",
      ...
    },
    multi_staging_marketing: {
      name: "Multi-Staging Marketing",
      ...
    }
  }
}

I can pass in the title explicitly like so g.dashboard.new("Multi-staging Marketing EC2 Metrics") and it works just fine. Has anyone ran into an issue like this: passing in a typed value to an object that is expecting that type but on runtime is expecting a different type?

Duologic commented 9 months ago

This misses an import statement:

-local CONSTANTS = '../constants.libsonnet';
+local CONSTANTS = import '../constants.libsonnet';
sulli204 commented 9 months ago

😔 ah thanks! Thought I scanned over the file thoroughly.