From 0e868f4ae7b7e616a4fc7baedf4a7f16fa119473 Mon Sep 17 00:00:00 2001 From: Daniel Chao Date: Thu, 27 Jun 2024 10:39:03 -0700 Subject: [PATCH] [com.influxdata.telegraf] Add OpenTelemetry Output plugin (#66) --- packages/com.influxdata.telegraf/PklProject | 2 +- packages/com.influxdata.telegraf/Telegraf.pkl | 7 ++ .../examples/opentelemetry-output.pkl | 42 ++++++++++ .../plugins/outputs/OpenTelemetryOutput.pkl | 80 +++++++++++++++++++ .../tests/Telegraf.pkl-expected.pcf | 24 ++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 packages/com.influxdata.telegraf/examples/opentelemetry-output.pkl create mode 100644 packages/com.influxdata.telegraf/plugins/outputs/OpenTelemetryOutput.pkl diff --git a/packages/com.influxdata.telegraf/PklProject b/packages/com.influxdata.telegraf/PklProject index 06d16b4..9cb61bd 100644 --- a/packages/com.influxdata.telegraf/PklProject +++ b/packages/com.influxdata.telegraf/PklProject @@ -22,5 +22,5 @@ dependencies { } package { - version = "1.1.1" + version = "1.2.0" } diff --git a/packages/com.influxdata.telegraf/Telegraf.pkl b/packages/com.influxdata.telegraf/Telegraf.pkl index c581233..0163b1c 100644 --- a/packages/com.influxdata.telegraf/Telegraf.pkl +++ b/packages/com.influxdata.telegraf/Telegraf.pkl @@ -52,6 +52,7 @@ import "plugins/inputs/SolrInput.pkl" import "plugins/outputs/FileOutput.pkl" import "plugins/outputs/DiscardOutput.pkl" import "plugins/outputs/PrometheusClientOutput.pkl" +import "plugins/outputs/OpenTelemetryOutput.pkl" import "plugins/processors/StarlarkProcessor.pkl" import "plugins/Plugin.pkl" @@ -87,7 +88,13 @@ open class Outputs { /// It is only meant to be used for testing purposes. discard: Listing? + /// This plugin starts a [Prometheus](https://prometheus.io) Client. + /// + /// Tt exposes all metrics on `/metrics` (default) to be polled by a Prometheus server. prometheus_client: Listing? + + /// This plugin sends metrics to [OpenTelemetry](https://opentelemetry.io) servers and agents via gRPC. + opentelemetry: Listing? } open class Inputs { diff --git a/packages/com.influxdata.telegraf/examples/opentelemetry-output.pkl b/packages/com.influxdata.telegraf/examples/opentelemetry-output.pkl new file mode 100644 index 0000000..2a4f2ee --- /dev/null +++ b/packages/com.influxdata.telegraf/examples/opentelemetry-output.pkl @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//===----------------------------------------------------------------------===// +amends "../Telegraf.pkl" + +outputs { + opentelemetry { + new { + service_address = "localhost:4312" + timeout = 10.s + tls_ca = "/path/to/ca/cert" + tls_cert = "/path/to/cert" + tls_key = "/path/to/key" + tls_server_name = "tls-server.com" + compression = "gzip" + coralogix { + application = "myapp" + private_key = "my secret value" + subsystem = "my subsystem" + } + attributes { + ["service.name"] = "foo" + ["service.version"] = "1.0.0" + } + headers { + ["x-api-key"] = "my-api-key" + } + } + } +} diff --git a/packages/com.influxdata.telegraf/plugins/outputs/OpenTelemetryOutput.pkl b/packages/com.influxdata.telegraf/plugins/outputs/OpenTelemetryOutput.pkl new file mode 100644 index 0000000..c271bbb --- /dev/null +++ b/packages/com.influxdata.telegraf/plugins/outputs/OpenTelemetryOutput.pkl @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//===----------------------------------------------------------------------===// +/// Sends metrics to [OpenTelemetry](https://opentelemetry.io) servers and agents via gRPC. +/// +/// +@ModuleInfo { minPklVersion = "0.24.0" } +open module com.influxdata.telegraf.plugins.outputs.OpenTelemetryOutput + +extends "Output.pkl" + +/// The endpoint to which the metrics will be sent. +/// +/// Default: `"localhost:4317"` +service_address: String? + +/// The timeout for the connection. +/// +/// Default: `5.s` +timeout: Duration? + +/// Optional TLS Config. +/// All variables should specify full path to the file. +/// Root certificates for verifying server certificates encoded in PEM format. +tls_ca: String? + +/// Path to the TLS certificate for the client encoded in PEM format. +/// May contain intermediate certificates. +tls_cert: String? + +/// Path to the TLS private key for the client encoded in PEM format. +tls_key: String? + +/// Send the specified TLS server name via SNI. +tls_server_name: String? + +/// Insecure option to skip TLS server cert verification. +/// +/// Warning: it is insecure to enable this option. +/// If enabled, crypto/tls accepts any certificate presented by the server and any host name in that certificate. +/// +/// Default: `false` +insecure_skip_verify: Boolean? + +/// Send data to a [Coralogix](https://coralogix.com) server. +coralogix: Coralogix? + +/// Set the compression method used to send data. +/// +/// Default: `"none"` +compression: ("none"|"gzip")? + +/// Additional OpenTelemetry resource attributes +attributes: Mapping? + +/// Additional gRPC request metadata headers +headers: Mapping? + +class Coralogix { + /// The private key, which can be found in Settings > Send Your Data. + private_key: String + + /// The application name, which will be added to metric attributes. + application: String + + /// The subsystem name, which will be added to metric attributes. + subsystem: String +} diff --git a/packages/com.influxdata.telegraf/tests/Telegraf.pkl-expected.pcf b/packages/com.influxdata.telegraf/tests/Telegraf.pkl-expected.pcf index b15172d..a5da3d5 100644 --- a/packages/com.influxdata.telegraf/tests/Telegraf.pkl-expected.pcf +++ b/packages/com.influxdata.telegraf/tests/Telegraf.pkl-expected.pcf @@ -1,4 +1,28 @@ examples { + ["opentelemetry-output.toml"] { + """ + [[outputs.opentelemetry]] + service_address = "localhost:4312" + timeout = "10s" + tls_ca = "/path/to/ca/cert" + tls_cert = "/path/to/cert" + tls_key = "/path/to/key" + tls_server_name = "tls-server.com" + compression = "gzip" + + [outputs.opentelemetry.coralogix] + private_key = "my secret value" + application = "myapp" + subsystem = "my subsystem" + + [outputs.opentelemetry.attributes] + "service.name" = "foo" + "service.version" = "1.0.0" + + [outputs.opentelemetry.headers] + x-api-key = "my-api-key" + """ + } ["simple.toml"] { """ [[outputs.file]]