Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otel -> aws -> qa #3405

Draft
wants to merge 155 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
3801b0f
pre test otel for word entry
andracc Jun 7, 2024
bd07ade
basic word creating tracing
andracc Jun 11, 2024
15f55cf
fuller tagging
andracc Jun 11, 2024
18065a3
git rebase issue fixed and initial metric setup
andracc Jun 12, 2024
6379e21
get user location with banner
andracc Jun 24, 2024
f0c02d1
handle null context and exceptions
andracc Jun 24, 2024
9dc3639
OtelKernel formatting
andracc Jun 25, 2024
84d9cb4
draft location in OtelKernel
andracc Jun 25, 2024
3b08cef
draft location caching
andracc Jul 1, 2024
b9d18c4
draft LocationEnricher
andracc Jul 2, 2024
ab41fa4
upgrade language version
andracc Jul 3, 2024
2a591d7
LocationEnricher only works once
andracc Jul 5, 2024
64f8266
address BannerControllerTests
andracc Jul 5, 2024
f5bd9fc
send to honeycomb
andracc Jul 8, 2024
b7e01b4
location cache fixed
andracc Jul 18, 2024
9f07b71
introducing telemetry helm chart
andracc Aug 8, 2024
bcb6319
Fix get_release() to convert '/' to '-' characters
jmgrady Aug 9, 2024
c0a13bc
Update deployment variables for external image
jmgrady Aug 9, 2024
26cc132
profile helm charts
andracc Aug 12, 2024
7617888
enable telemetry dependency
andracc Aug 13, 2024
9e5e47e
Merge branch 'master' into otel/initial-instrumentation
andracc Aug 13, 2024
53825e4
suppressed warning was resolved
andracc Aug 13, 2024
d65c3e5
Revert "suppressed warning was resolved"
andracc Aug 13, 2024
c8e1f9b
remove warning suppression
andracc Aug 13, 2024
ca544ba
install telemetry chart once as dependency
andracc Aug 15, 2024
247da4d
added otel service
andracc Aug 19, 2024
3b19691
Merge branch 'master' into otel/initial-instrumentation
andracc Aug 19, 2024
9cf971c
send OTEL to HC without collector
andracc Aug 20, 2024
474e141
send OTEL to HC without collector (fixed header)
andracc Aug 21, 2024
ec28701
Merge branch 'otel/initial-instrumentation' of https://github.com/sil…
andracc Aug 21, 2024
3ef46fb
moving to telemetry chart - in progress
andracc Aug 21, 2024
f3ce8b1
disable sending to HC from backend deployment
andracc Aug 22, 2024
eec8a8f
external-IP localhost with loadbalancer - undo
andracc Aug 22, 2024
9c3a656
config values for off-shelf chart
andracc Aug 26, 2024
59f1c1c
setup otel chart during cluster setup - in progress
andracc Aug 29, 2024
005b4cf
Add ability to provide secrets to 3rd-party charts
jmgrady Aug 28, 2024
3fb48fe
Replace "secrets" section with "additional_args"
jmgrady Aug 29, 2024
f858bde
Comment out example code
jmgrady Aug 29, 2024
6d647f4
use additional args instead of override for cluster install
andracc Aug 29, 2024
8d18ca2
fix setting secret
andracc Aug 29, 2024
1675cbb
Merge branch 'master' into otel/initial-instrumentation
andracc Aug 30, 2024
10c2e57
use target serverName as otel serviceName
andracc Sep 4, 2024
00ff933
custom otel service name based on target
andracc Sep 4, 2024
aa1f112
variable path in otel chart setup
andracc Sep 5, 2024
6da8ff2
note about reserved variable name
andracc Sep 5, 2024
5a47b27
Updates to setup_cluster.py
jmgrady Sep 5, 2024
8beab56
fix phrasing
andracc Sep 6, 2024
6a2b6c5
Merge remote-tracking branch 'origin/setup-cluster-changes' into otel…
andracc Sep 6, 2024
35f3101
after fmt-backend script
andracc Sep 6, 2024
6e79da7
after tox (remove unused import)
andracc Sep 6, 2024
d519822
provide helm exit status in info
andracc Sep 6, 2024
00c2977
backend serviceName as library.name in split HC charts
andracc Sep 6, 2024
372118d
check cov with tracerprovider
andracc Sep 18, 2024
e69f949
check cov with auth
andracc Sep 18, 2024
7e004b1
remove custom otel helm chart setup
andracc Sep 19, 2024
8867a83
save location test draft
andracc Sep 23, 2024
de9fbc0
change var name for ActivitySource
andracc Sep 23, 2024
f26bc45
one function for activity creation in Otel service
andracc Sep 24, 2024
bd8a3d7
separate code to exclude from testing
andracc Sep 24, 2024
9bf3355
clean Kernel
andracc Sep 24, 2024
0d8b6c5
test adding instrumentation and activity tag
andracc Sep 24, 2024
bd38789
LocationProvider interface and mock
andracc Sep 25, 2024
7c62e41
change location file name to match class
andracc Sep 25, 2024
ad17c22
clean otelservice
andracc Sep 25, 2024
8e54e30
initial otelkernel tests
andracc Sep 25, 2024
315d034
Add session id to frontend and send to backend
imnasnainaec Sep 24, 2024
ccf10aa
gets sessionId that was set in frontend
andracc Sep 26, 2024
8098773
cleaning OtelKernel
andracc Sep 26, 2024
d0329a1
tag is regionName (full) rather than region (abbrev)
andracc Sep 26, 2024
21598c0
redact ip from trace info
andracc Sep 27, 2024
5fa788b
pre combining client mock and test
andracc Sep 30, 2024
c546814
location testing mid memorycache
andracc Sep 30, 2024
4166310
pass along session baggage
andracc Oct 1, 2024
36c47fb
fixed test file names
andracc Oct 7, 2024
9c46644
async method not getting invoked
andracc Oct 7, 2024
b155e27
changes pre missing json token
andracc Oct 8, 2024
0ab03ea
valid json in httpresponsemessage content
andracc Oct 8, 2024
84795e6
cleaner json content
andracc Oct 9, 2024
6f75768
fixed ip mocking
andracc Oct 9, 2024
a119910
caching works
andracc Oct 9, 2024
4aa2403
get mocked ip rather than hard-code
andracc Oct 9, 2024
7e229cc
mock httpclient all within setup method
andracc Oct 9, 2024
3642baf
use real cache rather than mock
andracc Oct 9, 2024
1554c77
clean LP test and code
andracc Oct 9, 2024
5ba2b27
rename LP tests
andracc Oct 9, 2024
2eac403
AddOtelTag returns activity
andracc Oct 9, 2024
3c705ba
Merge branch 'master' into otel/initial-instrumentation
andracc Oct 9, 2024
7214fc3
not yet testing session
andracc Oct 9, 2024
20e5565
removing spaces
andracc Oct 9, 2024
a106f7a
try removing comments for formatting
andracc Oct 9, 2024
168f4db
try removing comments in func
andracc Oct 9, 2024
d6ccbd5
try removing object creation
andracc Oct 9, 2024
8c37dee
separate kernel classes and tmp comment test
andracc Oct 9, 2024
a5a6801
try moving onend from namespace
andracc Oct 9, 2024
ecb29be
try change end of line settings
andracc Oct 9, 2024
1836c65
revert end of line setting
andracc Oct 9, 2024
a9212e8
try remove more spaces
andracc Oct 9, 2024
99f7853
try simple OnEnd
andracc Oct 10, 2024
ee382de
try remove onend
andracc Oct 10, 2024
e5b68fa
try func signature
andracc Oct 10, 2024
3a4883a
try move onend
andracc Oct 10, 2024
c04bbb5
try move onend before otelkernel class
andracc Oct 10, 2024
76de569
formatted with updated dotnet format script
andracc Oct 10, 2024
3da4411
clean files for code review (besides kernel/service)
andracc Oct 10, 2024
5e70834
.59 method coverage
andracc Oct 11, 2024
d2769d1
.44 method coverage
andracc Oct 11, 2024
41415ec
OtelService and test for review
andracc Oct 11, 2024
31b29d1
Merge branch 'master' into otel/initial-instrumentation
andracc Oct 11, 2024
090ff52
proper format should pass test
andracc Oct 11, 2024
3ddb850
tmp save adding session
andracc Oct 12, 2024
9c3f93c
mid cleaning session testing
andracc Oct 12, 2024
f0220ef
basic session, location, ip testing
andracc Oct 12, 2024
b4bde92
address first code review
andracc Oct 13, 2024
d2ae959
address second code review
andracc Oct 14, 2024
1146711
updated license
andracc Oct 14, 2024
ae0ff12
update and clean packages
andracc Oct 14, 2024
1846a51
more descriptive function name
andracc Oct 14, 2024
1c2f890
cleaning unneeded code
andracc Oct 14, 2024
9175c96
Merge branch 'master' into otel/initial-instrumentation
andracc Oct 15, 2024
b46cdc3
addressed status, mem lim, cleaning tests, comments
andracc Oct 15, 2024
21dedca
address test cleaning
andracc Oct 16, 2024
bb87463
DisplayName should specify function
andracc Oct 16, 2024
be738d7
Fix activity tagging per Kevin H's suggestions
imnasnainaec Oct 16, 2024
0e2b718
Merge branch 'otel/initial-instrumentation' of https://github.com/sil…
imnasnainaec Oct 16, 2024
4de8243
remove OtelService method for instrumentation
andracc Oct 16, 2024
32c2569
more specific constants in OtelKernelTests
andracc Oct 16, 2024
59fab9d
use variable locationGetterUri
andracc Oct 16, 2024
be6c6fc
Merge branch 'otel/initial-instrumentation' of https://github.com/sil…
andracc Oct 16, 2024
bd91ef4
useGOMEMLIMIT true
andracc Oct 16, 2024
bd774e6
address more concise OtelKernel and var
andracc Oct 16, 2024
d92afde
api placeholder can be removed
andracc Oct 16, 2024
90f4166
addressed code review helm and test
andracc Oct 16, 2024
931efec
addressed clearer code
andracc Oct 16, 2024
1714201
Fix mismatch with aws-*-credentials
imnasnainaec Oct 16, 2024
c91a7e1
Fix helm stuff
imnasnainaec Oct 17, 2024
031e804
Fix fix
imnasnainaec Oct 17, 2024
23f01e3
Push to qa for testing
imnasnainaec Oct 18, 2024
e40c394
Update ecr repo cleanup
imnasnainaec Oct 18, 2024
806d9f1
Update ecr rem pattern
imnasnainaec Oct 18, 2024
ae03186
Restore only deploy from master
imnasnainaec Oct 18, 2024
d64f001
Revert aws-login change (part1)
imnasnainaec Oct 18, 2024
13d2fa6
Revert aws-login change (part2)
imnasnainaec Oct 18, 2024
78621b7
Extend log presence
imnasnainaec Oct 18, 2024
51bee4c
Merge branch 'aws-ecr' into otel-qa
imnasnainaec Oct 18, 2024
4fc9c86
Deploy to QA
imnasnainaec Oct 18, 2024
a690a90
Update maintenance scripts
imnasnainaec Oct 21, 2024
6a48f0f
More documentation
imnasnainaec Oct 21, 2024
9f44a70
Add comment
imnasnainaec Oct 21, 2024
3fae27e
Fix comment
imnasnainaec Oct 21, 2024
1ce1b0a
Merge branch 'aws-ecr' into otel-qa
imnasnainaec Oct 21, 2024
af49460
Fix aws-ecr-login command and resources
imnasnainaec Oct 22, 2024
3597669
Fix aws-ecr-login command
imnasnainaec Oct 22, 2024
636d8fa
Add resource limits
imnasnainaec Oct 22, 2024
b1ccd48
Merge branch 'master' into otel-qa
imnasnainaec Oct 22, 2024
eb272b6
Build to AWS, but don't deploy to QA
imnasnainaec Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy_qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Deploy Update to QA Server"

on:
push:
branches: [master]
branches: [master, otel-qa]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions Backend.Tests/Backend.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq.Contrib.HttpClient" Version="1.4.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
Expand Down
20 changes: 20 additions & 0 deletions Backend.Tests/Mocks/LocationProviderMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Threading.Tasks;
using BackendFramework.Interfaces;
using BackendFramework.Otel;

namespace Backend.Tests.Mocks
{
sealed internal class LocationProviderMock : ILocationProvider
{
public Task<LocationApi?> GetLocation()
{
LocationApi location = new LocationApi
{
Country = "test country",
RegionName = "test region",
City = "city"
};
return Task.FromResult<LocationApi?>(location);
}
}
}
116 changes: 116 additions & 0 deletions Backend.Tests/Otel/LocationProviderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using BackendFramework.Otel;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Moq.Protected;
using NUnit.Framework;

namespace Backend.Tests.Otel
{
public class LocationProviderTests
{
private readonly IPAddress TestIpAddress = new(new byte[] { 100, 0, 0, 0 });
private IHttpContextAccessor _contextAccessor = null!;
private IMemoryCache _memoryCache = null!;
private Mock<HttpMessageHandler> _handlerMock = null!;
private Mock<IHttpClientFactory> _httpClientFactory = null!;
private LocationProvider _locationProvider = null!;

[SetUp]
public void Setup()
{
// Set up HttpContextAccessor with mocked IP
_contextAccessor = new HttpContextAccessor();
var httpContext = new DefaultHttpContext()
{
Connection =
{
RemoteIpAddress = TestIpAddress
}
};
_contextAccessor.HttpContext = httpContext;

// Set up MemoryCache
var services = new ServiceCollection();
services.AddMemoryCache();
var serviceProvider = services.BuildServiceProvider();
_memoryCache = serviceProvider.GetService<IMemoryCache>()!;

var result = new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent("{}")
};

// Set up HttpClientFactory mock using httpClient with mocked HttpMessageHandler
_handlerMock = new Mock<HttpMessageHandler>();
_handlerMock.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(result)
.Verifiable();

var httpClient = new HttpClient(_handlerMock.Object);
_httpClientFactory = new Mock<IHttpClientFactory>();
_httpClientFactory
.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(httpClient);

_locationProvider = new LocationProvider(_contextAccessor, _memoryCache, _httpClientFactory.Object);
}

public static void Verify(Mock<HttpMessageHandler> mock, Func<HttpRequestMessage, bool> match)
{
mock.Protected()
.Verify(
"SendAsync",
Times.Exactly(1),
ItExpr.Is<HttpRequestMessage>(req => match(req)),
ItExpr.IsAny<CancellationToken>()
);
}

[Test]
public async Task GetLocationHttpClientUsesIp()
{
// Act
await _locationProvider.GetLocationFromIp(TestIpAddress.ToString());

// Assert
Verify(_handlerMock, r => r.RequestUri!.AbsoluteUri.Contains(TestIpAddress.ToString()));
Verify(_handlerMock, r => !r.RequestUri!.AbsoluteUri.Contains("123.1.2.3"));
}

[Test]
public async Task GetLocationUsesHttpContextIp()
{
// Act
await _locationProvider.GetLocation();

// Assert
Verify(_handlerMock, r => r.RequestUri!.AbsoluteUri.Contains(TestIpAddress.ToString()));
Verify(_handlerMock, r => !r.RequestUri!.AbsoluteUri.Contains("123.1.2.3"));
}

[Test]
public async Task GetLocationUsesCache()
{
// Act
// call getLocation twice and verify async method is called only once
await _locationProvider.GetLocation();
await _locationProvider.GetLocation();

// Assert
Verify(_handlerMock, r => r.RequestUri!.AbsoluteUri.Contains(TestIpAddress.ToString()));
}
}
}
99 changes: 99 additions & 0 deletions Backend.Tests/Otel/OtelKernelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Backend.Tests.Mocks;
using BackendFramework.Otel;
using Microsoft.AspNetCore.Http;
using NUnit.Framework;
using static BackendFramework.Otel.OtelKernel;

namespace Backend.Tests.Otel
{
public class OtelKernelTests : IDisposable
{
private const string FrontendSessionIdKey = "sessionId";
private const string OtelSessionIdKey = "sessionId";
private const string OtelSessionBaggageKey = "sessionBaggage";
private LocationEnricher _locationEnricher = null!;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_locationEnricher?.Dispose();
}
}

[Test]
public void BuildersSetSessionBaggageFromHeader()
{
// Arrange
var httpContext = new DefaultHttpContext();
httpContext.Request.Headers[FrontendSessionIdKey] = "123";
var activity = new Activity("testActivity").Start();

// Act
TrackSession(activity, httpContext.Request);

// Assert
Assert.That(activity.Baggage.Any(_ => _.Key == OtelSessionBaggageKey));
}

[Test]
public void OnEndSetsSessionTagFromBaggage()
{
// Arrange
var activity = new Activity("testActivity").Start();
activity.SetBaggage(OtelSessionBaggageKey, "test session id");

// Act
_locationEnricher.OnEnd(activity);

// Assert
Assert.That(activity.Tags.Any(_ => _.Key == OtelSessionIdKey));
}


[Test]
public void OnEndSetsLocationTags()
{
// Arrange
_locationEnricher = new LocationEnricher(new LocationProviderMock());
var activity = new Activity("testActivity").Start();

// Act
_locationEnricher.OnEnd(activity);

// Assert
var testLocation = new Dictionary<string, string>
{
{"country", "test country"},
{"regionName", "test region"},
{"city", "city"}
};
Assert.That(activity.Tags, Is.SupersetOf(testLocation));
}

public void OnEndRedactsIp()
{
// Arrange
_locationEnricher = new LocationEnricher(new LocationProviderMock());
var activity = new Activity("testActivity").Start();
activity.SetTag("url.full", $"{LocationProvider.locationGetterUri}100.0.0.0");

// Act
_locationEnricher.OnEnd(activity);

// Assert
Assert.That(activity.Tags.Any(_ => _.Key == "url.full" && _.Value == ""));
Assert.That(activity.Tags.Any(_ => _.Key == "url.redacted.ip" && _.Value == LocationProvider.locationGetterUri));
}
}
}
39 changes: 39 additions & 0 deletions Backend.Tests/Otel/OtelServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Diagnostics;
using BackendFramework.Otel;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

namespace Backend.Tests.Otel
{
public class OtelServiceTests
{
[Test]
public static void TestStartActivityWithTag()
{
// Arrange
var services = new ServiceCollection();
services.AddOpenTelemetryInstrumentation();
AddActivityListener();

// Act
var activity = OtelService.StartActivityWithTag("test key", "test val");
var tag = activity?.GetTagItem("test key");
var wrongTag = activity?.GetTagItem("wrong key");

// Assert
Assert.That(activity, Is.Not.Null);
Assert.That(tag, Is.Not.Null);
Assert.That(wrongTag, Is.Null);
}

private static void AddActivityListener()
{
var activityListener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData
};
ActivitySource.AddActivityListener(activityListener);
}
}
}
10 changes: 8 additions & 2 deletions Backend/BackendFramework.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>10.0</LangVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisMode>Recommended</AnalysisMode>
Expand All @@ -10,7 +10,13 @@
<NoWarn>$(NoWarn);CA1305;CA1848;CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RelaxNG" Version="3.2.3" >
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageReference Include="RelaxNG" Version="3.2.3">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
Expand Down
Loading
Loading