Skip to content

Commit

Permalink
Merge branch 'main' into internal-to-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
odubajDT authored Dec 17, 2024
2 parents 43cf2de + 9cb09d5 commit fc687df
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .chloggen/telemetrygen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: cmd/telemetrygen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Introduce support for generating histograms in telemetrygen

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36322]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
9 changes: 5 additions & 4 deletions cmd/telemetrygen/internal/metrics/metrics_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
type metricType string

const (
metricTypeGauge = "Gauge"
metricTypeSum = "Sum"
metricTypeGauge = "Gauge"
metricTypeSum = "Sum"
metricTypeHistogram = "Histogram"
)

// String is used both by fmt.Print and by Cobra in help text
Expand All @@ -22,11 +23,11 @@ func (e *metricType) String() string {
// Set must have pointer receiver so it doesn't change the value of a copy
func (e *metricType) Set(v string) error {
switch v {
case "Gauge", "Sum":
case "Gauge", "Sum", "Histogram":
*e = metricType(v)
return nil
default:
return errors.New(`must be one of "Gauge" or "Sum"`)
return errors.New(`must be one of "Gauge", "Sum", "Histogram"`)
}
}

Expand Down
69 changes: 69 additions & 0 deletions cmd/telemetrygen/internal/metrics/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,52 @@ type worker struct {
index int // worker index
}

var histogramBucketSamples = []struct {
bucketCounts []uint64
sum int64
}{
{
[]uint64{0, 0, 1, 0, 0, 0, 3, 4, 1, 1, 0, 0, 0, 0, 0},
3940,
},
{
[]uint64{0, 0, 0, 0, 0, 0, 2, 4, 4, 0, 0, 0, 0, 0, 0},
4455,
},
{
[]uint64{0, 0, 0, 0, 0, 0, 1, 4, 3, 2, 0, 0, 0, 0, 0},
5337,
},
{
[]uint64{0, 0, 1, 0, 1, 0, 2, 2, 1, 3, 0, 0, 0, 0, 0},
4477,
},
{
[]uint64{0, 0, 0, 0, 0, 1, 3, 2, 2, 2, 0, 0, 0, 0, 0},
4670,
},
{
[]uint64{0, 0, 0, 1, 1, 0, 1, 1, 1, 5, 0, 0, 0, 0, 0},
5670,
},
{
[]uint64{0, 0, 0, 0, 0, 2, 1, 1, 4, 2, 0, 0, 0, 0, 0},
5091,
},
{
[]uint64{0, 0, 2, 0, 0, 0, 2, 4, 1, 1, 0, 0, 0, 0, 0},
3420,
},
{
[]uint64{0, 0, 0, 0, 0, 0, 1, 3, 2, 4, 0, 0, 0, 0, 0},
5917,
},
{
[]uint64{0, 0, 1, 0, 1, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0},
3988,
},
}

func (w worker) simulateMetrics(res *resource.Resource, exporterFunc func() (sdkmetric.Exporter, error), signalAttrs []attribute.KeyValue) {
limiter := rate.NewLimiter(w.limitPerSecond, 1)

Expand Down Expand Up @@ -82,6 +128,29 @@ func (w worker) simulateMetrics(res *resource.Resource, exporterFunc func() (sdk
},
},
})
case metricTypeHistogram:
iteration := uint64(i) % 10
sum := histogramBucketSamples[iteration].sum
bucketCounts := histogramBucketSamples[iteration].bucketCounts
metrics = append(metrics, metricdata.Metrics{
Name: w.metricName,
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.HistogramDataPoint[int64]{
{
StartTime: time.Now().Add(-1 * time.Second),
Time: time.Now(),
Attributes: attribute.NewSet(signalAttrs...),
Exemplars: w.exemplars,
Count: iteration,
Sum: sum,
// Bounds from https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: bucketCounts,
},
},
},
})
default:
w.logger.Fatal("unknown metric type")
}
Expand Down

0 comments on commit fc687df

Please sign in to comment.