mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Make the scrape.metricMetadataStore interface public
To test the implementation of our metric metadata API, we need to represent various states of metadata in the scrape metadata store. That is currently not possible as the interface and method to set the store are private. This changes the interface, list and get methods, and the SetMetadaStore function to be public. Incidentally, the scrapeCache implementation needs to be renamed to match the new signature. Signed-off-by: gotjosh <josue@grafana.com>
This commit is contained in:
parent
4bf9c6bb82
commit
05842176a6
|
@ -209,7 +209,7 @@ func newScrapePool(cfg *config.ScrapeConfig, app Appendable, jitterSeed uint64,
|
|||
sp.newLoop = func(opts scrapeLoopOptions) loop {
|
||||
// Update the targets retrieval function for metadata to a new scrape cache.
|
||||
cache := newScrapeCache()
|
||||
opts.target.setMetadataStore(cache)
|
||||
opts.target.SetMetadataStore(cache)
|
||||
|
||||
return newScrapeLoop(
|
||||
ctx,
|
||||
|
@ -794,7 +794,7 @@ func (c *scrapeCache) setUnit(metric, unit []byte) {
|
|||
c.metaMtx.Unlock()
|
||||
}
|
||||
|
||||
func (c *scrapeCache) getMetadata(metric string) (MetricMetadata, bool) {
|
||||
func (c *scrapeCache) GetMetadata(metric string) (MetricMetadata, bool) {
|
||||
c.metaMtx.Lock()
|
||||
defer c.metaMtx.Unlock()
|
||||
|
||||
|
@ -810,7 +810,7 @@ func (c *scrapeCache) getMetadata(metric string) (MetricMetadata, bool) {
|
|||
}, true
|
||||
}
|
||||
|
||||
func (c *scrapeCache) listMetadata() []MetricMetadata {
|
||||
func (c *scrapeCache) ListMetadata() []MetricMetadata {
|
||||
c.metaMtx.Lock()
|
||||
defer c.metaMtx.Unlock()
|
||||
|
||||
|
|
|
@ -615,19 +615,19 @@ test_metric 1
|
|||
testutil.Ok(t, err)
|
||||
testutil.Equals(t, 1, total)
|
||||
|
||||
md, ok := cache.getMetadata("test_metric")
|
||||
md, ok := cache.GetMetadata("test_metric")
|
||||
testutil.Assert(t, ok, "expected metadata to be present")
|
||||
testutil.Assert(t, textparse.MetricTypeCounter == md.Type, "unexpected metric type")
|
||||
testutil.Equals(t, "some help text", md.Help)
|
||||
testutil.Equals(t, "metric", md.Unit)
|
||||
|
||||
md, ok = cache.getMetadata("test_metric_no_help")
|
||||
md, ok = cache.GetMetadata("test_metric_no_help")
|
||||
testutil.Assert(t, ok, "expected metadata to be present")
|
||||
testutil.Assert(t, textparse.MetricTypeGauge == md.Type, "unexpected metric type")
|
||||
testutil.Equals(t, "", md.Help)
|
||||
testutil.Equals(t, "", md.Unit)
|
||||
|
||||
md, ok = cache.getMetadata("test_metric_no_type")
|
||||
md, ok = cache.GetMetadata("test_metric_no_type")
|
||||
testutil.Assert(t, ok, "expected metadata to be present")
|
||||
testutil.Assert(t, textparse.MetricTypeUnknown == md.Type, "unexpected metric type")
|
||||
testutil.Equals(t, "other help text", md.Help)
|
||||
|
|
|
@ -58,7 +58,7 @@ type Target struct {
|
|||
lastScrape time.Time
|
||||
lastScrapeDuration time.Duration
|
||||
health TargetHealth
|
||||
metadata metricMetadataStore
|
||||
metadata MetricMetadataStore
|
||||
}
|
||||
|
||||
// NewTarget creates a reasonably configured target for querying.
|
||||
|
@ -75,9 +75,9 @@ func (t *Target) String() string {
|
|||
return t.URL().String()
|
||||
}
|
||||
|
||||
type metricMetadataStore interface {
|
||||
listMetadata() []MetricMetadata
|
||||
getMetadata(metric string) (MetricMetadata, bool)
|
||||
type MetricMetadataStore interface {
|
||||
ListMetadata() []MetricMetadata
|
||||
GetMetadata(metric string) (MetricMetadata, bool)
|
||||
}
|
||||
|
||||
// MetricMetadata is a piece of metadata for a metric.
|
||||
|
@ -95,7 +95,7 @@ func (t *Target) MetadataList() []MetricMetadata {
|
|||
if t.metadata == nil {
|
||||
return nil
|
||||
}
|
||||
return t.metadata.listMetadata()
|
||||
return t.metadata.ListMetadata()
|
||||
}
|
||||
|
||||
// Metadata returns type and help metadata for the given metric.
|
||||
|
@ -106,10 +106,10 @@ func (t *Target) Metadata(metric string) (MetricMetadata, bool) {
|
|||
if t.metadata == nil {
|
||||
return MetricMetadata{}, false
|
||||
}
|
||||
return t.metadata.getMetadata(metric)
|
||||
return t.metadata.GetMetadata(metric)
|
||||
}
|
||||
|
||||
func (t *Target) setMetadataStore(s metricMetadataStore) {
|
||||
func (t *Target) SetMetadataStore(s MetricMetadataStore) {
|
||||
t.mtx.Lock()
|
||||
defer t.mtx.Unlock()
|
||||
t.metadata = s
|
||||
|
|
Loading…
Reference in a new issue