monitoring generator: replace ContainerVariable with separate function constructors + use interval variables in search-blitz
Created by: ggilmore
This PR does two major things:
-
It rips out the
monitoring.ContainerVariable
abstraction in favor of separate friendly helper functions that generatesdk.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.ContainerVariable
was 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 intoGrafanaTemplateVar
hard-codes this. The logic to handle this correctly would be messy because it needs to consider all possible states ofmonitoring.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 ofsdk.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 ofTemplateVariable.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
andquery
in the same variable, as an example)
- The end result of continuing to use
- Going back to using the
sdk.TemplateVariable
type in themonitoring.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 generatesdk.TemplateVariable
s, so we don't lose any ease-of-use here.
- Different Grafana variable types have conflicting needs and requirements that that can't be meshed together cleanly in a sum type like
-
(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.):