mirror of
https://github.com/grafana/loki.git
synced 2025-08-02 20:08:13 +08:00

* Add wait until processed Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Add query lines Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Remove Cortex reference Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Add deleted lines metric and check in test Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Set negative cancel period so default 1 minute delay is compensated for Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Reduce timeout Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Add helper function Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Comment out assertions that only work with flush Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Remove unused metric type param Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Check counter in unit test Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Rename ClientOption to Option as per the linter Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * Remove redundant check Signed-off-by: Michel Hollands <michel.hollands@grafana.com> * fill in MsgAndArgs field of test assertion Signed-off-by: Michel Hollands <michel.hollands@grafana.com>
45 lines
971 B
Go
45 lines
971 B
Go
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
io_prometheus_client "github.com/prometheus/client_model/go"
|
|
"github.com/prometheus/common/expfmt"
|
|
)
|
|
|
|
var (
|
|
ErrNoMetricFound = fmt.Errorf("metric not found")
|
|
ErrInvalidMetricType = fmt.Errorf("invalid metric type")
|
|
)
|
|
|
|
func extractMetric(metricName, metrics string) (float64, map[string]string, error) {
|
|
var parser expfmt.TextParser
|
|
mfs, err := parser.TextToMetricFamilies(strings.NewReader(metrics))
|
|
if err != nil {
|
|
return 0, nil, err
|
|
}
|
|
|
|
mf, found := mfs[metricName]
|
|
if !found {
|
|
return 0, nil, ErrNoMetricFound
|
|
}
|
|
|
|
var val float64
|
|
switch mf.GetType() {
|
|
case io_prometheus_client.MetricType_COUNTER:
|
|
val = *mf.Metric[0].Counter.Value
|
|
case io_prometheus_client.MetricType_GAUGE:
|
|
val = *mf.Metric[0].Gauge.Value
|
|
default:
|
|
return 0, nil, ErrInvalidMetricType
|
|
}
|
|
|
|
labels := make(map[string]string)
|
|
for _, l := range mf.Metric[0].Label {
|
|
labels[*l.Name] = *l.Value
|
|
}
|
|
|
|
return val, labels, nil
|
|
}
|