Skip to content

Commit aba04c2

Browse files
committed
change name to aggregation_temporality, to match the data_model
Signed-off-by: Nikos Angelopoulos <[email protected]>
1 parent 56f210f commit aba04c2

File tree

7 files changed

+96
-96
lines changed

7 files changed

+96
-96
lines changed

.chloggen/nickange_telemetrygen_metrics_support-delta-temporality.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ change_type: enhancement
77
component: telemetrygen
88

99
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10-
note: "Add support for `temporalityType` flag in telemetrygen. Supported values (delta or cumulative)"
10+
note: "Add support for `aggregation-temporality` flag in telemetrygen. Supported values (delta or cumulative)"
1111

1212
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
1313
issues: [38073]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package metrics
2+
3+
import (
4+
"fmt"
5+
6+
"go.opentelemetry.io/otel/sdk/metric/metricdata"
7+
)
8+
9+
type AggregationTemporality metricdata.Temporality
10+
11+
func (t *AggregationTemporality) Set(v string) error {
12+
switch v {
13+
case "delta":
14+
*t = AggregationTemporality(metricdata.DeltaTemporality)
15+
return nil
16+
case "cumulative":
17+
*t = AggregationTemporality(metricdata.CumulativeTemporality)
18+
return nil
19+
default:
20+
return fmt.Errorf(`temporality must be one of "delta" or "cumulative"`)
21+
}
22+
}
23+
24+
func (t *AggregationTemporality) String() string {
25+
return string(metricdata.Temporality(*t))
26+
}
27+
28+
func (t *AggregationTemporality) Type() string {
29+
return "temporality"
30+
}
31+
32+
// AsTemporality converts the AggregationTemporality to metricdata.Temporality
33+
func (t AggregationTemporality) AsTemporality() metricdata.Temporality {
34+
return metricdata.Temporality(t)
35+
}

cmd/telemetrygen/pkg/metrics/config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
// Config describes the test scenario.
1616
type Config struct {
1717
common.Config
18-
NumMetrics int
19-
MetricName string
20-
MetricType MetricType
21-
TemporalityType TemporalityType
22-
SpanID string
23-
TraceID string
18+
NumMetrics int
19+
MetricName string
20+
MetricType MetricType
21+
AggregationTemporality AggregationTemporality
22+
SpanID string
23+
TraceID string
2424
}
2525

2626
// NewConfig creates a new Config with default values.
@@ -42,7 +42,7 @@ func (c *Config) Flags(fs *pflag.FlagSet) {
4242
fs.StringVar(&c.SpanID, "span-id", c.SpanID, "SpanID to use as exemplar")
4343

4444
fs.Var(&c.MetricType, "metric-type", "Metric type enum. must be one of 'Gauge' or 'Sum'")
45-
fs.Var(&c.TemporalityType, "temporality-type", "Temporality for Sum and Histogram metrics. Must be one of 'delta' or 'cumulative'")
45+
fs.Var(&c.AggregationTemporality, "aggregation-temporality", "aggregation-temporality for metrics. Must be one of 'delta' or 'cumulative'")
4646
}
4747

4848
// SetDefaults sets the default values for the configuration
@@ -57,7 +57,7 @@ func (c *Config) SetDefaults() {
5757
// Use Gauge as default metric type.
5858
c.MetricType = MetricTypeGauge
5959
// Use cumulative temporality as default.
60-
c.TemporalityType = TemporalityType(metricdata.CumulativeTemporality)
60+
c.AggregationTemporality = AggregationTemporality(metricdata.CumulativeTemporality)
6161

6262
c.TraceID = ""
6363
c.SpanID = ""

cmd/telemetrygen/pkg/metrics/metrics.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ func run(c *Config, expF exporterFunc, logger *zap.Logger) error {
6666
for i := 0; i < c.WorkerCount; i++ {
6767
wg.Add(1)
6868
w := worker{
69-
numMetrics: c.NumMetrics,
70-
metricName: c.MetricName,
71-
metricType: c.MetricType,
72-
temporalityType: c.TemporalityType,
73-
exemplars: exemplarsFromConfig(c),
74-
limitPerSecond: limit,
75-
totalDuration: c.TotalDuration,
76-
running: running,
77-
wg: &wg,
78-
logger: logger.With(zap.Int("worker", i)),
79-
index: i,
69+
numMetrics: c.NumMetrics,
70+
metricName: c.MetricName,
71+
metricType: c.MetricType,
72+
aggregationTemporality: c.AggregationTemporality,
73+
exemplars: exemplarsFromConfig(c),
74+
limitPerSecond: limit,
75+
totalDuration: c.TotalDuration,
76+
running: running,
77+
wg: &wg,
78+
logger: logger.With(zap.Int("worker", i)),
79+
index: i,
8080
}
8181
exp, err := expF()
8282
if err != nil {

cmd/telemetrygen/pkg/metrics/temporality_type.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

cmd/telemetrygen/pkg/metrics/worker.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ import (
1818
)
1919

2020
type worker struct {
21-
running *atomic.Bool // pointer to shared flag that indicates it's time to stop the test
22-
metricName string // name of metric to generate
23-
metricType MetricType // type of metric to generate
24-
temporalityType TemporalityType // Temporality type to use
25-
exemplars []metricdata.Exemplar[int64] // exemplars to attach to the metric
26-
numMetrics int // how many metrics the worker has to generate (only when duration==0)
27-
totalDuration time.Duration // how long to run the test for (overrides `numMetrics`)
28-
limitPerSecond rate.Limit // how many metrics per second to generate
29-
wg *sync.WaitGroup // notify when done
30-
logger *zap.Logger // logger
31-
index int // worker index
21+
running *atomic.Bool // pointer to shared flag that indicates it's time to stop the test
22+
metricName string // name of metric to generate
23+
metricType MetricType // type of metric to generate
24+
aggregationTemporality AggregationTemporality // Temporality type to use
25+
exemplars []metricdata.Exemplar[int64] // exemplars to attach to the metric
26+
numMetrics int // how many metrics the worker has to generate (only when duration==0)
27+
totalDuration time.Duration // how long to run the test for (overrides `numMetrics`)
28+
limitPerSecond rate.Limit // how many metrics per second to generate
29+
wg *sync.WaitGroup // notify when done
30+
logger *zap.Logger // logger
31+
index int // worker index
3232
}
3333

3434
var histogramBucketSamples = []struct {
@@ -104,7 +104,7 @@ func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Expor
104104
Name: w.metricName,
105105
Data: metricdata.Sum[int64]{
106106
IsMonotonic: true,
107-
Temporality: w.temporalityType.AsTemporality(),
107+
Temporality: w.aggregationTemporality.AsTemporality(),
108108
DataPoints: []metricdata.DataPoint[int64]{
109109
{
110110
StartTime: time.Now().Add(-1 * time.Second),
@@ -123,7 +123,7 @@ func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Expor
123123
metrics = append(metrics, metricdata.Metrics{
124124
Name: w.metricName,
125125
Data: metricdata.Histogram[int64]{
126-
Temporality: w.temporalityType.AsTemporality(),
126+
Temporality: w.aggregationTemporality.AsTemporality(),
127127
DataPoints: []metricdata.HistogramDataPoint[int64]{
128128
{
129129
StartTime: time.Now().Add(-1 * time.Second),

cmd/telemetrygen/pkg/metrics/worker_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ func (m *mockExporter) Shutdown(_ context.Context) error {
5050
return nil
5151
}
5252

53-
func checkMetricTemporality(t *testing.T, ms metricdata.Metrics, metricType MetricType, expectedTemporality metricdata.Temporality) {
53+
func checkMetricTemporality(t *testing.T, ms metricdata.Metrics, metricType MetricType, expectedAggregationTemporality metricdata.Temporality) {
5454
switch metricType {
5555
case MetricTypeSum:
5656
sumData, ok := ms.Data.(metricdata.Sum[int64])
5757
require.True(t, ok, "expected Sum data type")
58-
assert.Equal(t, expectedTemporality, sumData.Temporality)
58+
assert.Equal(t, expectedAggregationTemporality, sumData.Temporality)
5959
case MetricTypeHistogram:
6060
histogramData, ok := ms.Data.(metricdata.Histogram[int64])
6161
require.True(t, ok, "expected Histogram data type")
62-
assert.Equal(t, expectedTemporality, histogramData.Temporality)
62+
assert.Equal(t, expectedAggregationTemporality, histogramData.Temporality)
6363
default:
6464
t.Fatalf("unsupported metric type: %v", metricType)
6565
}
@@ -115,34 +115,34 @@ func TestRateOfMetrics(t *testing.T) {
115115

116116
func TestMetricsWithTemporality(t *testing.T) {
117117
tests := []struct {
118-
name string
119-
metricType MetricType
120-
temporalityType TemporalityType
121-
expectedTemporality metricdata.Temporality
118+
name string
119+
metricType MetricType
120+
aggregationTemporality AggregationTemporality
121+
expectedAggregationTemporality metricdata.Temporality
122122
}{
123123
{
124-
name: "Sum: delta temporality",
125-
metricType: MetricTypeSum,
126-
temporalityType: TemporalityType(metricdata.DeltaTemporality),
127-
expectedTemporality: metricdata.DeltaTemporality,
124+
name: "Sum: delta temporality",
125+
metricType: MetricTypeSum,
126+
aggregationTemporality: AggregationTemporality(metricdata.DeltaTemporality),
127+
expectedAggregationTemporality: metricdata.DeltaTemporality,
128128
},
129129
{
130-
name: "Sum: cumulative temporality",
131-
metricType: MetricTypeSum,
132-
temporalityType: TemporalityType(metricdata.CumulativeTemporality),
133-
expectedTemporality: metricdata.CumulativeTemporality,
130+
name: "Sum: cumulative temporality",
131+
metricType: MetricTypeSum,
132+
aggregationTemporality: AggregationTemporality(metricdata.CumulativeTemporality),
133+
expectedAggregationTemporality: metricdata.CumulativeTemporality,
134134
},
135135
{
136-
name: "Histogram: delta temporality",
137-
metricType: MetricTypeHistogram,
138-
temporalityType: TemporalityType(metricdata.DeltaTemporality),
139-
expectedTemporality: metricdata.DeltaTemporality,
136+
name: "Histogram: delta temporality",
137+
metricType: MetricTypeHistogram,
138+
aggregationTemporality: AggregationTemporality(metricdata.DeltaTemporality),
139+
expectedAggregationTemporality: metricdata.DeltaTemporality,
140140
},
141141
{
142-
name: "Histogram: cumulative temporality",
143-
metricType: MetricTypeHistogram,
144-
temporalityType: TemporalityType(metricdata.CumulativeTemporality),
145-
expectedTemporality: metricdata.CumulativeTemporality,
142+
name: "Histogram: cumulative temporality",
143+
metricType: MetricTypeHistogram,
144+
aggregationTemporality: AggregationTemporality(metricdata.CumulativeTemporality),
145+
expectedAggregationTemporality: metricdata.CumulativeTemporality,
146146
},
147147
}
148148

@@ -153,10 +153,10 @@ func TestMetricsWithTemporality(t *testing.T) {
153153
Config: common.Config{
154154
WorkerCount: 1,
155155
},
156-
NumMetrics: 1,
157-
MetricName: "test",
158-
MetricType: tt.metricType,
159-
TemporalityType: tt.temporalityType,
156+
NumMetrics: 1,
157+
MetricName: "test",
158+
MetricType: tt.metricType,
159+
AggregationTemporality: tt.aggregationTemporality,
160160
}
161161
m := &mockExporter{}
162162
expFunc := func() (sdkmetric.Exporter, error) {
@@ -174,7 +174,7 @@ func TestMetricsWithTemporality(t *testing.T) {
174174
ms := m.rms[0].ScopeMetrics[0].Metrics[0]
175175
assert.Equal(t, "test", ms.Name)
176176

177-
checkMetricTemporality(t, ms, tt.metricType, tt.expectedTemporality)
177+
checkMetricTemporality(t, ms, tt.metricType, tt.expectedAggregationTemporality)
178178
})
179179
}
180180
}

0 commit comments

Comments
 (0)