From 421cc47b840c5e6f745dda6c5732ab1203acf721 Mon Sep 17 00:00:00 2001 From: Purvi Kanal Date: Wed, 28 Sep 2022 14:47:49 -0400 Subject: [PATCH 1/5] add metrics smoke tests --- smoke-tests/collector/otel-collector-config.yaml | 3 +-- smoke-tests/docker-compose.yml | 3 ++- smoke-tests/smoke-sdk-grpc.bats | 7 +++++++ smoke-tests/smoke-sdk-http.bats | 7 +++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/smoke-tests/collector/otel-collector-config.yaml b/smoke-tests/collector/otel-collector-config.yaml index f9dc0fa..7d99fd3 100644 --- a/smoke-tests/collector/otel-collector-config.yaml +++ b/smoke-tests/collector/otel-collector-config.yaml @@ -22,8 +22,7 @@ service: metrics: receivers: [otlp] processors: [batch] - # exporters: [file, logging] - exporters: [logging] + exporters: [file, logging] logs: receivers: [otlp] processors: [batch] diff --git a/smoke-tests/docker-compose.yml b/smoke-tests/docker-compose.yml index cec96a1..3b98caf 100644 --- a/smoke-tests/docker-compose.yml +++ b/smoke-tests/docker-compose.yml @@ -5,7 +5,7 @@ x-env-base: &env_base HONEYCOMB_API_KEY: bogus_key HONEYCOMB_DATASET: bogus_dataset HONEYCOMB_METRICS_DATASET: bogus_dataset - OTEL_METRIC_EXPORT_INTERVAL: 1000 + OTEL_METRIC_EXPORT_INTERVAL: 100 OTEL_SERVICE_NAME: "aspnetcore-example" DEBUG: "true" @@ -37,6 +37,7 @@ services: environment: <<: *env_base HONEYCOMB_API_ENDPOINT: http://collector:4318 + HONEYCOMB_METRICS_ENDPOINT: http://collector:4318/v1/metrics OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf ports: - "127.0.0.1:5001:5001" diff --git a/smoke-tests/smoke-sdk-grpc.bats b/smoke-tests/smoke-sdk-grpc.bats index 248507d..2a6e028 100644 --- a/smoke-tests/smoke-sdk-grpc.bats +++ b/smoke-tests/smoke-sdk-grpc.bats @@ -4,6 +4,7 @@ load test_helpers/utilities CONTAINER_NAME="app-sdk-grpc" OTEL_SERVICE_NAME="aspnetcore-example" +METRICS_DATASET="bogus_dataset" setup_file() { echo "# 🚧" >&3 @@ -11,6 +12,7 @@ setup_file() { wait_for_ready_app ${CONTAINER_NAME} curl --silent "http://localhost:5001/weatherforecast" wait_for_traces + wait_for_metrics 15 } teardown_file() { @@ -30,4 +32,9 @@ teardown_file() { @test "Manual instrumentation adds custom attribute" { result=$(span_attributes_for ${OTEL_SERVICE_NAME} | jq "select(.key == \"delay_ms\").value.intValue") assert_equal "$result" '"100"' +} + +@test "Manual instrumentation produces metrics" { + result=$(metric_names_for ${METRICS_DATASET}) + assert_equal "$result" '"sheep"' } \ No newline at end of file diff --git a/smoke-tests/smoke-sdk-http.bats b/smoke-tests/smoke-sdk-http.bats index 3a60b5a..76f19fb 100644 --- a/smoke-tests/smoke-sdk-http.bats +++ b/smoke-tests/smoke-sdk-http.bats @@ -4,6 +4,7 @@ load test_helpers/utilities CONTAINER_NAME="app-sdk-http" OTEL_SERVICE_NAME="aspnetcore-example" +METRICS_DATASET="bogus_dataset" setup_file() { echo "# 🚧" >&3 @@ -11,6 +12,7 @@ setup_file() { wait_for_ready_app ${CONTAINER_NAME} curl --silent "http://localhost:5001/weatherforecast" wait_for_traces + wait_for_metrics 15 } teardown_file() { @@ -31,3 +33,8 @@ teardown_file() { result=$(span_attributes_for ${OTEL_SERVICE_NAME} | jq "select(.key == \"delay_ms\").value.intValue") assert_equal "$result" '"100"' } + +@test "Manual instrumentation produces metrics" { + result=$(metric_names_for ${METRICS_DATASET}) + assert_equal "$result" '"sheep"' +} From 77bcb40a2d6a3f7a8d89bc2bdddebdb402ffd5a9 Mon Sep 17 00:00:00 2001 From: Purvi Kanal Date: Wed, 28 Sep 2022 14:56:51 -0400 Subject: [PATCH 2/5] add logic to append metrics path for http --- src/Honeycomb.OpenTelemetry/HoneycombOptions.cs | 11 ++++++++--- .../HoneycombOptionsTests.cs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs b/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs index 84107bc..4109b2b 100644 --- a/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs +++ b/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs @@ -17,7 +17,7 @@ public class HoneycombOptions private const string OtelExporterOtlpProtocolHttpJson = "http/json"; private const string OtelExporterOtlpProtocolGrpc = "grpc"; private const string OtelExporterHttpTracesPath = "/v1/traces"; - + private const string OtelExporterHttpMetricsPath = "/v1/traces"; private bool isHttp = false; /// @@ -230,7 +230,7 @@ internal void ApplyEnvironmentOptions(EnvironmentOptions environmentOptions) } /// - /// Computes the final traces endpoint. + /// Gets the or falls back to the generic . /// internal string GetTracesEndpoint() { @@ -257,7 +257,12 @@ internal string GetTracesDataset() /// internal string GetMetricsEndpoint() { - return new UriBuilder(MetricsEndpoint ?? Endpoint).ToString(); + var endpoint = new UriBuilder(Endpoint); + if (isHttp && (string.IsNullOrWhiteSpace(endpoint.Path) || endpoint.Path == "/")) + { + endpoint.Path = OtelExporterHttpMetricsPath; + } + return MetricsEndpoint ?? endpoint.ToString(); } /// diff --git a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs index 319535a..3b95f67 100644 --- a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs +++ b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs @@ -198,7 +198,7 @@ public void UsesMetricsSpecificValuesIfSet_Config() MetricsEndpoint = "http://collector:4318", MetricsApiKey = "my-api-key", }; - Assert.Equal("http://collector:4318/", options.GetMetricsEndpoint()); + Assert.Equal("http://collector:4318", options.GetMetricsEndpoint()); Assert.Equal("my-api-key", options.GetMetricsApiKey()); } From 86d0fc7d75d75f6b7aff24c3b0f038447daa5913 Mon Sep 17 00:00:00 2001 From: Purvi Kanal Date: Wed, 28 Sep 2022 15:23:37 -0400 Subject: [PATCH 3/5] consolidate traces tests with InlineData --- .../HoneycombOptionsTests.cs | 148 ++++++------------ 1 file changed, 44 insertions(+), 104 deletions(-) diff --git a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs index 3b95f67..59cd667 100644 --- a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs +++ b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs @@ -337,48 +337,43 @@ public void UseMetricsSpecificValuesOverGenericValues_EnvVars() Assert.Equal("my-metrics-api-key-env-var", options.GetMetricsApiKey()); } - [Fact] - public void AppendsTracesPathIfProtocolIsHttpProtobuf_Config() - { - var options = new HoneycombOptions - { - Endpoint = "http://collector:4318/" - }; - var values = new Dictionary - { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf"}, - }; - - options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); - Assert.Equal("http://collector:4318/v1/traces", options.GetTracesEndpoint()); - } - - [Fact] - public void AppendsTracesPathIfProtocolIsHttpJson_Config() + [Theory] + [InlineData("http/protobuf", "http://collector:4318", null)] + [InlineData("http/json", "http://collector:4318", null)] + [InlineData("http/protobuf", null, "http://collector:4318")] + [InlineData("http/json", null, "http://collector:4318")] + [InlineData("http/protobuf", "http://collector:4318", "http://collector:4318")] + [InlineData("http/json", "http://collector:4318", "http://collector:4318")] + public void AppendsTracesPathIfProtocolIsHttp(string protocol, string configEndpoint, string envVarEndpoint) { var options = new HoneycombOptions { - Endpoint = "http://collector:4318/" + Endpoint = configEndpoint }; var values = new Dictionary { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "http/json"}, + {"OTEL_EXPORTER_OTLP_PROTOCOL", protocol}, + {"HONEYCOMB_API_ENDPOINT", envVarEndpoint}, }; options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); - Assert.Equal("http://collector:4318/v1/traces", options.GetTracesEndpoint()); + Assert.Equal($"{options.Endpoint}/v1/traces", options.GetTracesEndpoint()); } - [Fact] - public void DoesNotAppendTracesPathIfProtocolIsGrpc_Config() + [Theory] + [InlineData("http://collector:4317", null)] + [InlineData(null, "http://collector:4317")] + [InlineData("http://collector:4317", "http://collector:4317")] + public void DoesNotAppendTracesPathIfProtocolIsGrpc(string configEndpoint, string envVarEndpoint) { var options = new HoneycombOptions { - Endpoint = "http://collector:4317/" + Endpoint = configEndpoint }; var values = new Dictionary { {"OTEL_EXPORTER_OTLP_PROTOCOL", "grpc"}, + {"HONEYCOMB_API_ENDPOINT", envVarEndpoint}, }; options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); @@ -386,108 +381,53 @@ public void DoesNotAppendTracesPathIfProtocolIsGrpc_Config() Assert.DoesNotContain("/v1/traces", options.GetTracesEndpoint()); } - [Fact] - public void AppendsTracesPathIfProtocolIsHttpProtobuf_EnvVars() - { - var options = new HoneycombOptions { }; - var values = new Dictionary - { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf"}, - {"HONEYCOMB_API_ENDPOINT", "http://collector:4318/"} - }; - - options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); - Assert.Equal("http://collector:4318/v1/traces", options.GetTracesEndpoint()); - } - - [Fact] - public void AppendsTracesPathIfProtocolIsHttpJson_EnvVars() - { - var options = new HoneycombOptions { }; - var values = new Dictionary - { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "http/json"}, - {"HONEYCOMB_API_ENDPOINT", "http://collector:4318/"} - }; - - options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); - Assert.Equal("http://collector:4318/v1/traces", options.GetTracesEndpoint()); - } - - [Fact] - public void DoesNotAppendTracesPathIfProtocolIsGrpc_EnvVars() - { - var options = new HoneycombOptions { }; - var values = new Dictionary - { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "grpc"}, - {"HONEYCOMB_API_ENDPOINT", "http://collector:4317/"} - }; - - options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); - Assert.Equal("http://collector:4317/", options.GetTracesEndpoint()); - Assert.DoesNotContain("/v1/traces", options.GetTracesEndpoint()); - } - - [Fact] - public void DoesNotAppendTracesPathToTracesEndpoint_Config() + [Theory] + [InlineData("http/protobuf", "http://collector:4318", null)] + [InlineData("http/json", "http://collector:4318", null)] + [InlineData("http/protobuf", null, "http://collector:4318")] + [InlineData("http/json", null, "http://collector:4318")] + [InlineData("http/protobuf", "http://collector:4318", "http://collector:4318")] + [InlineData("http/json", "http://collector:4318", "http://collector:4318")] + public void DoesNotAppendTracesPathToTracesEndpoints(string protocol, string configEndpoint, string envVarEndpoint) { var options = new HoneycombOptions { - TracesEndpoint = "http://collector:4318/" + TracesEndpoint = configEndpoint }; var values = new Dictionary { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf"}, - }; - - options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); - Assert.Equal("http://collector:4318/", options.GetTracesEndpoint()); - } + {"OTEL_EXPORTER_OTLP_PROTOCOL", protocol}, + {"HONEYCOMB_TRACES_ENDPOINT", envVarEndpoint}, - [Fact] - public void DoesNotAppendTracesPathToTracesEndpoint_EnvVars() - { - var options = new HoneycombOptions { }; - var values = new Dictionary - { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf"}, - {"HONEYCOMB_TRACES_ENDPOINT", "http://collector:4318/"} }; options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); - Assert.Equal("http://collector:4318/", options.GetTracesEndpoint()); - + Assert.Equal("http://collector:4318", options.GetTracesEndpoint()); + Assert.DoesNotContain("/v1/traces", options.GetTracesEndpoint()); } - [Fact] - public void DoesNotAppendTracesPathToGenericEndpointIfPathSpecified_Config() + [Theory] + [InlineData("http/protobuf", "http://collector:4318/my-special-path", null)] + [InlineData("http/json", "http://collector:4318/my-special-path", null)] + [InlineData("http/protobuf", null, "http://collector:4318/my-special-path")] + [InlineData("http/json", null, "http://collector:4318/my-special-path")] + [InlineData("http/protobuf", "http://collector:4318/my-special-path", "http://collector:4318/my-special-path")] + [InlineData("http/json", "http://collector:4318/my-special-path", "http://collector:4318/my-special-path")] + public void DoesNotAppendTracesPathToGenericEndpointIfPathSpecified(string protocol, string configEndpoint, string envVarEndpoint) { var options = new HoneycombOptions { - Endpoint = "http://collector:4318/my-special-path" + Endpoint = configEndpoint }; var values = new Dictionary { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf"}, - }; - - options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); - Assert.Equal("http://collector:4318/my-special-path", options.GetTracesEndpoint()); - } - - [Fact] - public void DoesNotAppendTracesPathToGenericEndpointIfPathSpecified_EnvVars() - { - var options = new HoneycombOptions { }; - var values = new Dictionary - { - {"OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf"}, - {"HONEYCOMB_API_ENDPOINT", "http://collector:4318/my-special-path"} + {"OTEL_EXPORTER_OTLP_PROTOCOL", protocol}, + {"HONEYCOMB_API_ENDPOINT", envVarEndpoint}, }; options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); Assert.Equal("http://collector:4318/my-special-path", options.GetTracesEndpoint()); + Assert.DoesNotContain("/v1/traces", options.GetTracesEndpoint()); } [Fact] From 4ea413c56b87d001d6a23c2499a9a1867b20f350 Mon Sep 17 00:00:00 2001 From: Purvi Kanal Date: Wed, 28 Sep 2022 15:38:55 -0400 Subject: [PATCH 4/5] add metrics tests for appending http path --- .../HoneycombOptions.cs | 2 +- .../HoneycombOptionsTests.cs | 93 +++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs b/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs index 4109b2b..d0b1394 100644 --- a/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs +++ b/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs @@ -17,7 +17,7 @@ public class HoneycombOptions private const string OtelExporterOtlpProtocolHttpJson = "http/json"; private const string OtelExporterOtlpProtocolGrpc = "grpc"; private const string OtelExporterHttpTracesPath = "/v1/traces"; - private const string OtelExporterHttpMetricsPath = "/v1/traces"; + private const string OtelExporterHttpMetricsPath = "/v1/metrics"; private bool isHttp = false; /// diff --git a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs index 59cd667..34ed169 100644 --- a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs +++ b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs @@ -430,6 +430,99 @@ public void DoesNotAppendTracesPathToGenericEndpointIfPathSpecified(string proto Assert.DoesNotContain("/v1/traces", options.GetTracesEndpoint()); } + [Theory] + [InlineData("http/protobuf", "http://collector:4318", null)] + [InlineData("http/json", "http://collector:4318", null)] + [InlineData("http/protobuf", null, "http://collector:4318")] + [InlineData("http/json", null, "http://collector:4318")] + [InlineData("http/protobuf", "http://collector:4318", "http://collector:4318")] + [InlineData("http/json", "http://collector:4318", "http://collector:4318")] + public void AppendsMetricsPathIfProtocolIsHttp(string protocol, string configEndpoint, string envVarEndpoint) + { + var options = new HoneycombOptions + { + Endpoint = configEndpoint + }; + var values = new Dictionary + { + {"OTEL_EXPORTER_OTLP_PROTOCOL", protocol}, + {"HONEYCOMB_API_ENDPOINT", envVarEndpoint}, + }; + + options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); + Assert.Equal($"{options.Endpoint}/v1/metrics", options.GetMetricsEndpoint()); + } + + [Theory] + [InlineData("http://collector:4317", null)] + [InlineData(null, "http://collector:4317")] + [InlineData("http://collector:4317", "http://collector:4317")] + public void DoesNotAppendMetricsPathIfProtocolIsGrpc(string configEndpoint, string envVarEndpoint) + { + var options = new HoneycombOptions + { + Endpoint = configEndpoint + }; + var values = new Dictionary + { + {"OTEL_EXPORTER_OTLP_PROTOCOL", "grpc"}, + {"HONEYCOMB_API_ENDPOINT", envVarEndpoint}, + }; + + options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); + Assert.Equal("http://collector:4317/", options.GetMetricsEndpoint()); + Assert.DoesNotContain("/v1/metrics", options.GetMetricsEndpoint()); + } + + [Theory] + [InlineData("http/protobuf", "http://collector:4318", null)] + [InlineData("http/json", "http://collector:4318", null)] + [InlineData("http/protobuf", null, "http://collector:4318")] + [InlineData("http/json", null, "http://collector:4318")] + [InlineData("http/protobuf", "http://collector:4318", "http://collector:4318")] + [InlineData("http/json", "http://collector:4318", "http://collector:4318")] + public void DoesNotAppendMetricsPathToMetricsEndpoints(string protocol, string configEndpoint, string envVarEndpoint) + { + var options = new HoneycombOptions + { + MetricsEndpoint = configEndpoint + }; + var values = new Dictionary + { + {"OTEL_EXPORTER_OTLP_PROTOCOL", protocol}, + {"HONEYCOMB_METRICS_ENDPOINT", envVarEndpoint}, + + }; + + options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); + Assert.Equal("http://collector:4318", options.GetMetricsEndpoint()); + Assert.DoesNotContain("/v1/metrics", options.GetMetricsEndpoint()); + } + + [Theory] + [InlineData("http/protobuf", "http://collector:4318/my-special-path", null)] + [InlineData("http/json", "http://collector:4318/my-special-path", null)] + [InlineData("http/protobuf", null, "http://collector:4318/my-special-path")] + [InlineData("http/json", null, "http://collector:4318/my-special-path")] + [InlineData("http/protobuf", "http://collector:4318/my-special-path", "http://collector:4318/my-special-path")] + [InlineData("http/json", "http://collector:4318/my-special-path", "http://collector:4318/my-special-path")] + public void DoesNotAppendMetricsPathToGenericEndpointIfPathSpecified(string protocol, string configEndpoint, string envVarEndpoint) + { + var options = new HoneycombOptions + { + Endpoint = configEndpoint + }; + var values = new Dictionary + { + {"OTEL_EXPORTER_OTLP_PROTOCOL", protocol}, + {"HONEYCOMB_API_ENDPOINT", envVarEndpoint}, + }; + + options.ApplyEnvironmentOptions(new EnvironmentOptions(values)); + Assert.Equal("http://collector:4318/my-special-path", options.GetMetricsEndpoint()); + Assert.DoesNotContain("/v1/metrics", options.GetMetricsEndpoint()); + } + [Fact] public void Legacy_key_length() { From 3fb63a82b8061425f960b16a8e3a82ca573206fa Mon Sep 17 00:00:00 2001 From: Purvi Kanal Date: Wed, 28 Sep 2022 15:58:36 -0400 Subject: [PATCH 5/5] remove metrics specific endpoint var from smoke tests --- smoke-tests/docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/smoke-tests/docker-compose.yml b/smoke-tests/docker-compose.yml index 3b98caf..5dffbf4 100644 --- a/smoke-tests/docker-compose.yml +++ b/smoke-tests/docker-compose.yml @@ -37,7 +37,6 @@ services: environment: <<: *env_base HONEYCOMB_API_ENDPOINT: http://collector:4318 - HONEYCOMB_METRICS_ENDPOINT: http://collector:4318/v1/metrics OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf ports: - "127.0.0.1:5001:5001"