Клиент Go prometheus получает другую задержку с клиентом prometheus Python

Я читаю коды измерения задержки, потому что я обнаружил, что измеренная задержка выше, чем сквозная задержка, измеренная кодами Python. Верно ли следующее использование InstrumentRoundTripperDuration? Я не нашел подобных примеров в Интернете.

import (
    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)


// metrics client
func NewClientMetrics(spec *v1.PredictorSpec, deploymentName string, modelName string) *ClientMetrics {
    histogram := prometheus.NewHistogramVec(
        prometheus.HistogramOpts{
            Name:    ClientRequestsMetricName,
            Help:    "A histogram of latencies for client calls from executor",
            Buckets: prometheus.DefBuckets,
        },
        []string{DeploymentNameMetric, PredictorNameMetric, PredictorVersionMetric, ServiceMetric, ModelNameMetric, ModelImageMetric, ModelVersionMetric, "method", "code"},
    )

    err := prometheus.Register(histogram)
    if err != nil {
        prometheus.Unregister(histogram)
        prometheus.Register(histogram)
    }
    ...

    return &ClientMetrics{
        ClientHandledHistogram: histogram,
        Predictor:              spec,
        DeploymentName:         deploymentName,
        ModelName:              modelName,
        ImageName:              imageName,
        ImageVersion:           imageVersion,
    }
}

// In json rest client, construct metrics client
func NewJSONRestClient(protocol string, deploymentName string, predictor *v1.PredictorSpec, annotations map[string]string, options ...BytesRestClientOption) (client.SeldonApiClient, error) {

    httpClient := http.DefaultClient
...

    client := JSONRestClient{
        httpClient,
        logf.Log.WithName("JSONRestClient"),
        protocol,
        deploymentName,
        predictor,
        metric.NewClientMetrics(predictor, deploymentName, ""),
    }
    ...

    return &client, nil
}

// In Json rest client, create a function to measure roundtrip latency
func (smc *JSONRestClient) getMetricsRoundTripper(modelName string, service string) http.RoundTripper {
...
    return promhttp.InstrumentRoundTripperDuration(smc.metrics.ClientHandledHistogram.MustCurryWith(prometheus.Labels{
        metric.DeploymentNameMetric:   smc.DeploymentName,
        metric.PredictorNameMetric:    smc.predictor.Name,
        metric.PredictorVersionMetric: smc.predictor.Annotations["version"],
        metric.ServiceMetric:          service,
        metric.ModelNameMetric:        modelName,
        metric.ModelImageMetric:       imageName,
        metric.ModelVersionMetric:     imageVersion,
    }), http.DefaultTransport)
}

// http call (getMetricsRoundTripper is called middleware)
client := smc.httpClient
client.Transport = smc.getMetricsRoundTripper(modelName, method)

исходные коды:

https://github.com/SeldonIO/seldon-core/blob/master/executor/api/rest/client.go#L88 и строки 148, 118

https://github.com/SeldonIO/seldon-core/blob/master/executor/api/metric/client.go#L22

Спасибо


person BAE    schedule 06.06.2020    source источник


Ответы (1)


У клиента Python prometheus разные корзины с клиентом go prometheus. Первый использует Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10}.

Но последний использует []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10} (код).

Они используют разные корзины, поэтому метрики могут выглядеть по-разному.

person BAE    schedule 07.06.2020