diff --git a/Backend.Tests/Controllers/ProjectControllerTests.cs b/Backend.Tests/Controllers/ProjectControllerTests.cs index f074d8e510..8bd6a7091f 100644 --- a/Backend.Tests/Controllers/ProjectControllerTests.cs +++ b/Backend.Tests/Controllers/ProjectControllerTests.cs @@ -4,10 +4,8 @@ using BackendFramework.Controllers; using BackendFramework.Interfaces; using BackendFramework.Models; -using BackendFramework.Otel; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; namespace Backend.Tests.Controllers @@ -49,8 +47,6 @@ public void Setup() ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; - var services = new ServiceCollection(); - services.AddOpenTelemetryInstrumentation(); _jwtAuthenticatedUser = new User { Username = "user", Password = "pass" }; _userRepo.Create(_jwtAuthenticatedUser); _jwtAuthenticatedUser = _permissionService.Authenticate(_jwtAuthenticatedUser.Username, diff --git a/Backend.Tests/Controllers/WordControllerTests.cs b/Backend.Tests/Controllers/WordControllerTests.cs index 829471638c..9bd23f6f44 100644 --- a/Backend.Tests/Controllers/WordControllerTests.cs +++ b/Backend.Tests/Controllers/WordControllerTests.cs @@ -6,10 +6,8 @@ using BackendFramework.Controllers; using BackendFramework.Interfaces; using BackendFramework.Models; -// using BackendFramework.Otel; using BackendFramework.Services; using Microsoft.AspNetCore.Mvc; -// using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; namespace Backend.Tests.Controllers @@ -391,9 +389,6 @@ public async Task TestUpdateDuplicateNonDuplicate() [Test] public async Task TestCreateWord() { - // var service = new ServiceCollection(); - // service.AddOpenTelemetryInstrumentation(); - var word = Util.RandomWord(_projId); var id = (string)((ObjectResult)await _wordController.CreateWord(_projId, word)).Value!; @@ -404,8 +399,6 @@ public async Task TestCreateWord() var frontier = await _wordRepo.GetFrontier(_projId); Assert.That(frontier[0], Is.EqualTo(word)); - - } [Test] diff --git a/Backend.Tests/Otel/LocationProviderTests.cs b/Backend.Tests/Otel/LocationProviderTests.cs index 6bbcc0fac2..a46fd28ed2 100644 --- a/Backend.Tests/Otel/LocationProviderTests.cs +++ b/Backend.Tests/Otel/LocationProviderTests.cs @@ -1,18 +1,12 @@ using System; using System.Net; using System.Net.Http; -// using System.Net.Http.Json; - -// using System.Text; using System.Threading; using System.Threading.Tasks; -// using Backend.Tests.Mocks; using BackendFramework.Otel; -// using Castle.Core.Internal; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; -// using MongoDB.Driver; using Moq; using Moq.Protected; using NUnit.Framework; @@ -29,13 +23,6 @@ public class LocationProviderTests private Mock? _handlerMock; - // private - - // private static void MemFunction() - // { - - // } - [SetUp] public void Setup() { @@ -62,7 +49,6 @@ public void Setup() Content = new StringContent("{}") }; - // Set up HttpClientFactory mock using httpClient with mocked HttpMessageHandler _handlerMock = new Mock(); _handlerMock.Protected() @@ -124,8 +110,7 @@ public async Task GetLocationUsesCache() { var testIp = "100.0.0.0"; - // call getLocation twice and verify that the mocked async call - // was still only made once + // call getLocation twice and verify async method is called only once LocationApi? location = await _locationProvider?.GetLocation()!; location = await _locationProvider?.GetLocation()!; Verify(_handlerMock!, r => r.RequestUri!.AbsoluteUri.Contains(testIp)); diff --git a/Backend/BackendFramework.csproj b/Backend/BackendFramework.csproj index 2169bec12f..460f38b169 100644 --- a/Backend/BackendFramework.csproj +++ b/Backend/BackendFramework.csproj @@ -33,7 +33,7 @@ - + NU1701 diff --git a/Backend/Controllers/BannerController.cs b/Backend/Controllers/BannerController.cs index 32aca24fee..dc05ac898b 100644 --- a/Backend/Controllers/BannerController.cs +++ b/Backend/Controllers/BannerController.cs @@ -17,8 +17,6 @@ public class BannerController : Controller private readonly IBannerRepository _bannerRepo; private readonly IPermissionService _permissionService; - private const string otelTagName = "otel.report.controller"; - public BannerController(IBannerRepository bannerRepo, IPermissionService permissionService) { _bannerRepo = bannerRepo; diff --git a/Backend/Controllers/WordController.cs b/Backend/Controllers/WordController.cs index 0c454c6fd7..2cec8d5e0b 100644 --- a/Backend/Controllers/WordController.cs +++ b/Backend/Controllers/WordController.cs @@ -20,7 +20,7 @@ public class WordController : Controller private readonly IPermissionService _permissionService; private readonly IWordService _wordService; - private const string otelTagName = "otel.report.controller"; + private const string otelTagName = "otel.WordController"; public WordController(IWordRepository repo, IWordService wordService, IProjectRepository projRepo, IPermissionService permissionService) diff --git a/Backend/Otel/BackendActivitySource.cs b/Backend/Otel/BackendActivitySource.cs deleted file mode 100644 index 8848024af2..0000000000 --- a/Backend/Otel/BackendActivitySource.cs +++ /dev/null @@ -1,12 +0,0 @@ -// using System.Diagnostics; - -// namespace BackendFramework.Otel; - -// public class BackendActivitySource -// { -// public static ActivitySource Get() -// { -// // return new ActivitySource("service"); -// return new ActivitySource(OtelKernel.SourceName); -// } -// } diff --git a/Backend/Otel/DraftLocationProvider.cs b/Backend/Otel/DraftLocationProvider.cs deleted file mode 100644 index 0ba81d0b24..0000000000 --- a/Backend/Otel/DraftLocationProvider.cs +++ /dev/null @@ -1,77 +0,0 @@ - - -// using System; -// using System.Net.Http; -// using System.Net.Http.Json; -// using System.Threading.Tasks; -// using Microsoft.AspNetCore.Http; -// using Microsoft.Extensions.Caching.Memory; - -// namespace BackendFramework.Otel -// { -// public class DraftLocationProvider -// { -// public const string locationGetterUri = "http://ip-api.com/json/"; -// private readonly IHttpContextAccessor _contextAccessor; -// private readonly IMemoryCache _memoryCache; -// private readonly IHttpClientFactory _httpClientFactory; -// public DraftLocationProvider(IHttpContextAccessor contextAccessor, IMemoryCache memoryCache, IHttpClientFactory httpClientFactory) -// { -// _contextAccessor = contextAccessor; -// _memoryCache = memoryCache; -// _httpClientFactory = httpClientFactory; - -// } -// public async Task GetLocation() -// { -// // note: adding any activity tags in this function will cause overflow -// // because function called on each activity in OtelKernel -// if (_contextAccessor.HttpContext is { } context) -// { -// var ipAddress = context.GetServerVariable("HTTP_X_FORWARDED_FOR") ?? context.Connection.RemoteIpAddress?.ToString(); -// var ipAddressWithoutPort = ipAddress?.Split(':')[0]; -// ipAddressWithoutPort = "100.0.0.0"; - -// LocationApi? location = await GetLocationWithCaching(ipAddressWithoutPort); -// return location; -// } -// return null; -// } - -// public Task GetLocationWithCaching(string ipAddressWithoutPort) -// { - -// var location = _memoryCache.GetOrCreateAsync( -// "location_" + ipAddressWithoutPort, -// async (cacheEntry) => -// { -// cacheEntry.SlidingExpiration = TimeSpan.FromHours(1); -// try -// { -// return await GetLocationFromIp(ipAddressWithoutPort); - - -// } -// catch (Exception) -// { -// // todo consider what to have in catch -// Console.WriteLine("Attempted to get location but exception"); -// throw; -// } -// }); -// return location; - -// } - -// public async Task GetLocationFromIp(string ipAddressWithoutPort) -// { - -// var route = locationGetterUri + $"{ipAddressWithoutPort}"; -// var httpClient = _httpClientFactory.CreateClient(); -// var response = await httpClient.GetFromJsonAsync(route); - -// return response; - -// } -// } -// } diff --git a/Backend/Otel/LocationProvider.cs b/Backend/Otel/LocationProvider.cs index 7daf1c66b9..9f176a6112 100644 --- a/Backend/Otel/LocationProvider.cs +++ b/Backend/Otel/LocationProvider.cs @@ -7,7 +7,6 @@ using BackendFramework.Interfaces; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Memory; -// using SharpCompress.Archives; namespace BackendFramework.Otel { @@ -45,7 +44,7 @@ public LocationProvider(IHttpContextAccessor contextAccessor, IMemoryCache memor } catch (Exception) { - // todo consider what to have in catch + // TODO consider what to have in catch Console.WriteLine("Attempted to get location but exception"); throw; } @@ -57,12 +56,10 @@ public LocationProvider(IHttpContextAccessor contextAccessor, IMemoryCache memor internal async Task GetLocationFromIp(string? ipAddressWithoutPort) { - var route = locationGetterUri + $"{ipAddressWithoutPort}"; var httpClient = _httpClientFactory.CreateClient(); var response = await httpClient.GetFromJsonAsync(route); return response; - } } } diff --git a/Backend/Properties/launchSettings.json b/Backend/Properties/launchSettings.json index c859227ddc..3fad483db3 100644 --- a/Backend/Properties/launchSettings.json +++ b/Backend/Properties/launchSettings.json @@ -28,8 +28,6 @@ "environmentVariables": { "Key": "Value", "ASPNETCORE_ENVIRONMENT": "Development", - "OTEL_EXPORTER_OTLP_PROTOCOL": "grpc", - "OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317", "COMBINE_CAPTCHA_REQUIRED": "true", "COMBINE_CAPTCHA_SECRET_KEY": "1x0000000000000000000000000000000AA", "COMBINE_CAPTCHA_VERIFY_URL": "https://challenges.cloudflare.com/turnstile/v0/siteverify", diff --git a/Backend/Repositories/WordRepository.cs b/Backend/Repositories/WordRepository.cs index 753585f20e..07f55507fc 100644 --- a/Backend/Repositories/WordRepository.cs +++ b/Backend/Repositories/WordRepository.cs @@ -1,13 +1,11 @@ using System; using System.Collections.Generic; -// using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using BackendFramework.Helper; using BackendFramework.Interfaces; using BackendFramework.Models; using BackendFramework.Otel; -// using Microsoft.Extensions.Logging; using MongoDB.Driver; namespace BackendFramework.Repositories @@ -18,7 +16,7 @@ public class WordRepository : IWordRepository { private readonly IWordContext _wordDatabase; - private const string otelTagName = "otel.report.wordrepo"; + private const string otelTagName = "otel.WordRepository"; public WordRepository(IWordContext collectionSettings) { diff --git a/Backend/Services/WordService.cs b/Backend/Services/WordService.cs index 777cf197fd..9e842511dc 100644 --- a/Backend/Services/WordService.cs +++ b/Backend/Services/WordService.cs @@ -12,7 +12,7 @@ public class WordService : IWordService { private readonly IWordRepository _wordRepo; - private const string otelTagName = "otel.report.service"; + private const string otelTagName = "otel.WordService"; public WordService(IWordRepository wordRepo) { @@ -63,7 +63,7 @@ private async Task Add(string userId, Word word) /// A bool: success of operation public async Task Delete(string projectId, string userId, string wordId) { - // note: review tag description + // TODO review tag description OtelService.AddOtelTag(otelTagName, "deleting a word"); var wordIsInFrontier = await _wordRepo.DeleteFrontier(projectId, wordId); diff --git a/Backend/Startup.cs b/Backend/Startup.cs index 99247b6ea7..1d423b2c97 100644 --- a/Backend/Startup.cs +++ b/Backend/Startup.cs @@ -17,9 +17,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; -// using OpenTelemetry.Resources; -// using OpenTelemetry.Trace; -// using OpenTelemetry.Exporter; using static System.Text.Encoding; namespace BackendFramework @@ -293,11 +290,9 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient(); // OpenTelemetry + services.AddHttpClient(); services.AddMemoryCache(); services.AddHttpContextAccessor(); - - services.AddHttpClient(); - // services.AddSingleton(); services.AddTransient(); services.AddOpenTelemetryInstrumentation(); diff --git a/deploy/helm/thecombine/charts/backend/templates/deployment-backend.yaml b/deploy/helm/thecombine/charts/backend/templates/deployment-backend.yaml index 2d1d8fbc3a..bcfdc71c3a 100644 --- a/deploy/helm/thecombine/charts/backend/templates/deployment-backend.yaml +++ b/deploy/helm/thecombine/charts/backend/templates/deployment-backend.yaml @@ -95,7 +95,6 @@ spec: secretKeyRef: key: COMBINE_SMTP_USERNAME name: env-backend-secrets - ports: - containerPort: 5000 resources: diff --git a/deploy/scripts/setup_files/cluster_config.yaml b/deploy/scripts/setup_files/cluster_config.yaml index 533b93ad8d..61e911a325 100644 --- a/deploy/scripts/setup_files/cluster_config.yaml +++ b/deploy/scripts/setup_files/cluster_config.yaml @@ -31,9 +31,6 @@ otel: # values inside curly braces ({}) are interpreted as # environment variables and their values will be substituted for # the curly brace expression. - # If $scripts_dir included in an additional argument, it - # will be interpreted as a variable and its value will be - # substituted by the scripts_dir variable set in setup_cluster.py. additional_args: - --values - "{SCRIPTS_DIR}/setup_files/collector_config.yaml" diff --git a/deploy/scripts/setup_files/collector_config.yaml b/deploy/scripts/setup_files/collector_config.yaml index 14d32e127e..5caef6716b 100644 --- a/deploy/scripts/setup_files/collector_config.yaml +++ b/deploy/scripts/setup_files/collector_config.yaml @@ -2,12 +2,6 @@ mode: "deployment" namespaceOverride: "thecombine" image: repository: "otel/opentelemetry-collector-k8s" -# extraEnvs: -# - name: HONEYCOMB_API_KEY -# valueFrom: -# secretKeyRef: -# name: honeycomb-secret -# key: api-key config: receivers: jaeger: null @@ -19,14 +13,10 @@ config: endpoint: 0.0.0.0:4317 http: endpoint: 0.0.0.0:4318 - # cors: - # allowed_origins: - # - "http://thecombine.localhost/*" processors: batch: {} exporters: otlp: - # endpoint: "api.honeycomb.io:443" endpoint: "https://api.honeycomb.io:443" headers: "x-honeycomb-team": "" @@ -48,11 +38,6 @@ config: ports: otlp: enabled: false - # enabled: true - # containerPort: 4317 - # servicePort: 4317 - # hostPort: 4317 - # protocol: TCP otlp-http: enabled: true containerPort: 4318