newNativeHistogramWithClassicBuckets returns a Metric representing a native histogram that also has classic buckets. This is for testing purposes.
( desc *Desc, count uint64, sum float64, positiveBuckets, negativeBuckets map[int]int64, zeroBucket uint64, schema int32, zeroThreshold float64, createdTimestamp time.Time, // DummyNativeHistogram also defines buckets in the metric for testing buckets []*dto.Bucket, labelValues ...string, )
| 297 | // newNativeHistogramWithClassicBuckets returns a Metric representing |
| 298 | // a native histogram that also has classic buckets. This is for testing purposes. |
| 299 | func newNativeHistogramWithClassicBuckets( |
| 300 | desc *Desc, |
| 301 | count uint64, |
| 302 | sum float64, |
| 303 | positiveBuckets, negativeBuckets map[int]int64, |
| 304 | zeroBucket uint64, |
| 305 | schema int32, |
| 306 | zeroThreshold float64, |
| 307 | createdTimestamp time.Time, |
| 308 | // DummyNativeHistogram also defines buckets in the metric for testing |
| 309 | buckets []*dto.Bucket, |
| 310 | labelValues ...string, |
| 311 | ) (Metric, error) { |
| 312 | if desc.err != nil { |
| 313 | fmt.Println("error", desc.err) |
| 314 | return nil, desc.err |
| 315 | } |
| 316 | if err := validateLabelValues(labelValues, len(desc.variableLabels.names)); err != nil { |
| 317 | return nil, err |
| 318 | } |
| 319 | if schema > nativeHistogramSchemaMaximum || schema < nativeHistogramSchemaMinimum { |
| 320 | return nil, errors.New("invalid native histogram schema") |
| 321 | } |
| 322 | if err := validateCount(sum, count, negativeBuckets, positiveBuckets, zeroBucket); err != nil { |
| 323 | return nil, err |
| 324 | } |
| 325 | |
| 326 | NegativeSpan, NegativeDelta := makeBucketsFromMap(negativeBuckets) |
| 327 | PositiveSpan, PositiveDelta := makeBucketsFromMap(positiveBuckets) |
| 328 | ret := &constNativeHistogram{ |
| 329 | desc: desc, |
| 330 | Histogram: dto.Histogram{ |
| 331 | CreatedTimestamp: timestamppb.New(createdTimestamp), |
| 332 | Schema: &schema, |
| 333 | ZeroThreshold: &zeroThreshold, |
| 334 | SampleCount: &count, |
| 335 | SampleSum: &sum, |
| 336 | |
| 337 | NegativeSpan: NegativeSpan, |
| 338 | NegativeDelta: NegativeDelta, |
| 339 | |
| 340 | PositiveSpan: PositiveSpan, |
| 341 | PositiveDelta: PositiveDelta, |
| 342 | |
| 343 | ZeroCount: proto.Uint64(zeroBucket), |
| 344 | |
| 345 | // DummyNativeHistogram also defines buckets in the metric |
| 346 | Bucket: buckets, |
| 347 | }, |
| 348 | labelPairs: MakeLabelPairs(desc, labelValues), |
| 349 | } |
| 350 | if *ret.ZeroThreshold == 0 && *ret.ZeroCount == 0 && len(ret.PositiveSpan) == 0 && len(ret.NegativeSpan) == 0 { |
| 351 | ret.PositiveSpan = []*dto.BucketSpan{{ |
| 352 | Offset: proto.Int32(0), |
| 353 | Length: proto.Uint32(0), |
| 354 | }} |
| 355 | } |
| 356 | return ret, nil |
no test coverage detected