Skip to content

Commit

Permalink
Add http metrics tests (#716)
Browse files Browse the repository at this point in the history
* Add OTLP proto v0.18.0 to test helpers.

* Fix spelling and lint issues in readme

* Fix proto search path

* Add initial mock collector for metrics

* Improve mock collector bad request handling

* Add test for http metrics

* Remove commented out code

* Fix mockcollector metrics endpoint

* Fix http metrics test assertions

* Update mockcollector listener prefix to not require admin priveledges

* Rename default wait timeout in mock collector

Co-authored-by: Rajkumar Rangaraj <[email protected]>
  • Loading branch information
nrcventura and rajkumar-rangaraj authored Jun 17, 2022
1 parent 74b0ecf commit 1cd4583
Show file tree
Hide file tree
Showing 24 changed files with 2,131 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .cspell/other.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ dylib
bytecode
unencrypted
UNENCRYPTEDSUPPORT
proto
protos
protobuf
bitness
cmake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ public static void ClearProfilerEnvironmentVariables()
"OTEL_DOTNET_AUTO_INTEGRATIONS_FILE",
"OTEL_DISABLED_INTEGRATIONS",
"OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES",
"OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES"
"OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES",
"OTEL_TRACES_EXPORTER",
"OTEL_METRICS_EXPORTER",
"OTEL_EXPORTER_ZIPKIN_ENDPOINT",
"OTEL_EXPORTER_OTLP_ENDPOINT"
};

foreach (string variable in environmentVariables)
Expand Down Expand Up @@ -150,11 +154,9 @@ public static bool IsRunningOnCI()
}

public void SetEnvironmentVariables(
int agentPort,
int aspNetCorePort,
TestSettings testSettings,
StringDictionary environmentVariables,
bool enableStartupHook,
string processToProfile = null)
string processToProfile)
{
string profilerEnabled = _requiresProfiling ? "1" : "0";
string profilerPath = GetProfilerPath();
Expand All @@ -163,7 +165,7 @@ public void SetEnvironmentVariables(
{
// enableStartupHook should be true by default, and the parameter should only be set
// to false when testing the case that instrumentation should not be available.
if (enableStartupHook)
if (testSettings.EnableStartupHook)
{
environmentVariables["DOTNET_STARTUP_HOOKS"] = GetStartupHookOutputPath();
environmentVariables["DOTNET_SHARED_STORE"] = GetSharedStorePath();
Expand Down Expand Up @@ -195,11 +197,21 @@ public void SetEnvironmentVariables(
string integrations = GetIntegrationsPath();
environmentVariables["OTEL_DOTNET_AUTO_HOME"] = GetNukeBuildOutput();
environmentVariables["OTEL_DOTNET_AUTO_INTEGRATIONS_FILE"] = integrations;
environmentVariables["OTEL_TRACES_EXPORTER"] = "zipkin";
environmentVariables["OTEL_EXPORTER_ZIPKIN_ENDPOINT"] = $"http://127.0.0.1:{agentPort}";

if (testSettings.TracesSettings != null)
{
environmentVariables["OTEL_TRACES_EXPORTER"] = testSettings.TracesSettings.Exporter;
environmentVariables["OTEL_EXPORTER_ZIPKIN_ENDPOINT"] = $"http://127.0.0.1:{testSettings.TracesSettings.Port}";
}

if (testSettings.MetricsSettings != null)
{
environmentVariables["OTEL_METRICS_EXPORTER"] = testSettings.MetricsSettings.Exporter;
environmentVariables["OTEL_EXPORTER_OTLP_ENDPOINT"] = $"http://127.0.0.1:{testSettings.MetricsSettings.Port}";
}

// for ASP.NET Core test applications, set the server's port
environmentVariables["ASPNETCORE_URLS"] = $"http://127.0.0.1:{aspNetCorePort}/";
environmentVariables["ASPNETCORE_URLS"] = $"http://127.0.0.1:{testSettings.AspNetCorePort}/";

environmentVariables["OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES"] = "TestApplication.*";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ public class InstrumentedProcessHelper
public static Process StartInstrumentedProcess(
string executable,
EnvironmentHelper environmentHelper,
string arguments = null,
bool redirectStandardInput = false,
int traceAgentPort = 9696,
int aspNetCorePort = 5000,
string processToProfile = null,
bool enableStartupHook = true)
string arguments,
TestSettings testSettings)
{
if (environmentHelper == null)
{
Expand All @@ -41,13 +37,13 @@ public static Process StartInstrumentedProcess(

var startInfo = new ProcessStartInfo(executable, $"{arguments ?? string.Empty}");

environmentHelper.SetEnvironmentVariables(traceAgentPort, aspNetCorePort, startInfo.EnvironmentVariables, enableStartupHook, processToProfile);
environmentHelper.SetEnvironmentVariables(testSettings, startInfo.EnvironmentVariables, executable);

startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardInput = redirectStandardInput;
startInfo.RedirectStandardInput = false;

return Process.Start(startInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<ItemGroup>
<PackageReference Include="DotNet.Testcontainers" Version="1.6.0" />
<PackageReference Include="Google.Protobuf" Version="3.21.1" />
<PackageReference Include="Grpc.Tools" Version="2.46.3" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
Expand All @@ -12,4 +14,9 @@
<ItemGroup>
<ProjectReference Include="..\..\..\src\OpenTelemetry.AutoInstrumentation\OpenTelemetry.AutoInstrumentation.csproj" />
</ItemGroup>

<ItemGroup>
<!-- GrpcServices is 'none' so that we do not need to depend on the grpc nuget package, and we only need protobuf support. -->
<Protobuf Include="opentelemetry\**\*.proto" GrpcServices="none" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions test/integration-tests/IntegrationTests.Helpers/MetricsSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// <copyright file="MetricsSettings.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// 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
//
// http://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.
// </copyright>

namespace IntegrationTests.Helpers
{
public class MetricsSettings
{
public string Exporter => "otlp";

public int Port { get; set; }
}
}
Loading

0 comments on commit 1cd4583

Please sign in to comment.