forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stat_sinks: add OpenTelemetry stats sink (envoyproxy#26620)
Signed-off-by: ohadvano <[email protected]>
- Loading branch information
Showing
27 changed files
with
1,336 additions
and
2 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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,12 @@ | ||
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
||
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_package( | ||
deps = [ | ||
"//envoy/config/core/v3:pkg", | ||
"@com_github_cncf_udpa//udpa/annotations:pkg", | ||
], | ||
) |
47 changes: 47 additions & 0 deletions
47
api/envoy/extensions/stat_sinks/open_telemetry/v3/open_telemetry.proto
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,47 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.stat_sinks.open_telemetry.v3; | ||
|
||
import "envoy/config/core/v3/grpc_service.proto"; | ||
|
||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.stat_sinks.open_telemetry.v3"; | ||
option java_outer_classname = "OpenTelemetryProto"; | ||
option java_multiple_files = true; | ||
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/stat_sinks/open_telemetry/v3;open_telemetryv3"; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Open Telemetry Stats Sink] | ||
// Stats configuration proto schema for ``envoy.stat_sinks.open_telemetry`` sink. | ||
// [#extension: envoy.stat_sinks.open_telemetry] | ||
|
||
// [#next-free-field: 6] | ||
message SinkConfig { | ||
oneof protocol_specifier { | ||
option (validate.required) = true; | ||
|
||
// The upstream gRPC cluster that implements the OTLP/gRPC collector. | ||
config.core.v3.GrpcService grpc_service = 1 [(validate.rules).message = {required: true}]; | ||
} | ||
|
||
// If set to true, counters will be emitted as deltas, and the OTLP message will have | ||
// ``AGGREGATION_TEMPORALITY_DELTA`` set as AggregationTemporality. | ||
bool report_counters_as_deltas = 2; | ||
|
||
// If set to true, histograms will be emitted as deltas, and the OTLP message will have | ||
// ``AGGREGATION_TEMPORALITY_DELTA`` set as AggregationTemporality. | ||
bool report_histograms_as_deltas = 3; | ||
|
||
// If set to true, metrics will have their tags emitted as OTLP attributes, which may | ||
// contain values used by the tag extractor or additional tags added during stats creation. | ||
// Otherwise, no attributes will be associated with the export message. Default value is true. | ||
google.protobuf.BoolValue emit_tags_as_attributes = 4; | ||
|
||
// If set to true, metric names will be represented as the tag extracted name instead | ||
// of the full metric name. Default value is true. | ||
google.protobuf.BoolValue use_tag_extracted_name = 5; | ||
} |
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
12 changes: 12 additions & 0 deletions
12
docs/root/configuration/observability/stat_sinks/open_telemetry_stat_sink.rst
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,12 @@ | ||
.. _config_stat_sinks_open_telemetry: | ||
|
||
OpenTelemetry Stat Sink | ||
========================= | ||
|
||
The :ref:`OpenTelemetryStatsSink <envoy_v3_api_msg_extensions.stat_sinks.open_telemetry.v3.SinkConfig>` configuration specifies a | ||
stat sink that emits stats according to `OpenTelemetry Protocol Specification <https://opentelemetry.io/docs/reference/specification/protocol/otlp/>`_. | ||
The export requests of this sink are sent to the collector service according to the Protobuf defined in | ||
`MetricService/Export <https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/collector/metrics/v1/metrics_service.proto>`_. | ||
The metric resources exported are defined in `metrics.proto <https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/metrics/v1/metrics.proto>`_. | ||
Any export request that this sink sends, will contain a single ``ResourceMetrics`` message, a single ``ScopeMetrics`` and repeated ``MetricRecord``, | ||
according to the number of metrics collected during the proccess run. |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ Stat sinks | |
:maxdepth: 2 | ||
|
||
graphite_statsd_stat_sink | ||
open_telemetry_stat_sink | ||
wasm_stat_sink |
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,45 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_extension", | ||
"envoy_cc_library", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_library( | ||
name = "open_telemetry_lib", | ||
srcs = ["open_telemetry_impl.cc"], | ||
hdrs = ["open_telemetry_impl.h"], | ||
deps = [ | ||
"//envoy/grpc:async_client_interface", | ||
"//envoy/singleton:instance_interface", | ||
"//source/common/grpc:async_client_lib", | ||
"@envoy_api//envoy/extensions/stat_sinks/open_telemetry/v3:pkg_cc_proto", | ||
"@opentelemetry_proto//:metrics_cc_proto", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "open_telemetry_proto_descriptors_lib", | ||
srcs = ["open_telemetry_proto_descriptors.cc"], | ||
hdrs = ["open_telemetry_proto_descriptors.h"], | ||
deps = [ | ||
"//source/common/common:assert_lib", | ||
"//source/common/protobuf", | ||
], | ||
) | ||
|
||
envoy_cc_extension( | ||
name = "config", | ||
srcs = ["config.cc"], | ||
hdrs = ["config.h"], | ||
deps = [ | ||
":open_telemetry_lib", | ||
":open_telemetry_proto_descriptors_lib", | ||
"//envoy/registry", | ||
"//source/server:configuration_lib", | ||
], | ||
) |
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,60 @@ | ||
#include "source/extensions/stat_sinks/open_telemetry/config.h" | ||
|
||
#include "envoy/registry/registry.h" | ||
|
||
#include "source/extensions/stat_sinks/open_telemetry/open_telemetry_impl.h" | ||
#include "source/extensions/stat_sinks/open_telemetry/open_telemetry_proto_descriptors.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace StatSinks { | ||
namespace OpenTelemetry { | ||
|
||
Stats::SinkPtr | ||
OpenTelemetrySinkFactory::createStatsSink(const Protobuf::Message& config, | ||
Server::Configuration::ServerFactoryContext& server) { | ||
validateProtoDescriptors(); | ||
|
||
const auto& sink_config = MessageUtil::downcastAndValidate<const SinkConfig&>( | ||
config, server.messageValidationContext().staticValidationVisitor()); | ||
|
||
auto otlp_options = std::make_shared<OtlpOptions>(sink_config); | ||
std::shared_ptr<OtlpMetricsFlusher> otlp_metrics_flusher = | ||
std::make_shared<OtlpMetricsFlusherImpl>(otlp_options); | ||
|
||
switch (sink_config.protocol_specifier_case()) { | ||
case SinkConfig::ProtocolSpecifierCase::kGrpcService: { | ||
const auto& grpc_service = sink_config.grpc_service(); | ||
|
||
std::shared_ptr<OpenTelemetryGrpcMetricsExporter> grpc_metrics_exporter = | ||
std::make_shared<OpenTelemetryGrpcMetricsExporterImpl>( | ||
otlp_options, | ||
server.clusterManager().grpcAsyncClientManager().getOrCreateRawAsyncClient( | ||
grpc_service, server.scope(), false)); | ||
|
||
return std::make_unique<OpenTelemetryGrpcSink>(otlp_metrics_flusher, grpc_metrics_exporter); | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
|
||
throw EnvoyException("unexpected Open Telemetry protocol case num"); | ||
} | ||
|
||
ProtobufTypes::MessagePtr OpenTelemetrySinkFactory::createEmptyConfigProto() { | ||
return std::make_unique<SinkConfig>(); | ||
} | ||
|
||
std::string OpenTelemetrySinkFactory::name() const { return OpenTelemetryName; } | ||
|
||
/** | ||
* Static registration for the this sink factory. @see RegisterFactory. | ||
*/ | ||
LEGACY_REGISTER_FACTORY(OpenTelemetrySinkFactory, Server::Configuration::StatsSinkFactory, | ||
"envoy.open_telemetry_stat_sink"); | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace StatSinks | ||
} // namespace Extensions | ||
} // namespace Envoy |
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,34 @@ | ||
#pragma once | ||
|
||
#include "envoy/registry/registry.h" | ||
#include "envoy/server/instance.h" | ||
|
||
#include "source/server/configuration_impl.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace StatSinks { | ||
namespace OpenTelemetry { | ||
|
||
constexpr char OpenTelemetryName[] = "envoy.stat_sinks.open_telemetry"; | ||
|
||
/** | ||
* Config registration for the OpenTelemetry stats sink. @see StatsSinkFactory. | ||
*/ | ||
class OpenTelemetrySinkFactory : Logger::Loggable<Logger::Id::config>, | ||
public Server::Configuration::StatsSinkFactory { | ||
public: | ||
Stats::SinkPtr createStatsSink(const Protobuf::Message& config, | ||
Server::Configuration::ServerFactoryContext& server) override; | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override; | ||
|
||
std::string name() const override; | ||
}; | ||
|
||
DECLARE_FACTORY(OpenTelemetrySinkFactory); | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace StatSinks | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.