mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #356 from prometheus/refactor/retrieval-ingester
Make retrieval work with client's new Ingester interface.
This commit is contained in:
commit
c453445390
|
@ -202,6 +202,19 @@ func (t *target) Scrape(earliest time.Time, results chan<- *extraction.Result) e
|
||||||
|
|
||||||
const acceptHeader = `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,application/json;schema=prometheus/telemetry;version=0.0.2;q=0.2,*/*;q=0.1`
|
const acceptHeader = `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,application/json;schema=prometheus/telemetry;version=0.0.2;q=0.2,*/*;q=0.1`
|
||||||
|
|
||||||
|
type extendLabelsIngester struct {
|
||||||
|
baseLabels clientmodel.LabelSet
|
||||||
|
results chan<- *extraction.Result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *extendLabelsIngester) Ingest(r *extraction.Result) error {
|
||||||
|
for _, s := range r.Samples {
|
||||||
|
s.Metric.MergeFromLabelSet(i.baseLabels, clientmodel.ExporterLabelPrefix)
|
||||||
|
}
|
||||||
|
i.results <- r
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *target) scrape(timestamp time.Time, results chan<- *extraction.Result) (err error) {
|
func (t *target) scrape(timestamp time.Time, results chan<- *extraction.Result) (err error) {
|
||||||
defer func(start time.Time) {
|
defer func(start time.Time) {
|
||||||
ms := float64(time.Since(start)) / float64(time.Millisecond)
|
ms := float64(time.Since(start)) / float64(time.Millisecond)
|
||||||
|
@ -238,20 +251,22 @@ func (t *target) scrape(timestamp time.Time, results chan<- *extraction.Result)
|
||||||
baseLabels[baseLabel] = baseValue
|
baseLabels[baseLabel] = baseValue
|
||||||
}
|
}
|
||||||
|
|
||||||
processOptions := &extraction.ProcessOptions{
|
|
||||||
Timestamp: timestamp,
|
|
||||||
BaseLabels: baseLabels,
|
|
||||||
}
|
|
||||||
|
|
||||||
// N.B. - It is explicitly required to extract the entire payload before
|
// N.B. - It is explicitly required to extract the entire payload before
|
||||||
// attempting to deserialize, as the underlying reader expects will
|
// attempting to deserialize, as the underlying reader will interpret
|
||||||
// interpret pending data as a truncated message.
|
// pending data as a truncated message.
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if _, err := buf.ReadFrom(resp.Body); err != nil {
|
if _, err := buf.ReadFrom(resp.Body); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return processor.ProcessSingle(buf, results, processOptions)
|
ingester := &extendLabelsIngester{
|
||||||
|
baseLabels: baseLabels,
|
||||||
|
results: results,
|
||||||
|
}
|
||||||
|
processOptions := &extraction.ProcessOptions{
|
||||||
|
Timestamp: timestamp,
|
||||||
|
}
|
||||||
|
return processor.ProcessSingle(buf, ingester, processOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *target) State() TargetState {
|
func (t *target) State() TargetState {
|
||||||
|
|
Loading…
Reference in a new issue