Skip to content

Commit

Permalink
Rename prometheus#min_interval -> prometheus#min_step. Add `query…
Browse files Browse the repository at this point in the history
…#min_interval`
  • Loading branch information
iRevive committed Mar 26, 2024
1 parent 678de42 commit cfb2f4e
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/bar_gauge.md
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ Optional:

- `cloudwatch` (Block List) The CloudWatch query. (see [below for nested schema](#nestedblock--queries--cloudwatch))
- `expression` (Block List) The expression query. (see [below for nested schema](#nestedblock--queries--expression))
- `min_interval` (String) The lower bounds on the interval between data points.
- `prometheus` (Block List) The Prometheus query. (see [below for nested schema](#nestedblock--queries--prometheus))

<a id="nestedblock--queries--cloudwatch"></a>
Expand Down Expand Up @@ -863,7 +864,6 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `label` (String) The legend name.
- `match_exact` (Boolean) If enabled you also need to specify **all** the dimensions of the metric you’re querying.
- `min_interval` (String) The lower bounds on the interval between data points.
- `period` (String) The minimum interval between points in seconds.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
- `region` (String) The AWS region to query the metrics from.
Expand Down Expand Up @@ -941,7 +941,7 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `instant` (Boolean) Whether to return the latest value from the time series or not.
- `legend_format` (String) The legend name.
- `min_interval` (String) The lower bounds on the interval between data points.
- `min_step` (String) The lower bounds on the interval between data points.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.


Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/gauge.md
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ Optional:

- `cloudwatch` (Block List) The CloudWatch query. (see [below for nested schema](#nestedblock--queries--cloudwatch))
- `expression` (Block List) The expression query. (see [below for nested schema](#nestedblock--queries--expression))
- `min_interval` (String) The lower bounds on the interval between data points.
- `prometheus` (Block List) The Prometheus query. (see [below for nested schema](#nestedblock--queries--prometheus))

<a id="nestedblock--queries--cloudwatch"></a>
Expand Down Expand Up @@ -901,7 +902,6 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `label` (String) The legend name.
- `match_exact` (Boolean) If enabled you also need to specify **all** the dimensions of the metric you’re querying.
- `min_interval` (String) The lower bounds on the interval between data points.
- `period` (String) The minimum interval between points in seconds.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
- `region` (String) The AWS region to query the metrics from.
Expand Down Expand Up @@ -979,7 +979,7 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `instant` (Boolean) Whether to return the latest value from the time series or not.
- `legend_format` (String) The legend name.
- `min_interval` (String) The lower bounds on the interval between data points.
- `min_step` (String) The lower bounds on the interval between data points.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.


Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Optional:

- `cloudwatch` (Block List) The CloudWatch query. (see [below for nested schema](#nestedblock--queries--cloudwatch))
- `expression` (Block List) The expression query. (see [below for nested schema](#nestedblock--queries--expression))
- `min_interval` (String) The lower bounds on the interval between data points.
- `prometheus` (Block List) The Prometheus query. (see [below for nested schema](#nestedblock--queries--prometheus))

<a id="nestedblock--queries--cloudwatch"></a>
Expand Down Expand Up @@ -149,7 +150,6 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `label` (String) The legend name.
- `match_exact` (Boolean) If enabled you also need to specify **all** the dimensions of the metric you’re querying.
- `min_interval` (String) The lower bounds on the interval between data points.
- `period` (String) The minimum interval between points in seconds.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
- `region` (String) The AWS region to query the metrics from.
Expand Down Expand Up @@ -227,5 +227,5 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `instant` (Boolean) Whether to return the latest value from the time series or not.
- `legend_format` (String) The legend name.
- `min_interval` (String) The lower bounds on the interval between data points.
- `min_step` (String) The lower bounds on the interval between data points.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
4 changes: 2 additions & 2 deletions docs/data-sources/stat.md
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ Optional:

- `cloudwatch` (Block List) The CloudWatch query. (see [below for nested schema](#nestedblock--queries--cloudwatch))
- `expression` (Block List) The expression query. (see [below for nested schema](#nestedblock--queries--expression))
- `min_interval` (String) The lower bounds on the interval between data points.
- `prometheus` (Block List) The Prometheus query. (see [below for nested schema](#nestedblock--queries--prometheus))

<a id="nestedblock--queries--cloudwatch"></a>
Expand Down Expand Up @@ -898,7 +899,6 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `label` (String) The legend name.
- `match_exact` (Boolean) If enabled you also need to specify **all** the dimensions of the metric you’re querying.
- `min_interval` (String) The lower bounds on the interval between data points.
- `period` (String) The minimum interval between points in seconds.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
- `region` (String) The AWS region to query the metrics from.
Expand Down Expand Up @@ -976,7 +976,7 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `instant` (Boolean) Whether to return the latest value from the time series or not.
- `legend_format` (String) The legend name.
- `min_interval` (String) The lower bounds on the interval between data points.
- `min_step` (String) The lower bounds on the interval between data points.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.


Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ Optional:

- `cloudwatch` (Block List) The CloudWatch query. (see [below for nested schema](#nestedblock--queries--cloudwatch))
- `expression` (Block List) The expression query. (see [below for nested schema](#nestedblock--queries--expression))
- `min_interval` (String) The lower bounds on the interval between data points.
- `prometheus` (Block List) The Prometheus query. (see [below for nested schema](#nestedblock--queries--prometheus))

<a id="nestedblock--queries--cloudwatch"></a>
Expand Down Expand Up @@ -933,7 +934,6 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `label` (String) The legend name.
- `match_exact` (Boolean) If enabled you also need to specify **all** the dimensions of the metric you’re querying.
- `min_interval` (String) The lower bounds on the interval between data points.
- `period` (String) The minimum interval between points in seconds.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
- `region` (String) The AWS region to query the metrics from.
Expand Down Expand Up @@ -1011,7 +1011,7 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `instant` (Boolean) Whether to return the latest value from the time series or not.
- `legend_format` (String) The legend name.
- `min_interval` (String) The lower bounds on the interval between data points.
- `min_step` (String) The lower bounds on the interval between data points.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.


Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/timeseries.md
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ Optional:

- `cloudwatch` (Block List) The CloudWatch query. (see [below for nested schema](#nestedblock--queries--cloudwatch))
- `expression` (Block List) The expression query. (see [below for nested schema](#nestedblock--queries--expression))
- `min_interval` (String) The lower bounds on the interval between data points.
- `prometheus` (Block List) The Prometheus query. (see [below for nested schema](#nestedblock--queries--prometheus))

<a id="nestedblock--queries--cloudwatch"></a>
Expand Down Expand Up @@ -928,7 +929,6 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `label` (String) The legend name.
- `match_exact` (Boolean) If enabled you also need to specify **all** the dimensions of the metric you’re querying.
- `min_interval` (String) The lower bounds on the interval between data points.
- `period` (String) The minimum interval between points in seconds.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
- `region` (String) The AWS region to query the metrics from.
Expand Down Expand Up @@ -1006,7 +1006,7 @@ Optional:
- `hide` (Boolean) Whether to hide query result from the panel or not.
- `instant` (Boolean) Whether to return the latest value from the time series or not.
- `legend_format` (String) The legend name.
- `min_interval` (String) The lower bounds on the interval between data points.
- `min_step` (String) The lower bounds on the interval between data points.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.


Expand Down
3 changes: 2 additions & 1 deletion internal/provider/bar_gauge_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (d *BarGaugeDataSource) Read(ctx context.Context, req datasource.ReadReques
return
}

targets := createTargets(data.Queries)
targets, minInterval := createTargets(data.Queries)
fieldConfig := createFieldConfig(d.Defaults.Field, data.Field)
transformations := createTransformations(data.Transformations)

Expand Down Expand Up @@ -206,6 +206,7 @@ func (d *BarGaugeDataSource) Read(ctx context.Context, req datasource.ReadReques
Span: 12,
IsNew: true,
Transformations: transformations,
Interval: minInterval,
},
BarGaugePanel: &grafana.BarGaugePanel{
Targets: targets,
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/gauge_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (d *GaugeDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

targets := createTargets(data.Queries)
targets, minInterval := createTargets(data.Queries)
fieldConfig := createFieldConfig(d.Defaults.Field, data.Field)
transformations := createTransformations(data.Transformations)

Expand Down Expand Up @@ -198,6 +198,7 @@ func (d *GaugeDataSource) Read(ctx context.Context, req datasource.ReadRequest,
Span: 12,
IsNew: true,
Transformations: transformations,
Interval: minInterval,
},
GaugePanel: &grafana.GaugePanel{
Targets: targets,
Expand Down
1 change: 1 addition & 0 deletions internal/provider/grafana/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type (
Type string `json:"type"`
Alert *Alert `json:"alert,omitempty"`
Transformations []Transformation `json:"transformations,omitempty"`
Interval *string `json:"interval,omitempty"`
}
AlertEvaluator struct {
Params []float64 `json:"params,omitempty"`
Expand Down
13 changes: 7 additions & 6 deletions internal/provider/logs_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (d *LogsDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
return
}

targets := createTargets(data.Queries)
targets, minInterval := createTargets(data.Queries)

falseVal := false
trueVal := true
Expand Down Expand Up @@ -210,11 +210,12 @@ func (d *LogsDataSource) Read(ctx context.Context, req datasource.ReadRequest, r

panel := &grafana.Panel{
CommonPanel: grafana.CommonPanel{
OfType: grafana.LogsType,
Title: data.Title.ValueString(),
Type: "logs",
Span: 12,
IsNew: true,
OfType: grafana.LogsType,
Title: data.Title.ValueString(),
Type: "logs",
Span: 12,
IsNew: true,
Interval: minInterval,
},
LogsPanel: &grafana.LogsPanel{
Targets: targets,
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/stat_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (d *StatDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
return
}

targets := createTargets(data.Queries)
targets, minInterval := createTargets(data.Queries)
fieldConfig := createFieldConfig(d.Defaults.Field, data.Field)
transformations := createTransformations(data.Transformations)

Expand Down Expand Up @@ -236,6 +236,7 @@ func (d *StatDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
Span: 12,
IsNew: true,
Transformations: transformations,
Interval: minInterval,
},
StatPanel: &grafana.StatPanel{
Targets: targets,
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/table_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (d *TableDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

targets := createTargets(data.Queries)
targets, minInterval := createTargets(data.Queries)
fieldConfig := createFieldConfig(d.Defaults.Field, data.Field)
transformations := createTransformations(data.Transformations)

Expand Down Expand Up @@ -339,6 +339,7 @@ func (d *TableDataSource) Read(ctx context.Context, req datasource.ReadRequest,
Span: 12,
IsNew: true,
Transformations: transformations,
Interval: minInterval,
},
TablePanel: &grafana.TablePanel{
Targets: targets,
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/timeseries_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (d *TimeseriesDataSource) Read(ctx context.Context, req datasource.ReadRequ
return
}

targets := createTargets(data.Queries)
targets, minInterval := createTargets(data.Queries)
transformations := createTransformations(data.Transformations)

legendOptions := grafana.TimeseriesLegendOptions{
Expand Down Expand Up @@ -451,6 +451,7 @@ func (d *TimeseriesDataSource) Read(ctx context.Context, req datasource.ReadRequ
Span: 12,
IsNew: true,
Transformations: transformations,
Interval: minInterval,
},
TimeseriesPanel: &grafana.TimeseriesPanel{
Targets: targets,
Expand Down
36 changes: 20 additions & 16 deletions internal/provider/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ type ByQueryIDOverrideOptions struct {
}

type Query struct {
Prometheus []PrometheusTarget `tfsdk:"prometheus"`
CloudWatch []CloudWatchTarget `tfsdk:"cloudwatch"`
MinInterval types.String `tfsdk:"min_interval"`
Prometheus []PrometheusTarget `tfsdk:"prometheus"`
CloudWatch []CloudWatchTarget `tfsdk:"cloudwatch"`
Expression []ExpressionTarget `tfsdk:"expression"`
}

Expand All @@ -273,7 +274,7 @@ type PrometheusTarget struct {
Format types.String `tfsdk:"format"`
// etc
RefId types.String `tfsdk:"ref_id"`
MinInterval types.String `tfsdk:"min_interval"`
MinStep types.String `tfsdk:"min_step"`
LegendFormat types.String `tfsdk:"legend_format"`
}

Expand All @@ -292,10 +293,9 @@ type CloudWatchMetricsTarget struct {
MatchExact types.Bool `tfsdk:"match_exact"`
Region types.String `tfsdk:"region"`
// etc
RefId types.String `tfsdk:"ref_id"`
MinInterval types.String `tfsdk:"min_interval"`
Period types.String `tfsdk:"period"`
Label types.String `tfsdk:"label"`
RefId types.String `tfsdk:"ref_id"`
Period types.String `tfsdk:"period"`
Label types.String `tfsdk:"label"`
}

type CloudWatchLogGroup struct {
Expand Down Expand Up @@ -672,7 +672,7 @@ func queryBlock() schema.Block {
stringvalidator.OneOf("time_series", "table", "heatmap"),
},
},
"min_interval": schema.StringAttribute{
"min_step": schema.StringAttribute{
Optional: true,
Description: "The lower bounds on the interval between data points.",
},
Expand Down Expand Up @@ -748,10 +748,6 @@ func queryBlock() schema.Block {
Optional: true,
Description: "The ID of the query. The ID can be used to reference queries in math expressions.",
},
"min_interval": schema.StringAttribute{
Optional: true,
Description: "The lower bounds on the interval between data points.",
},
"period": schema.StringAttribute{
Optional: true,
Description: "The minimum interval between points in seconds.",
Expand Down Expand Up @@ -951,6 +947,12 @@ func queryBlock() schema.Block {
},
},
},
Attributes: map[string]schema.Attribute{
"min_interval": schema.StringAttribute{
Optional: true,
Description: "The lower bounds on the interval between data points.",
},
},
},
Validators: []validator.List{
listvalidator.SizeAtMost(3),
Expand Down Expand Up @@ -1185,10 +1187,13 @@ func descriptionAttribute() schema.StringAttribute {

// creators

func createTargets(queries []Query) []grafana.Target {
func createTargets(queries []Query) ([]grafana.Target, *string) {
targets := make([]grafana.Target, 0)
var minInterval *string

for _, group := range queries {
minInterval = group.MinInterval.ValueStringPointer()

for _, target := range group.Prometheus {
t := grafana.Target{
Datasource: grafana.Datasource{
Expand All @@ -1198,7 +1203,7 @@ func createTargets(queries []Query) []grafana.Target {
RefID: target.RefId.ValueString(),
Hide: target.Hide.ValueBool(),
Expr: target.Expr.ValueString(),
Interval: target.MinInterval.ValueString(),
Interval: target.MinStep.ValueString(),
LegendFormat: target.LegendFormat.ValueString(),
Instant: target.Instant.ValueBool(),
Format: target.Format.ValueString(),
Expand All @@ -1224,7 +1229,6 @@ func createTargets(queries []Query) []grafana.Target {
},
RefID: metrics.RefId.ValueString(),
Hide: metrics.Hide.ValueBool(),
Interval: metrics.MinInterval.ValueString(),
QueryMode: "Metrics",
MetricQueryType: &zero,
MetricEditorMode: &zero,
Expand Down Expand Up @@ -1316,7 +1320,7 @@ func createTargets(queries []Query) []grafana.Target {
}
}

return targets
return targets, minInterval
}

type ValueMappingResult struct {
Expand Down

0 comments on commit cfb2f4e

Please sign in to comment.