Repository: prometheus/prometheus
File: web/federate.go (Go)

Code before:
			lastHistogramWasGauge = false
			protMetric.Untyped = &dto.Untyped{
				Value: proto.Float64(s.F),
			}
		} else {
			lastHistogramWasGauge = s.H.CounterResetHint == histogram.GaugeType
			if s.H.UsesCustomBuckets() {
				protMetric.Histogram = makeClassicHistogram(s.H)
			} else {
				protMetric.Histogram = makeNativeHistogram(s.H)
			}
		}
		lastWasHistogram = isHistogram
		protMetricFam.Metric = append(protMetricFam.Metric, protMetric)
	}
	// Still have to ship off the last MetricDescriptor, if any.
	if protMetricFam != nil {
		if err := enc.Encode(protMetricFam); err != nil {
			federationErrors.Inc()
			h.logger.Error("federation failed", "err", err)
		}
	}
}

// makeNativeHistogram creates a dto.Histogram representing a native histogram.
// Use only for standard exponential schemal.
func makeNativeHistogram(h *histogram.FloatHistogram) *dto.Histogram {
	result := &dto.Histogram{
		SampleCountFloat: proto.Float64(h.Count),
		SampleSum:        proto.Float64(h.Sum),
		Schema:           proto.Int32(h.Schema),
		ZeroThreshold:    proto.Float64(h.ZeroThreshold),
		ZeroCountFloat:   proto.Float64(h.ZeroCount),
		NegativeCount:    h.NegativeBuckets,
		PositiveCount:    h.PositiveBuckets,
	}
	if len(h.PositiveSpans) > 0 {
		result.PositiveSpan = make([]*dto.BucketSpan, len(h.PositiveSpans))
		for i, sp := range h.PositiveSpans {
			result.PositiveSpan[i] = &dto.BucketSpan{
				Offset: proto.Int32(sp.Offset),
				Length: proto.Uint32(sp.Length),
			}
		}
	}
	if len(h.NegativeSpans) > 0 {
		result.NegativeSpan = make([]*dto.BucketSpan, len(h.NegativeSpans))
		for i, sp := range h.NegativeSpans {
			result.NegativeSpan[i] = &dto.BucketSpan{
				Offset: proto.Int32(sp.Offset),
				Length: proto.Uint32(sp.Length),

Review comment (suggestion):
```suggestion
// Use only for standard exponential schema.
```

Code after:
			lastHistogramWasGauge = false
			protMetric.Untyped = &dto.Untyped{
				Value: proto.Float64(s.F),
			}
		} else {
			lastHistogramWasGauge = s.H.CounterResetHint == histogram.GaugeType
			if s.H.UsesCustomBuckets() {
				protMetric.Histogram = makeClassicHistogram(s.H)
			} else {
				protMetric.Histogram = makeNativeHistogram(s.H)
			}
		}
		lastWasHistogram = isHistogram
		protMetricFam.Metric = append(protMetricFam.Metric, protMetric)
	}
	// Still have to ship off the last MetricDescriptor, if any.
	if protMetricFam != nil {
		if err := enc.Encode(protMetricFam); err != nil {
			federationErrors.Inc()
			h.logger.Error("federation failed", "err", err)
		}
	}
}

// makeNativeHistogram creates a dto.Histogram representing a native histogram.
// Use only for standard exponential schemas.
func makeNativeHistogram(h *histogram.FloatHistogram) *dto.Histogram {
	result := &dto.Histogram{
		SampleCountFloat: proto.Float64(h.Count),
		SampleSum:        proto.Float64(h.Sum),
		Schema:           proto.Int32(h.Schema),
		ZeroThreshold:    proto.Float64(h.ZeroThreshold),
		ZeroCountFloat:   proto.Float64(h.ZeroCount),
		NegativeCount:    h.NegativeBuckets,
		PositiveCount:    h.PositiveBuckets,
	}
	if len(h.PositiveSpans) > 0 {
		result.PositiveSpan = make([]*dto.BucketSpan, len(h.PositiveSpans))
		for i, sp := range h.PositiveSpans {
			result.PositiveSpan[i] = &dto.BucketSpan{
				Offset: proto.Int32(sp.Offset),
				Length: proto.Uint32(sp.Length),
			}
		}
	}
	if len(h.NegativeSpans) > 0 {
		result.NegativeSpan = make([]*dto.BucketSpan, len(h.NegativeSpans))
		for i, sp := range h.NegativeSpans {
			result.NegativeSpan[i] = &dto.BucketSpan{
				Offset: proto.Int32(sp.Offset),
				Length: proto.Uint32(sp.Length),