mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add a few more tests; remove unused helpers
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
This commit is contained in:
parent
32cf14c339
commit
5227af2e59
|
@ -181,6 +181,9 @@ func (c *flagConfig) setFeatureListOptions(logger log.Logger) error {
|
|||
case "extra-scrape-metrics":
|
||||
c.scrape.ExtraMetrics = true
|
||||
level.Info(logger).Log("msg", "Experimental additional scrape metrics enabled")
|
||||
case "metadata-storage":
|
||||
c.scrape.EnableMetadataStorage = true
|
||||
level.Info(logger).Log("msg", "Experimental in-memory metadata storage enabled")
|
||||
case "new-service-discovery-manager":
|
||||
c.enableNewSDManager = true
|
||||
level.Info(logger).Log("msg", "Experimental service discovery manager")
|
||||
|
|
|
@ -36,7 +36,6 @@ import (
|
|||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
||||
"github.com/prometheus/prometheus/tsdb/chunks"
|
||||
"github.com/prometheus/prometheus/tsdb/record"
|
||||
)
|
||||
|
||||
// decodeReadLimit is the maximum size of a read request body in bytes.
|
||||
|
@ -757,15 +756,6 @@ func spansToSpansProto(s []histogram.Span) []prompb.BucketSpan {
|
|||
return spans
|
||||
}
|
||||
|
||||
func MetadataToMetadataProto(metricName string, m record.RefMetadata) prompb.MetricMetadata {
|
||||
return prompb.MetricMetadata{
|
||||
MetricFamilyName: metricName,
|
||||
Type: metricTypeToMetricTypeProto(record.ToTextparseMetricType(m.Type)),
|
||||
Help: m.Help,
|
||||
Unit: m.Unit,
|
||||
}
|
||||
}
|
||||
|
||||
// LabelProtosToMetric unpack a []*prompb.Label to a model.Metric
|
||||
func LabelProtosToMetric(labelPairs []*prompb.Label) model.Metric {
|
||||
metric := make(model.Metric, len(labelPairs))
|
||||
|
|
|
@ -57,6 +57,7 @@ var writeRequestFixture = &prompb.WriteRequest{
|
|||
Samples: []prompb.Sample{{Value: 1, Timestamp: 0}},
|
||||
Exemplars: []prompb.Exemplar{{Labels: []prompb.Label{{Name: "f", Value: "g"}}, Value: 1, Timestamp: 0}},
|
||||
Histograms: []prompb.Histogram{HistogramToHistogramProto(0, &testHistogram), FloatHistogramToHistogramProto(1, testHistogram.ToFloat())},
|
||||
Metadatas: []prompb.Metadata{{Type: prompb.Metadata_COUNTER, Help: "help text 1", Unit: "unit text 1"}},
|
||||
},
|
||||
{
|
||||
Labels: []prompb.Label{
|
||||
|
@ -69,6 +70,7 @@ var writeRequestFixture = &prompb.WriteRequest{
|
|||
Samples: []prompb.Sample{{Value: 2, Timestamp: 1}},
|
||||
Exemplars: []prompb.Exemplar{{Labels: []prompb.Label{{Name: "h", Value: "i"}}, Value: 2, Timestamp: 1}},
|
||||
Histograms: []prompb.Histogram{HistogramToHistogramProto(2, &testHistogram), FloatHistogramToHistogramProto(3, testHistogram.ToFloat())},
|
||||
Metadatas: []prompb.Metadata{{Type: prompb.Metadata_GAUGE, Help: "help text 2", Unit: "unit text 2"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1614,7 +1614,7 @@ func (s *shards) sendSamplesWithBackoff(ctx context.Context, samples []prompb.Ti
|
|||
s.qm.metrics.samplesTotal.Add(float64(sampleCount))
|
||||
s.qm.metrics.exemplarsTotal.Add(float64(exemplarCount))
|
||||
s.qm.metrics.histogramsTotal.Add(float64(histogramCount))
|
||||
s.qm.metrics.metadataTotal.Add(float64(histogramCount))
|
||||
s.qm.metrics.metadataTotal.Add(float64(metadataCount))
|
||||
err := s.qm.client().Store(ctx, *buf)
|
||||
s.qm.metrics.sentBatchDuration.Observe(time.Since(begin).Seconds())
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ func TestRemoteWriteHandler(t *testing.T) {
|
|||
i := 0
|
||||
j := 0
|
||||
k := 0
|
||||
l := 0
|
||||
for _, ts := range writeRequestFixture.Timeseries {
|
||||
labels := labelProtosToLabels(ts.Labels)
|
||||
for _, s := range ts.Samples {
|
||||
|
@ -78,6 +79,11 @@ func TestRemoteWriteHandler(t *testing.T) {
|
|||
|
||||
k++
|
||||
}
|
||||
|
||||
for _, m := range ts.Metadatas {
|
||||
require.Equal(t, mockMetadata{labels, int32(m.Type), m.Unit, m.Help}, appendable.metadata[l])
|
||||
l++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,6 +245,7 @@ type mockAppendable struct {
|
|||
exemplars []mockExemplar
|
||||
latestHistogram int64
|
||||
histograms []mockHistogram
|
||||
metadata []mockMetadata
|
||||
commitErr error
|
||||
}
|
||||
|
||||
|
@ -262,6 +269,13 @@ type mockHistogram struct {
|
|||
fh *histogram.FloatHistogram
|
||||
}
|
||||
|
||||
type mockMetadata struct {
|
||||
l labels.Labels
|
||||
mtype int32
|
||||
unit string
|
||||
help string
|
||||
}
|
||||
|
||||
func (m *mockAppendable) Appender(_ context.Context) storage.Appender {
|
||||
return m
|
||||
}
|
||||
|
@ -304,8 +318,7 @@ func (m *mockAppendable) AppendHistogram(_ storage.SeriesRef, l labels.Labels, t
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
func (m *mockAppendable) UpdateMetadata(_ storage.SeriesRef, _ labels.Labels, _ metadata.Metadata) (storage.SeriesRef, error) {
|
||||
// TODO: Wire metadata in a mockAppendable field when we get around to handling metadata in remote_write.
|
||||
// UpdateMetadata is no-op for remote write (where mockAppendable is being used to test) for now.
|
||||
func (m *mockAppendable) UpdateMetadata(_ storage.SeriesRef, l labels.Labels, mp metadata.Metadata) (storage.SeriesRef, error) {
|
||||
m.metadata = append(m.metadata, mockMetadata{l, int32(metricTypeToProtoEquivalent(mp.Type)), mp.Unit, mp.Help})
|
||||
return 0, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue