mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
d6b4c8e4ef
Co-authored-by: Andrew Chubatiuk <andrew.chubatiuk@motional.com>
Co-authored-by: Nikolay <https://github.com/f41gh7>
Co-authored-by: Roman Khavronenko <roman@victoriametrics.com>
(cherry picked from commit 543f218fe9
)
Signed-off-by: hagen1778 <roman@victoriametrics.com>
56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package datadog
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmagent/common"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmagent/remotewrite"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/auth"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/datadog/stream"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/tenantmetrics"
|
|
"github.com/VictoriaMetrics/metrics"
|
|
)
|
|
|
|
var (
|
|
rowsInserted = metrics.NewCounter(`vmagent_rows_inserted_total{type="datadog"}`)
|
|
rowsTenantInserted = tenantmetrics.NewCounterMap(`vmagent_tenant_inserted_rows_total{type="datadog"}`)
|
|
rowsPerInsert = metrics.NewHistogram(`vmagent_rows_per_insert{type="datadog"}`)
|
|
)
|
|
|
|
// InsertHandlerForHTTP processes remote write for DataDog POST /api/v1/series, /api/v2/series, /api/beta/sketches request.
|
|
//
|
|
// See https://docs.datadoghq.com/api/latest/metrics/#submit-metrics
|
|
func InsertHandlerForHTTP(at *auth.Token, req *http.Request) error {
|
|
extraLabels, err := parserCommon.GetExtraLabels(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return stream.Parse(
|
|
req, func(series prompbmarshal.TimeSeries) error {
|
|
series.Labels = append(series.Labels, extraLabels...)
|
|
return insertRows(at, series)
|
|
},
|
|
)
|
|
}
|
|
|
|
func insertRows(at *auth.Token, series prompbmarshal.TimeSeries) error {
|
|
ctx := common.GetPushCtx()
|
|
defer common.PutPushCtx(ctx)
|
|
|
|
rowsTotal := len(series.Samples)
|
|
|
|
ctx.WriteRequest.Timeseries = []prompbmarshal.TimeSeries{series}
|
|
ctx.Labels = series.Labels
|
|
ctx.Samples = series.Samples
|
|
if !remotewrite.TryPush(at, &ctx.WriteRequest) {
|
|
return remotewrite.ErrQueueFullHTTPRetry
|
|
}
|
|
rowsInserted.Add(rowsTotal)
|
|
if at != nil {
|
|
rowsTenantInserted.Get(at).Add(rowsTotal)
|
|
}
|
|
rowsPerInsert.Update(float64(rowsTotal))
|
|
return nil
|
|
}
|