-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vlinsert: added opentelemetry logs support
- Loading branch information
1 parent
c0050be
commit fa7ca96
Showing
14 changed files
with
807 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package opentelemetry | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/insertutils" | ||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlstorage" | ||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver" | ||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logstorage" | ||
opentelemetry "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/opentelemetry/stream" | ||
"github.com/VictoriaMetrics/metrics" | ||
) | ||
|
||
// RequestHandler processes Opentelemetry insert requests | ||
func RequestHandler(path string, w http.ResponseWriter, r *http.Request) bool { | ||
switch path { | ||
case "/api/v1/push": | ||
return handleInsert(r, w) | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func handleInsert(r *http.Request, w http.ResponseWriter) bool { | ||
startTime := time.Now() | ||
var m *otelMetrics | ||
contentType := r.Header.Get("Content-Type") | ||
if contentType == "application/json" { | ||
m = jsonMetrics | ||
} else { | ||
m = protobufMetrics | ||
} | ||
isGzipped := r.Header.Get("Content-Encoding") == "gzip" | ||
m.requestsTotal.Inc() | ||
cp, err := insertutils.GetCommonParams(r) | ||
if err != nil { | ||
httpserver.Errorf(w, r, "cannot parse common params from request: %s", err) | ||
return true | ||
} | ||
n, err := opentelemetry.ParseLogsStream(r.Body, contentType, isGzipped, func(streamFields []string) (func(int64, []logstorage.Field), func()) { | ||
lr := logstorage.GetLogRows(streamFields, nil) | ||
processLogFn := cp.GetProcessLogMessageFunc(lr) | ||
pushFn := func() { | ||
vlstorage.MustAddRows(lr) | ||
logstorage.PutLogRows(lr) | ||
} | ||
return processLogFn, pushFn | ||
}) | ||
if err != nil { | ||
httpserver.Errorf(w, r, "cannot parse Opentelemetry request: %s", err) | ||
return true | ||
} | ||
|
||
m.ingestedTotal.Add(n) | ||
|
||
m.requestsDuration.UpdateDuration(startTime) | ||
|
||
return true | ||
} | ||
|
||
type otelMetrics struct { | ||
requestsTotal *metrics.Counter | ||
ingestedTotal *metrics.Counter | ||
requestsDuration *metrics.Histogram | ||
} | ||
|
||
func newMetrics(format string) *otelMetrics { | ||
return &otelMetrics{ | ||
requestsTotal: metrics.NewCounter(fmt.Sprintf(`vl_http_requests_total{path="/insert/opentelemetry/api/v1/push",format="%s"}`, format)), | ||
ingestedTotal: metrics.NewCounter(fmt.Sprintf(`vl_rows_ingested_total{type="opentelemetry",format="%s"}`, format)), | ||
requestsDuration: metrics.NewHistogram(fmt.Sprintf(`vl_http_request_duration_seconds{path="/insert/opentelemetry/api/v1/push",format="%s"}`, format)), | ||
} | ||
} | ||
|
||
var ( | ||
jsonMetrics = newMetrics("json") | ||
protobufMetrics = newMetrics("protobuf") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
weight: 4 | ||
title: OpenTelemetry setup | ||
disableToc: true | ||
menu: | ||
docs: | ||
parent: "victorialogs-data-ingestion" | ||
weight: 4 | ||
aliases: | ||
- /VictoriaLogs/data-ingestion/OpenTelemetry.html | ||
--- | ||
# OpenTelemetry setup | ||
|
||
Specify logs endpoint for [OTLP/HTTP exporter](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/otlphttpexporter/README.md) in configuration file | ||
for sending the collected logs to [VictoriaLogs](https://docs.victoriametrics.com/VictoriaLogs/): | ||
|
||
```yaml | ||
exporters: | ||
otlphttp: | ||
logs_endpoint: http://localhost:9428/insert/opentelemetry/api/v1/push | ||
``` | ||
|
||
Substitute `localhost:9428` address inside `exporters.oltphttp.logs_endpoint` with the real TCP address of VictoriaLogs. | ||
|
||
VictoriaLogs divides all the ingested logs into a log streams [log stream](https://docs.victoriametrics.com/VictoriaLogs/keyConcepts.html#stream-fields) relying on resource attributes. In example below resource attributes are set for [filelog OpenTelemetry receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver): | ||
|
||
```yaml | ||
receivers: | ||
filelog: | ||
include: [/var/log/myservice/*.json] | ||
resource: | ||
region: us-east-1 | ||
``` | ||
|
||
The ingested log entries can be queried according to [these docs](https://docs.victoriametrics.com/VictoriaLogs/querying/). | ||
|
||
See also [data ingestion troubleshooting](https://docs.victoriametrics.com/VictoriaLogs/data-ingestion/#troubleshooting) docs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.