2021-09-28 21:47:45 +02:00
|
|
|
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"
|
2023-02-13 18:51:35 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/datadog/stream"
|
2021-09-28 21:47:45 +02:00
|
|
|
"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"}`)
|
|
|
|
)
|
|
|
|
|
2023-11-28 14:52:29 +01:00
|
|
|
// InsertHandlerForHTTP processes remote write for DataDog POST /api/v1/series, /api/v2/series, /api/beta/sketches request.
|
2021-09-28 21:47:45 +02:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
}
|
2023-11-28 14:52:29 +01:00
|
|
|
return stream.Parse(
|
|
|
|
req, func(series prompbmarshal.TimeSeries) error {
|
|
|
|
series.Labels = append(series.Labels, extraLabels...)
|
|
|
|
return insertRows(at, series)
|
|
|
|
},
|
|
|
|
)
|
2021-09-28 21:47:45 +02:00
|
|
|
}
|
|
|
|
|
2023-11-28 14:52:29 +01:00
|
|
|
func insertRows(at *auth.Token, series prompbmarshal.TimeSeries) error {
|
2021-09-28 21:47:45 +02:00
|
|
|
ctx := common.GetPushCtx()
|
|
|
|
defer common.PutPushCtx(ctx)
|
|
|
|
|
2023-11-28 14:52:29 +01:00
|
|
|
rowsTotal := len(series.Samples)
|
|
|
|
|
|
|
|
ctx.WriteRequest.Timeseries = []prompbmarshal.TimeSeries{series}
|
|
|
|
ctx.Labels = series.Labels
|
|
|
|
ctx.Samples = series.Samples
|
2023-11-25 10:31:30 +01:00
|
|
|
if !remotewrite.TryPush(at, &ctx.WriteRequest) {
|
2023-11-24 13:42:11 +01:00
|
|
|
return remotewrite.ErrQueueFullHTTPRetry
|
|
|
|
}
|
2021-09-28 21:47:45 +02:00
|
|
|
rowsInserted.Add(rowsTotal)
|
|
|
|
if at != nil {
|
|
|
|
rowsTenantInserted.Get(at).Add(rowsTotal)
|
|
|
|
}
|
|
|
|
rowsPerInsert.Update(float64(rowsTotal))
|
|
|
|
return nil
|
|
|
|
}
|