From ce2053d26ddb251b4060a9629bf9de956174dee1 Mon Sep 17 00:00:00 2001 From: Povilas Versockas Date: Mon, 8 Aug 2022 16:39:33 +0300 Subject: [PATCH] feat: add coralogix dialect to opentelemetry (#11622) --- plugins/outputs/opentelemetry/README.md | 28 +++++++++++++++++++ .../outputs/opentelemetry/opentelemetry.go | 26 ++++++++++++++++- plugins/outputs/opentelemetry/sample.conf | 11 ++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/plugins/outputs/opentelemetry/README.md b/plugins/outputs/opentelemetry/README.md index 3993ca245..94144ffc5 100644 --- a/plugins/outputs/opentelemetry/README.md +++ b/plugins/outputs/opentelemetry/README.md @@ -32,6 +32,17 @@ and agents via gRPC. ## Supports: "gzip", "none" # compression = "gzip" + ## Configuration options for the Coralogix dialect + ## Enable the following section of you use this plugin with a Coralogix endpoint + # [outputs.opentelemetry.coralogix] + # ## Your Coralogix private key (required). + # ## Please note that this is sensitive data! + # private_key = "your_coralogix_key" + # + # ## Application and subsystem names for the metrics (required) + # application = "$NAMESPACE" + # subsystem = "$HOSTNAME" + ## Additional OpenTelemetry resource attributes # [outputs.opentelemetry.attributes] # "service.name" = "demo" @@ -41,6 +52,23 @@ and agents via gRPC. # key1 = "value1" ``` +## Supported dialects + +### Coralogix + +This plugins supports sending data to a [Coralogix](https://coralogix.com) +server by enabling the corresponding dialect by uncommenting +the `[output.opentelemetry.coralogix]` section. + +There, you can find the required setting to interact with the server. + +- The `private_key` is your Private Key, which you can find in Settings > Send Your Data. +- The `application`, is your application name, which will be added to your metric attributes. +- The `subsystem`, is your subsystem, which will be added to your metric attributes. + +More information in the +[Getting Started page](https://coralogix.com/docs/guide-first-steps-coralogix/). + ### Schema The InfluxDB->OpenTelemetry conversion [schema][] and [implementation][] are diff --git a/plugins/outputs/opentelemetry/opentelemetry.go b/plugins/outputs/opentelemetry/opentelemetry.go index f509f85ce..daf123f34 100644 --- a/plugins/outputs/opentelemetry/opentelemetry.go +++ b/plugins/outputs/opentelemetry/opentelemetry.go @@ -4,8 +4,12 @@ package opentelemetry import ( "context" _ "embed" + "fmt" + "runtime" "time" + ntls "crypto/tls" + "github.com/influxdata/influxdb-observability/common" "github.com/influxdata/influxdb-observability/influx2otel" "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" @@ -23,6 +27,8 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +var userAgent = fmt.Sprintf("telegraf (%s/%s)", runtime.GOOS, runtime.GOARCH) + // DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data. //go:embed sample.conf var sampleConfig string @@ -35,6 +41,7 @@ type OpenTelemetry struct { Compression string `toml:"compression"` Headers map[string]string `toml:"headers"` Attributes map[string]string `toml:"attributes"` + Coralogix *CoralogixConfig `toml:"coralogix"` Log telegraf.Logger `toml:"-"` @@ -44,6 +51,12 @@ type OpenTelemetry struct { callOptions []grpc.CallOption } +type CoralogixConfig struct { + AppName string `toml:"application"` + SubSystem string `toml:"subsystem"` + PrivateKey string `toml:"private_key"` +} + func (*OpenTelemetry) SampleConfig() string { return sampleConfig } @@ -60,6 +73,14 @@ func (o *OpenTelemetry) Connect() error { if o.Compression == "" { o.Compression = defaultCompression } + if o.Coralogix != nil { + if o.Headers == nil { + o.Headers = make(map[string]string) + } + o.Headers["ApplicationName"] = o.Coralogix.AppName + o.Headers["ApiName"] = o.Coralogix.SubSystem + o.Headers["Authorization"] = "Bearer " + o.Coralogix.PrivateKey + } metricsConverter, err := influx2otel.NewLineProtocolToOtelMetrics(logger) if err != nil { @@ -71,11 +92,14 @@ func (o *OpenTelemetry) Connect() error { return err } else if tlsConfig != nil { grpcTLSDialOption = grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)) + } else if o.Coralogix != nil { + // For coralogix, we enforce GRPC connection with TLS + grpcTLSDialOption = grpc.WithTransportCredentials(credentials.NewTLS(&ntls.Config{})) } else { grpcTLSDialOption = grpc.WithTransportCredentials(insecure.NewCredentials()) } - grpcClientConn, err := grpc.Dial(o.ServiceAddress, grpcTLSDialOption) + grpcClientConn, err := grpc.Dial(o.ServiceAddress, grpcTLSDialOption, grpc.WithUserAgent(userAgent)) if err != nil { return err } diff --git a/plugins/outputs/opentelemetry/sample.conf b/plugins/outputs/opentelemetry/sample.conf index 38070f494..9ab1eafe5 100644 --- a/plugins/outputs/opentelemetry/sample.conf +++ b/plugins/outputs/opentelemetry/sample.conf @@ -24,6 +24,17 @@ ## Supports: "gzip", "none" # compression = "gzip" + ## Configuration options for the Coralogix dialect + ## Enable the following section of you use this plugin with a Coralogix endpoint + # [outputs.opentelemetry.coralogix] + # ## Your Coralogix private key (required). + # ## Please note that this is sensitive data! + # private_key = "your_coralogix_key" + # + # ## Application and subsystem names for the metrics (required) + # application = "$NAMESPACE" + # subsystem = "$HOSTNAME" + ## Additional OpenTelemetry resource attributes # [outputs.opentelemetry.attributes] # "service.name" = "demo"