Skip to content

Commit 57429ff

Browse files
yotamloe8naama
andauthored
[Feat] Metrics Rollup Rules: Support all aggregation types for MEASUREMENT (#221)
* go mod tidy * Update provider.go * Add `metricsRollupRules` support * docs * Add tests * testdata * Add validation * uppercase * Update resource_metrics_rollup_rules_test.go * Add drop metric examples * Add retries resource user * Add unique id kibana object * revert * update `logzio_terraform_client` 1.27.0 -> 1.27.1 * update rollup rules according to latest api spec * tests * examples * readme * Update resource_user.go * Update group_2.txt * updated docs * validate aggregation by metric type + remove name length validation * tests * docs + examples * validate sum agg for `COUNTER`, `DELTA_COUNTER`, and `CUMULATIVE_COUNTER` + tests * docs + examples * logzio_terraform_client -> 1.27.2 * Update group_2.txt * fix test regex errors * pr comments fixes * Update group_2.txt * Update CHANGELOG.md * Update resource_metrics_rollup_rules_test.go * Update resource_metrics_rollup_rules_test.go * Update resource_metrics_rollup_rules_test.go * Update resource_metrics_rollup_rules_test.go * Update resource_metrics_rollup_rules_test.go * fix tests and adding helpers * remove unused helpers and improve test checks * add random id to kibana tests * make tests fail faster * `MEASUREMENT` support all aggegations * tests * docs * Update group_2.txt * logzio_terraform_client: `v1.27.2` -> `v1.27.3` * Update CHANGELOG.md * Update metrics_rollup_rules.md --------- Co-authored-by: 8naama <[email protected]>
1 parent 501c02a commit 57429ff

File tree

10 files changed

+39
-35
lines changed

10 files changed

+39
-35
lines changed

.github/test-groups/group_2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ TestAccLogzioGrafanaAlertRule_CreateUpdateAlertRule
2020
TestAccLogzioGrafanaNotificationPolicy_InvalidMatchType
2121
TestAccLogzioGrafanaNotificationPolicy_ManageGrafanaNotificationPolicy
2222
TestAccLogzioMetricsRollupRules_CreateMeasurement
23-
TestAccLogzioMetricsRollupRules_CreateMeasurementInvalid
23+
TestAccLogzioMetricsRollupRules_CreateMeasurementWithP99
2424
TestAccLogzioMetricsRollupRules_CreateWithFilter
2525
TestAccLogzioMetricsRollupRules_CreateSimple
2626
TestAccLogzioMetricsRollupRules_CreateComplex

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changes by Version
22

33
<!-- next version -->
4+
## v1.21.1
5+
- Upgrade `logzio_client_terraform` to `1.27.3`.
6+
- Metrics Rollup Rules: Support all aggregation types for `MEASUREMENT`
7+
48
## v1.21.0
59
- Upgrade `logzio_client_terraform` to `1.27.2`.
610
- Add support for [Metrics Rollup Rules](./docs/resources/metrics_rollup_rules.md)

docs/data-sources/metrics_rollup_rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ The following attributes are exported:
7676
* `name` - The human-readable name of the rollup rule.
7777
* `metric_name` - The name of the metric (if rule is metric name-based).
7878
* `metric_type` - The type of the metric (GAUGE, COUNTER, DELTA_COUNTER, CUMULATIVE_COUNTER, or MEASUREMENT).
79-
* `rollup_function` - The aggregation function used for rolling up the metric. Always "SUM" for COUNTER, DELTA_COUNTER, and CUMULATIVE_COUNTER types.
79+
* `rollup_function` - The aggregation function used for rolling up the metric. Always "SUM" for COUNTER, DELTA_COUNTER, and CUMULATIVE_COUNTER types. Can be any valid aggregation function for GAUGE and MEASUREMENT types.
8080
* `labels_elimination_method` - The method for eliminating labels (EXCLUDE_BY or GROUP_BY).
8181
* `labels` - The list of label names being eliminated from the metric.
8282
* `new_metric_name_template` - The template for generating new metric names.

docs/resources/metrics_rollup_rules.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ resource "logzio_metrics_rollup_rules" "frontend_metrics_rollup" {
2727
rollup_function = "SUM"
2828
labels_elimination_method = "GROUP_BY"
2929
labels = ["service", "region"]
30-
30+
3131
filter {
3232
expression {
3333
comparison = "EQ"
@@ -40,7 +40,7 @@ resource "logzio_metrics_rollup_rules" "frontend_metrics_rollup" {
4040
value = "us-.*"
4141
}
4242
}
43-
43+
4444
new_metric_name_template = "rollup.frontend.{{metricName}}"
4545
drop_original_metric = true
4646
}
@@ -53,7 +53,7 @@ resource "logzio_metrics_rollup_rules" "response_time_rollup" {
5353
account_id = 123456
5454
metric_name = "http_response_time"
5555
metric_type = "MEASUREMENT"
56-
rollup_function = "SUM"
56+
rollup_function = "P95"
5757
labels_elimination_method = "EXCLUDE_BY"
5858
labels = ["endpoint", "method"]
5959
}
@@ -66,7 +66,7 @@ The following arguments are supported:
6666
* `account_id` - (Required) The metrics account ID for the metrics rollup rule.
6767
* `metric_name` - (Optional) The name of the metric for which to create the rollup rule. Either `metric_name` or `filter` must be specified, but not both.
6868
* `metric_type` - (Required) The type of the metric. Valid values are `GAUGE`, `COUNTER`, `DELTA_COUNTER`, `CUMULATIVE_COUNTER`, and `MEASUREMENT`.
69-
* `rollup_function` - The aggregation function to use for rolling up the metric. Required for all metric types. For `COUNTER`, `DELTA_COUNTER`, and `CUMULATIVE_COUNTER` types, must be `SUM`. For `MEASUREMENT` metric type, only `SUM`, `MIN`, `MAX`, `COUNT`, `SUMSQ`, `MEAN`, and `LAST` are allowed. For `GAUGE` type, any valid aggregation function is allowed. Valid values include `SUM`, `MIN`, `MAX`, `COUNT`, `LAST`, `MEAN`, `MEDIAN`, `STDEV`, `SUMSQ`, and percentiles (`P10`, `P20`, `P25`, `P30`, `P40`, `P50`, `P60`, `P70`, `P75`, `P80`, `P90`, `P95`, `P99`, `P999`, `P9999`).
69+
* `rollup_function` - The aggregation function to use for rolling up the metric. Required for all metric types. For `COUNTER`, `DELTA_COUNTER`, and `CUMULATIVE_COUNTER` types, must be `SUM`. For `MEASUREMENT` and `GAUGE` metric types, any valid aggregation function is allowed. Valid values include `SUM`, `MIN`, `MAX`, `COUNT`, `LAST`, `MEAN`, `MEDIAN`, `STDEV`, `SUMSQ`, and percentiles (`P10`, `P20`, `P25`, `P30`, `P40`, `P50`, `P60`, `P70`, `P75`, `P80`, `P90`, `P95`, `P99`, `P999`, `P9999`).
7070
* `labels_elimination_method` - (Required) The method for eliminating labels. Valid values are `EXCLUDE_BY` and `GROUP_BY`.
7171
* `labels` - (Required) A list of label names to be eliminated from the metric.
7272
* `name` - (Optional) A human-readable name for the rollup rule.

examples/metrics_rollup_rules/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ resource "logzio_metrics_rollup_rules" "frontend_service_rollup" {
7171
}
7272
}
7373

74+
7475
new_metric_name_template = "rollup.frontend.{{metricName}}"
7576
drop_original_metric = true
7677
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/hashicorp/go-cty v1.5.0
88
github.com/hashicorp/terraform-plugin-log v0.9.0
99
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
10-
github.com/logzio/logzio_terraform_client v1.27.2
10+
github.com/logzio/logzio_terraform_client v1.27.3
1111
github.com/stoewer/go-strcase v1.3.1
1212
github.com/stretchr/testify v1.10.0
1313
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
124124
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
125125
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
126126
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
127-
github.com/logzio/logzio_terraform_client v1.27.2 h1:zfZ09gtbxVAM6g1FKC5inpK8zeAiN2F+pPhrHs2/Hj0=
128-
github.com/logzio/logzio_terraform_client v1.27.2/go.mod h1:pzXrr7gGIi6tU1mk2vTtg8dr6ttKMlt03kz6asC53o4=
127+
github.com/logzio/logzio_terraform_client v1.27.3 h1:Sf58iy88N4H4JBMiyl90joWpHUrDcoUCdB/WEnGnZbU=
128+
github.com/logzio/logzio_terraform_client v1.27.3/go.mod h1:pzXrr7gGIi6tU1mk2vTtg8dr6ttKMlt03kz6asC53o4=
129129
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
130130
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
131131
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=

logzio/resource_metrics_rollup_rules.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,6 @@ func validateRollup(ctx context.Context, d *schema.ResourceDiff, m interface{})
197197
if rollupFunction == "" {
198198
return fmt.Errorf("rollup_function must be set for MEASUREMENT metrics")
199199
}
200-
// Validate MEASUREMENT allows only specific aggregation functions
201-
allowedForMeasurement := map[string]bool{
202-
string(metrics_rollup_rules.AggSum): true,
203-
string(metrics_rollup_rules.AggMin): true,
204-
string(metrics_rollup_rules.AggMax): true,
205-
string(metrics_rollup_rules.AggCount): true,
206-
string(metrics_rollup_rules.AggSumSq): true,
207-
string(metrics_rollup_rules.AggMean): true,
208-
string(metrics_rollup_rules.AggLast): true,
209-
}
210-
if !allowedForMeasurement[rollupFunction] {
211-
return fmt.Errorf("invalid aggregation function %q for MEASUREMENT metric type. Allowed functions: SUM, MIN, MAX, COUNT, SUMSQ, MEAN, LAST", rollupFunction)
212-
}
213200
case string(metrics_rollup_rules.MetricTypeCounter),
214201
string(metrics_rollup_rules.MetricTypeDeltaCounter),
215202
string(metrics_rollup_rules.MetricTypeCumulativeCounter):

logzio/resource_metrics_rollup_rules_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
metricsRollupRulesResourceUpdate = "update_metrics_rollup_rules"
2323
metricsRollupRulesResourceCreateWithFilter = "create_metrics_rollup_rules_with_filter"
2424
metricsRollupRulesResourceCreateMeasurement = "create_metrics_rollup_rules_measurement"
25-
metricsRollupRulesResourceCreateMeasurementInvalid = "create_metrics_rollup_rules_measurement_invalid"
25+
metricsRollupRulesResourceCreateMeasurementP99 = "create_metrics_rollup_rules_measurement_p99"
2626
metricsRollupRulesResourceCreateCounterWithRollupFunction = "create_metrics_rollup_rules_counter_with_rollup_function"
2727
metricsRollupRulesResourceCreateCounterMissingRollupFunction = "create_metrics_rollup_rules_counter_missing_rollup_function"
2828
)
@@ -309,8 +309,8 @@ func TestAccLogzioMetricsRollupRules_CreateMeasurement(t *testing.T) {
309309
})
310310
}
311311

312-
func TestAccLogzioMetricsRollupRules_CreateMeasurementInvalid(t *testing.T) {
313-
resourceName := "test_create_metrics_rollup_rules_measurement_invalid"
312+
func TestAccLogzioMetricsRollupRules_CreateCounterWithRollupFunction(t *testing.T) {
313+
resourceName := "test_create_metrics_rollup_rules_counter_with_rollup_function"
314314
accountId := os.Getenv(envLogzioMetricsAccountId)
315315

316316
defer utils.SleepAfterTest()
@@ -323,15 +323,15 @@ func TestAccLogzioMetricsRollupRules_CreateMeasurementInvalid(t *testing.T) {
323323
ProviderFactories: testAccProviderFactories,
324324
Steps: []resource.TestStep{
325325
{
326-
Config: resourceTestMetricsRollupRules(resourceName, metricsRollupRulesResourceCreateMeasurementInvalid, accountId),
327-
ExpectError: regexp.MustCompile("invalid aggregation function \"P99\" for MEASUREMENT metric type"),
326+
Config: resourceTestMetricsRollupRules(resourceName, metricsRollupRulesResourceCreateCounterWithRollupFunction, accountId),
327+
ExpectError: regexp.MustCompile("for COUNTER metrics, rollup_function must be SUM"),
328328
},
329329
},
330330
})
331331
}
332332

333-
func TestAccLogzioMetricsRollupRules_CreateCounterWithRollupFunction(t *testing.T) {
334-
resourceName := "test_create_metrics_rollup_rules_counter_with_rollup_function"
333+
func TestAccLogzioMetricsRollupRules_CreateCounterMissingRollupFunction(t *testing.T) {
334+
resourceName := "test_create_metrics_rollup_rules_counter_missing_rollup_function"
335335
accountId := os.Getenv(envLogzioMetricsAccountId)
336336

337337
defer utils.SleepAfterTest()
@@ -344,15 +344,15 @@ func TestAccLogzioMetricsRollupRules_CreateCounterWithRollupFunction(t *testing.
344344
ProviderFactories: testAccProviderFactories,
345345
Steps: []resource.TestStep{
346346
{
347-
Config: resourceTestMetricsRollupRules(resourceName, metricsRollupRulesResourceCreateCounterWithRollupFunction, accountId),
348-
ExpectError: regexp.MustCompile("for COUNTER metrics, rollup_function must be SUM"),
347+
Config: resourceTestMetricsRollupRules(resourceName, metricsRollupRulesResourceCreateCounterMissingRollupFunction, accountId),
348+
ExpectError: regexp.MustCompile("rollup_function must be set for COUNTER metrics"),
349349
},
350350
},
351351
})
352352
}
353353

354-
func TestAccLogzioMetricsRollupRules_CreateCounterMissingRollupFunction(t *testing.T) {
355-
resourceName := "test_create_metrics_rollup_rules_counter_missing_rollup_function"
354+
func TestAccLogzioMetricsRollupRules_CreateMeasurementWithP99(t *testing.T) {
355+
resourceName := "test_create_metrics_rollup_rules_measurement_p99"
356356
accountId := os.Getenv(envLogzioMetricsAccountId)
357357

358358
defer utils.SleepAfterTest()
@@ -365,8 +365,12 @@ func TestAccLogzioMetricsRollupRules_CreateCounterMissingRollupFunction(t *testi
365365
ProviderFactories: testAccProviderFactories,
366366
Steps: []resource.TestStep{
367367
{
368-
Config: resourceTestMetricsRollupRules(resourceName, metricsRollupRulesResourceCreateCounterMissingRollupFunction, accountId),
369-
ExpectError: regexp.MustCompile("rollup_function must be set for COUNTER metrics"),
368+
Config: resourceTestMetricsRollupRules(resourceName, metricsRollupRulesResourceCreateMeasurementP99, accountId),
369+
Check: resource.ComposeAggregateTestCheckFunc(
370+
resource.TestCheckResourceAttr("logzio_metrics_rollup_rules."+resourceName, metricsRollupRulesMetricType, "MEASUREMENT"),
371+
resource.TestCheckResourceAttr("logzio_metrics_rollup_rules."+resourceName, metricsRollupRulesRollupFunction, "P99"),
372+
resource.TestCheckResourceAttr("logzio_metrics_rollup_rules."+resourceName, metricsRollupRulesMetricName, "response_time"),
373+
),
370374
},
371375
},
372376
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "logzio_metrics_rollup_rules" "%s" {
2+
account_id = %s
3+
metric_name = "response_time"
4+
metric_type = "MEASUREMENT"
5+
rollup_function = "P99"
6+
labels_elimination_method = "EXCLUDE_BY"
7+
labels = ["instance_id"]
8+
}

0 commit comments

Comments
 (0)