MCPcopy
hub / github.com/prometheus/prometheus / generateOTLPWriteRequest

Function generateOTLPWriteRequest

storage/remote/write_otlp_handler_test.go:287–372  ·  view source on GitHub ↗
(timestamp, startTime time.Time)

Source from the content-addressed store, hash-verified

285}
286
287func generateOTLPWriteRequest(timestamp, startTime time.Time) pmetricotlp.ExportRequest {
288 d := pmetric.NewMetrics()
289
290 // Generate One Counter, One Gauge, One Histogram, One Exponential-Histogram
291 // with resource attributes: service.name="test-service", service.instance.id="test-instance", host.name="test-host"
292 // with metric attribute: foo.bar="baz"
293
294 resourceMetric := d.ResourceMetrics().AppendEmpty()
295 resourceMetric.Resource().Attributes().PutStr("service.name", "test-service")
296 resourceMetric.Resource().Attributes().PutStr("service.instance.id", "test-instance")
297 resourceMetric.Resource().Attributes().PutStr("host.name", "test-host")
298
299 scopeMetric := resourceMetric.ScopeMetrics().AppendEmpty()
300
301 // Generate One Counter
302 counterMetric := scopeMetric.Metrics().AppendEmpty()
303 counterMetric.SetName("test.counter")
304 counterMetric.SetDescription("test-counter-description")
305 counterMetric.SetUnit("By")
306 counterMetric.SetEmptySum()
307 counterMetric.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
308 counterMetric.Sum().SetIsMonotonic(true)
309
310 counterDataPoint := counterMetric.Sum().DataPoints().AppendEmpty()
311 counterDataPoint.SetTimestamp(pcommon.NewTimestampFromTime(timestamp))
312 counterDataPoint.SetStartTimestamp(pcommon.NewTimestampFromTime(startTime))
313 counterDataPoint.SetDoubleValue(10.0)
314 counterDataPoint.Attributes().PutStr("foo.bar", "baz")
315
316 counterExemplar := counterDataPoint.Exemplars().AppendEmpty()
317
318 counterExemplar.SetTimestamp(pcommon.NewTimestampFromTime(timestamp))
319 counterExemplar.SetDoubleValue(10.0)
320 counterExemplar.SetSpanID(pcommon.SpanID{0, 1, 2, 3, 4, 5, 6, 7})
321 counterExemplar.SetTraceID(pcommon.TraceID{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15})
322
323 // Generate One Gauge
324 gaugeMetric := scopeMetric.Metrics().AppendEmpty()
325 gaugeMetric.SetName("test.gauge")
326 gaugeMetric.SetDescription("test-gauge-description")
327 gaugeMetric.SetUnit("By")
328 gaugeMetric.SetEmptyGauge()
329
330 gaugeDataPoint := gaugeMetric.Gauge().DataPoints().AppendEmpty()
331 gaugeDataPoint.SetTimestamp(pcommon.NewTimestampFromTime(timestamp))
332 gaugeDataPoint.SetStartTimestamp(pcommon.NewTimestampFromTime(startTime))
333 gaugeDataPoint.SetDoubleValue(10.0)
334 gaugeDataPoint.Attributes().PutStr("foo.bar", "baz")
335
336 // Generate One Histogram
337 histogramMetric := scopeMetric.Metrics().AppendEmpty()
338 histogramMetric.SetName("test.histogram")
339 histogramMetric.SetDescription("test-histogram-description")
340 histogramMetric.SetUnit("By")
341 histogramMetric.SetEmptyHistogram()
342 histogramMetric.Histogram().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
343
344 histogramDataPoint := histogramMetric.Histogram().DataPoints().AppendEmpty()

Callers 1

TestOTLPWriteHandlerFunction · 0.85

Calls 4

SetCountMethod · 0.80
SetSumMethod · 0.80
HistogramMethod · 0.65
ExemplarsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…