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 3 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
1 change: 1 addition & 0 deletions .pipelines/azure-pipeline-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pr:
branches:
include:
- main
- feature/otlpmain

variables:
HELM_CHART_NAME: 'prometheus-collector'
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
Loading