Skip to content

Commit 1d3536c

Browse files
committed
rename to exportAllDataPoints and added test
Signed-off-by: Lukas Wöhrl <[email protected]>
1 parent ce858fb commit 1d3536c

File tree

11 files changed

+74
-36
lines changed

11 files changed

+74
-36
lines changed

docs/configuration.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ statistics:
140140
# Enables the inclusion of past metric data points from the CloudWatch response if available.
141141
# This is useful when a metric is configured with a 60-second period and a 300-second duration, ensuring that all
142142
# five data points are exposed at the metrics endpoint instead of only the latest one.
143-
# Note: This option requires `addCloudwatchTimestamp` to be enabled
143+
# Note: This option requires `addCloudwatchTimestamp` to be enabled.
144+
# The metric destination must support out of order timestamps, see https://prometheus.io/docs/prometheus/latest/configuration/configuration/#tsdb
144145
# (General Setting for all metrics in this job)
145-
[ addHistoricalMetrics: <boolean> ]
146+
[ exportAllDataPoints: <boolean> ]
146147

147148
# List of metric definitions
148149
metrics:
@@ -282,9 +283,10 @@ statistics:
282283
# Enables the inclusion of past metric data points from the CloudWatch response if available.
283284
# This is useful when a metric is configured with a 60-second period and a 300-second duration, ensuring that all
284285
# five data points are exposed at the metrics endpoint instead of only the latest one.
285-
# Note: This option requires `addCloudwatchTimestamp` to be enabled
286+
# Note: This option requires `addCloudwatchTimestamp` to be enabled.
287+
# The metric destination must support out of order timestamps, see https://prometheus.io/docs/prometheus/latest/configuration/configuration/#tsdb
286288
# (General Setting for all metrics in this job)
287-
[ addHistoricalMetrics: <boolean> ]
289+
[ exportAllDataPoints: <boolean> ]
288290

289291
# List of metric definitions
290292
metrics:
@@ -349,7 +351,7 @@ Notes:
349351
350352
- Available statistics: `Maximum`, `Minimum`, `Sum`, `SampleCount`, `Average`, `pXX` (e.g. `p90`).
351353

352-
- Watch out using `addCloudwatchTimestamp` for sparse metrics, e.g from S3, since Prometheus won't scrape metrics containing timestamps older than 2-3 hours. Also the same applies when enabling `addHistoricalMetrics` in any metric
354+
- Watch out using `addCloudwatchTimestamp` for sparse metrics, e.g from S3, since Prometheus won't scrape metrics containing timestamps older than 2-3 hours. Also the same applies when enabling `exportAllDataPoints` in any metric
353355

354356
### `exported_tags_config`
355357

examples/historic-data.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ discovery:
77
period: 60
88
length: 300
99
addCloudwatchTimestamp: true
10-
addHistoricalMetrics: true
10+
exportAllDataPoints: true
1111
metrics:
1212
- name: NumberOfMessagesSent
1313
statistics: [Sum]

pkg/clients/cloudwatch/v1/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ func toMetricDataResult(resp cloudwatch.GetMetricDataOutput) []cloudwatch_client
147147
ID: *metricDataResult.Id,
148148
Datapoints: make([]cloudwatch_client.DatapointWithTimestamp, 0, len(metricDataResult.Timestamps))}
149149
for i := 0; i < len(metricDataResult.Timestamps); i++ {
150-
mappedResult.Datapoints = append(mappedResult.Datapoints, cloudwatch_client.DatapointWithTimestamp{
151-
Datapoint: metricDataResult.Values[i],
152-
Timestamp: *metricDataResult.Timestamps[i],
153-
})
150+
mappedResult.Datapoints = append(mappedResult.Datapoints, cloudwatch_client.NewDataPoint(metricDataResult.Values[i], *metricDataResult.Timestamps[i]))
154151
}
155152
output = append(output, mappedResult)
156153
}

pkg/clients/cloudwatch/v2/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ func toMetricDataResult(resp cloudwatch.GetMetricDataOutput) []cloudwatch_client
154154
Datapoints: make([]cloudwatch_client.DatapointWithTimestamp, 0, len(metricDataResult.Timestamps)),
155155
}
156156
for i := 0; i < len(metricDataResult.Timestamps); i++ {
157-
mappedResult.Datapoints = append(mappedResult.Datapoints, cloudwatch_client.DatapointWithTimestamp{
158-
Datapoint: &metricDataResult.Values[i],
159-
Timestamp: metricDataResult.Timestamps[i],
160-
})
157+
mappedResult.Datapoints = append(mappedResult.Datapoints, cloudwatch_client.NewDataPoint(&metricDataResult.Values[i], metricDataResult.Timestamps[i]))
161158
}
162159
output = append(output, mappedResult)
163160
}

pkg/config/config.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type JobLevelMetricFields struct {
5252
Delay int64 `yaml:"delay"`
5353
NilToZero *bool `yaml:"nilToZero"`
5454
AddCloudwatchTimestamp *bool `yaml:"addCloudwatchTimestamp"`
55-
AddHistoricalMetrics *bool `yaml:"addHistoricalMetrics"`
55+
ExportAllDataPoints *bool `yaml:"exportAllDataPoints"`
5656
}
5757

5858
type Job struct {
@@ -100,7 +100,7 @@ type Metric struct {
100100
Delay int64 `yaml:"delay"`
101101
NilToZero *bool `yaml:"nilToZero"`
102102
AddCloudwatchTimestamp *bool `yaml:"addCloudwatchTimestamp"`
103-
AddHistoricalMetrics *bool `yaml:"addHistoricalMetrics"`
103+
ExportAllDataPoints *bool `yaml:"exportAllDataPoints"`
104104
}
105105

106106
type Dimension struct {
@@ -389,17 +389,17 @@ func (m *Metric) validateMetric(logger *slog.Logger, metricIdx int, parent strin
389389
}
390390
}
391391

392-
mAddHistoricalMetrics := m.AddHistoricalMetrics
393-
if mAddHistoricalMetrics == nil {
394-
if discovery != nil && discovery.AddHistoricalMetrics != nil {
395-
mAddHistoricalMetrics = discovery.AddHistoricalMetrics
392+
mExportAllDataPoints := m.ExportAllDataPoints
393+
if mExportAllDataPoints == nil {
394+
if discovery != nil && discovery.ExportAllDataPoints != nil {
395+
mExportAllDataPoints = discovery.ExportAllDataPoints
396396
} else {
397-
mAddHistoricalMetrics = aws.Bool(false)
397+
mExportAllDataPoints = aws.Bool(false)
398398
}
399399
}
400400

401-
if aws.BoolValue(mAddHistoricalMetrics) && !aws.BoolValue(mAddCloudwatchTimestamp) {
402-
return fmt.Errorf("Metric [%s/%d] in %v: AddHistoricalMetrics can only be enabled if AddCloudwatchTimestamp is enabled", m.Name, metricIdx, parent)
401+
if aws.BoolValue(mExportAllDataPoints) && !aws.BoolValue(mAddCloudwatchTimestamp) {
402+
return fmt.Errorf("Metric [%s/%d] in %v: ExportAllDataPoints can only be enabled if AddCloudwatchTimestamp is enabled", m.Name, metricIdx, parent)
403403
}
404404

405405
if mLength < mPeriod {
@@ -413,7 +413,7 @@ func (m *Metric) validateMetric(logger *slog.Logger, metricIdx int, parent strin
413413
m.Delay = mDelay
414414
m.NilToZero = mNilToZero
415415
m.AddCloudwatchTimestamp = mAddCloudwatchTimestamp
416-
m.AddHistoricalMetrics = mAddHistoricalMetrics
416+
m.ExportAllDataPoints = mExportAllDataPoints
417417
m.Statistics = mStatistics
418418

419419
return nil
@@ -535,7 +535,7 @@ func toModelMetricConfig(metrics []*Metric) []*model.MetricConfig {
535535
Delay: m.Delay,
536536
NilToZero: aws.BoolValue(m.NilToZero),
537537
AddCloudwatchTimestamp: aws.BoolValue(m.AddCloudwatchTimestamp),
538-
AddHistoricalMetrics: aws.BoolValue(m.AddHistoricalMetrics),
538+
ExportAllDataPoints: aws.BoolValue(m.ExportAllDataPoints),
539539
})
540540
}
541541
return ret

pkg/job/custom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func getMetricDataForQueriesForCustomNamespace(
8686
MetricMigrationParams: model.MetricMigrationParams{
8787
NilToZero: metric.NilToZero,
8888
AddCloudwatchTimestamp: metric.AddCloudwatchTimestamp,
89-
AddHistoricalMetrics: metric.AddHistoricalMetrics,
89+
ExportAllDataPoints: metric.ExportAllDataPoints,
9090
},
9191
Tags: nil,
9292
GetMetricDataResult: nil,

pkg/job/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func getFilteredMetricDatas(
179179
MetricMigrationParams: model.MetricMigrationParams{
180180
NilToZero: m.NilToZero,
181181
AddCloudwatchTimestamp: m.AddCloudwatchTimestamp,
182-
AddHistoricalMetrics: m.AddHistoricalMetrics,
182+
ExportAllDataPoints: m.ExportAllDataPoints,
183183
},
184184
Tags: metricTags,
185185
GetMetricDataResult: nil,

pkg/job/getmetricdata/processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func getSampleMetricDatas(id string) *model.CloudwatchData {
259259
MetricMigrationParams: model.MetricMigrationParams{
260260
NilToZero: false,
261261
AddCloudwatchTimestamp: false,
262-
AddHistoricalMetrics: false,
262+
ExportAllDataPoints: false,
263263
},
264264
GetMetricDataProcessingParams: &model.GetMetricDataProcessingParams{
265265
Period: 60,

pkg/model/model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type MetricConfig struct {
8080
Delay int64
8181
NilToZero bool
8282
AddCloudwatchTimestamp bool
83-
AddHistoricalMetrics bool
83+
ExportAllDataPoints bool
8484
}
8585

8686
type DimensionsRegexp struct {
@@ -199,7 +199,7 @@ type GetMetricDataProcessingParams struct {
199199
type MetricMigrationParams struct {
200200
NilToZero bool
201201
AddCloudwatchTimestamp bool
202-
AddHistoricalMetrics bool
202+
ExportAllDataPoints bool
203203
}
204204

205205
type GetMetricDataResult struct {

pkg/promutil/migrate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ func BuildMetrics(results []model.CloudwatchMetricResult, labelsSnakeCase bool,
143143
IncludeTimestamp: metric.MetricMigrationParams.AddCloudwatchTimestamp,
144144
})
145145

146-
if !metric.MetricMigrationParams.AddHistoricalMetrics {
147-
// If we're not adding historical metrics, we can skip the rest of the statistics for this metric
146+
if !metric.MetricMigrationParams.ExportAllDataPoints {
147+
// If we're not adding historical metrics, we can skip the rest of the datapoints for this metric
148148
break
149149
}
150150
}
@@ -326,7 +326,7 @@ func EnsureLabelConsistencyAndRemoveDuplicates(metrics []*PrometheusMetric, obse
326326

327327
// We are including the timestamp in the metric key to ensure that we don't have duplicate metrics
328328
// if we have AddCloudwatchTimestamp enabled its the real timestamp, otherwise its a zero value
329-
// the timestamp is needed to ensure valid date created by AddHistoricalMetrics
329+
// the timestamp is needed to ensure valid date created by ExportAllDataPoints
330330
metricKey := fmt.Sprintf("%s-%d-%d", metric.Name, prom_model.LabelsToSignature(metric.Labels), metric.Timestamp.Unix())
331331
if _, exists := metricKeys[metricKey]; !exists {
332332
metricKeys[metricKey] = struct{}{}

0 commit comments

Comments
 (0)