Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref app: update for otlp data quality testing #1082

Open
wants to merge 6 commits into
base: feature/otlpmain
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pipelines/azure-pipeline-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ trigger:
include:
- main
- feature/otlpmain
- grace/ref-app-update-march

pr:
autoCancel: true
branches:
include:
- main
- feature/otlpmain

variables:
HELM_CHART_NAME: 'prometheus-collector'
Expand Down
20 changes: 19 additions & 1 deletion internal/referenceapp/golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@ This app generates both Prometheus and OTLP metrics.
| `OTEL_TEMPORALITY` | string | `cumulative` or `delta` | `cumulative` |
| `OTEL_CONSOLE_METRICS` | bool | Print metrics to stdout instead of exporting | `false` |
| `OTEL_EXPORT_ENDPOINT` | string | GRPC endpoint to export metrics to | `localhost:4317` |
| `OTEL_INTERVAL` | int | How often to export metrics in seconds | `15` |
| `OTEL_INTERVAL` | int | How often to export metrics in seconds | `15` |

### OTLP Data Quality Testing
The logic for each metric recorded is [here](main.go?plain=1#L309) with function `recordTestMetrics()`.

Each metric is emitted with cumulative and delta settings. Each metric will have a one time series with label `temporality`=`cumulative` and one with label `temporality`=`delta`.

| Metric Name | Type | Int/Float | Labels | Values Emitted |
|---------------------------|----------|-----------|-----------------|----------------|
| `otlpapp.intcounter.total`| counter | int | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>` | Increment by 1 every 60s |
| `otlpapp.floatcounter.total`| counter| float | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>`| Increment by 1.5 every 60s |
| `otlpapp.intgauge` | gauge | int | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>` | Alternate between recording 1 and 2 every 60s |
| `otlpapp.floatgauge` | gauge | float | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>` | Alternate between recording 1.5 and 2.5 every 60s |
| `otlpapp.intupdowncounter`| updown counter | int | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>`| Alternate between incrementing by 2 every 60s and decrementing by 1 every 60s |
| `otlpapp.floatupdowncounter`| updown counter | float | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>`| Alternate between incrementing by 2.5 every 60s and decrementing by 1.5 every 60s |
| `otlpapp.intexponentialhistogram` | exponential histogram | int | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>` | Alternate between recording 1 and 2 every 60s |
| `otlpapp.floatexponentialhistogram` | exponential histogram | float | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>` | Alternate between recording 0.5 and 1.5 every 60s |
| `otlpapp.intexplicithistogram` | explicit histogram | int | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>` | Alternate between recording 1 and 2 every 60s |
| `otlpapp.floatexplicithistogram` | explicit histogram | float | `label.1`=`label.1-value`, `label.2`=`label.2-value`, `temporality`=`<cumulative/delta>` | Alternate between recording 0.5 and 1.5 every 60s |
2 changes: 0 additions & 2 deletions internal/referenceapp/golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/vishiy/opentelemetry-collector-builder

go 1.22.7

toolchain go1.23.2

require (
github.com/prometheus/client_golang v1.11.1
go.opentelemetry.io/otel v1.33.0
Expand Down
111 changes: 110 additions & 1 deletion internal/referenceapp/golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,54 @@ func recordPerfMetrics() {
}()
}

func recordTestMetrics() {
go func() {
i := 0

ctx := context.Background()
metricAttributes := attribute.NewSet(
attribute.String("label.1", "label.1-value"),
attribute.String("label.2", "label.2-value"),
attribute.String("temporality", temporalityLabel),
)
for {
otlpIntCounterTest.Add(ctx, 1, metric.WithAttributeSet(metricAttributes))
otlpFloatCounterTest.Add(ctx, 1.5, metric.WithAttributeSet(metricAttributes))

// Add 2 on even loop, subtract 1 on odd loop
if i%2 == 0 {
otlpIntGaugeTest.Record(ctx, 2, metric.WithAttributeSet(metricAttributes))
otlpFloatGaugeTest.Record(ctx, 2.5, metric.WithAttributeSet(metricAttributes))

otlpIntUpDownCounterTest.Add(ctx, 2, metric.WithAttributeSet(metricAttributes))
otlpFloatUpDownCounterTest.Add(ctx, 2.5, metric.WithAttributeSet(metricAttributes))

otlpIntExponentialHistogramTest.Record(ctx, 1, metric.WithAttributeSet(metricAttributes))
otlpFloatExponentialHistogramTest.Record(ctx, 0.5, metric.WithAttributeSet(metricAttributes))

otlpIntExplicitHistogramTest.Record(ctx, 1, metric.WithAttributeSet(metricAttributes))
otlpFloatExplicitHistogramTest.Record(ctx, 0.5, metric.WithAttributeSet(metricAttributes))

} else {
otlpIntGaugeTest.Record(ctx, 1, metric.WithAttributeSet(metricAttributes))
otlpFloatGaugeTest.Record(ctx, 1.5, metric.WithAttributeSet(metricAttributes))

otlpIntUpDownCounterTest.Add(ctx, -1, metric.WithAttributeSet(metricAttributes))
otlpFloatUpDownCounterTest.Add(ctx, -1.5, metric.WithAttributeSet(metricAttributes))

otlpIntExponentialHistogramTest.Record(ctx, 2, metric.WithAttributeSet(metricAttributes))
otlpFloatExponentialHistogramTest.Record(ctx, 1.5, metric.WithAttributeSet(metricAttributes))

otlpIntExplicitHistogramTest.Record(ctx, 2, metric.WithAttributeSet(metricAttributes))
otlpFloatExplicitHistogramTest.Record(ctx, 1.5, metric.WithAttributeSet(metricAttributes))
}

i++
time.Sleep(60 * time.Second)
}
}()
}

func createGauges() {
for i := 0; i < metricCount; i++ {
name := fmt.Sprintf("myapp_temperature_%d", i)
Expand All @@ -331,6 +379,19 @@ var (
otlpExponentialRainfallHistogram metric.Float64Histogram
otlpExplicitRainfallHistogram metric.Float64Histogram

otlpIntCounterTest metric.Int64Counter
otlpFloatCounterTest metric.Float64Counter
otlpIntGaugeTest metric.Int64Gauge
otlpFloatGaugeTest metric.Float64Gauge
otlpIntUpDownCounterTest metric.Int64UpDownCounter
otlpFloatUpDownCounterTest metric.Float64UpDownCounter
otlpIntExponentialHistogramTest metric.Int64Histogram
otlpFloatExponentialHistogramTest metric.Float64Histogram
otlpIntExplicitHistogramTest metric.Int64Histogram
otlpFloatExplicitHistogramTest metric.Float64Histogram

temporalityLabel string

scrapeIntervalSec = 60
metricCount = 10000
gaugeList = make([]*prometheus.GaugeVec, 0, metricCount)
Expand Down Expand Up @@ -516,7 +577,8 @@ func main() {
createGauges()
recordPerfMetrics()
} else {
recordMetrics()
//recordMetrics()
recordTestMetrics()
}

untypedServer := http.NewServeMux()
Expand Down Expand Up @@ -566,6 +628,10 @@ func setupOTLP() {

// The default temporality should be cumulative unless specified as delta otherwise
deltaTemporality := os.Getenv("OTEL_TEMPORALITY") == "delta"
temporalityLabel = "cumulative"
if deltaTemporality {
temporalityLabel = "delta"
}

// Export as stdout logs instead for debugging
if os.Getenv("OTEL_CONSOLE_METRICS") == "true" {
Expand Down Expand Up @@ -643,6 +709,49 @@ func setupOTLP() {

// Actually register metrics with the meter provider. These will then be used to record values
otlpMeter := provider.Meter("referenceapp")
otlpIntCounterTest, _ = otlpMeter.Int64Counter(
"otlpapp.intcounter.total",
metric.WithUnit("1"),
)
otlpFloatCounterTest, _ = otlpMeter.Float64Counter(
"otlpapp.floatcounter.total",
metric.WithUnit("1"),
)
otlpIntGaugeTest, _ = otlpMeter.Int64Gauge(
"otlpapp.intgauge",
metric.WithUnit("1"),
)
otlpFloatGaugeTest, _ = otlpMeter.Float64Gauge(
"otlpapp.floatgauge",
metric.WithUnit("1"),
)
otlpIntUpDownCounterTest, _ = otlpMeter.Int64UpDownCounter(
"otlpapp.intupdowncounter",
metric.WithUnit("1"),
)
otlpFloatUpDownCounterTest, _ = otlpMeter.Float64UpDownCounter(
"otlpapp.floatupdowncounter",
metric.WithUnit("1"),
)
otlpIntExponentialHistogramTest, _ = otlpMeter.Int64Histogram(
"otlpapp.intexponentialhistogram",
metric.WithUnit("1"),
)
otlpFloatExponentialHistogramTest, _ = otlpMeter.Float64Histogram(
"otlpapp.floatexponentialhistogram",
metric.WithUnit("1"),
)
otlpIntExplicitHistogramTest, _ = otlpMeter.Int64Histogram(
"otlpapp.intexplicithistogram",
metric.WithUnit("1"),
metric.WithExplicitBucketBoundaries(0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
)
otlpFloatExplicitHistogramTest, _ = otlpMeter.Float64Histogram(
"otlpapp.floatexplicithistogram",
metric.WithUnit("1"),
metric.WithExplicitBucketBoundaries(0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25),
)

otlpCounter, _ = otlpMeter.Int64Counter(
"myotelapp.measurements.total",
metric.WithUnit("1"),
Expand Down