Skip to content

monitoring generator: replace ContainerVariable with separate function constructors + use interval variables in search-blitz

Administrator requested to merge interval-var into main

Created by: ggilmore

This PR does two major things:

  1. It rips out the monitoring.ContainerVariable abstraction in favor of separate friendly helper functions that generate sdk.TemplateVars directly:

    • Different Grafana variable types have conflicting needs and requirements that that can't be meshed together cleanly in a sum type like monitoring.ContainerVariablewas going to turn out to be. Consider the interval variable type that I wanted to add. The notion of an "All" value or "multiple selection" doesn't really make sense with time intervals, but the logic in toGrafanaTemplateVar hard-codes this. The logic to handle this correctly would be messy because it needs to consider all possible states of monitoring.ContainerVariable's fields.
      • The end result of continuing to use monitoring.ContainerVariable would be basically a "pass-through" type that would end up duplicating most/all of the underlying fields of sdk.TemplateVariable with no added functionality.
      • Using separate helper functions for different kinds variables makes the logic much nicer. We can assume the user's intent (I want make a selector using a query / I want to populate a selector with time intervals) without having to consider all possible states of what the fields of monitoring.ContainerVariable could be in. This lets us do things like ignore checking to see which of the sub-fields are populated before we know what the value of TemplateVariable.Type should be - it's already known depending on which helper function you call.
      • Using separate helper functions cleans up the interface. As a user, you don't need to understand what the "options" slice should be if you're just creating a variable that's populated with a query.
      • Entire classes of errors are avoided (not possible to accidentally specify both options and query in the same variable, as an example)
    • Going back to using the sdk.TemplateVariable type in the monitoring.Containers struct allows us to drop down and have full access to Grafana's variable API when we need it (when we require customization that the helper functions don't offer). The helper functions generate sdk.TemplateVariables, so we don't lose any ease-of-use here.
  2. (As a motivating example) Using the interval variable helper function that was added in the previous step, the search-blitz dashboard now lets you select the sampling duration for its queries (5m, 1hr30m, etc.): Screen Shot 2022-01-13 at 2 05 24 PM

Merge request reports

Loading