Skip to content

Commit

Permalink
feat: onetime headers for agent and runtime-version
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce committed Jun 12, 2024
1 parent 1d8a472 commit c3cdae2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Momento.Sdk/Internal/ScsDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
Expand All @@ -22,6 +23,7 @@ public class ScsDataClientBase : IDisposable
private readonly TimeSpan defaultTtl;
private readonly TimeSpan dataClientOperationTimeout;
private readonly ILogger _logger;
private bool hasSentOnetimeHeaders = false;

protected readonly CacheExceptionMapper _exceptionMapper;

Expand All @@ -41,7 +43,13 @@ internal Task EagerConnectAsync(TimeSpan eagerConnectionTimeout)

protected Metadata MetadataWithCache(string cacheName)
{
return new Metadata() { { "cache", cacheName } };
if (this.hasSentOnetimeHeaders) {
return new Metadata() { { "cache", cacheName } };
}
this.hasSentOnetimeHeaders = true;
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
return new Metadata() { { "cache", cacheName }, { "Agent", $"dotnet:{version}" }, { "Runtime-Version", runtimeVer } };
}
protected DateTime CalculateDeadline()
{
Expand Down
11 changes: 10 additions & 1 deletion src/Momento.Sdk/Internal/ScsTopicClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
Expand All @@ -18,6 +19,7 @@ public class ScsTopicClientBase : IDisposable
protected readonly TopicGrpcManager grpcManager;
private readonly TimeSpan dataClientOperationTimeout;
private readonly ILogger _logger;
private bool hasSentOnetimeHeaders = false;

protected readonly CacheExceptionMapper _exceptionMapper;

Expand All @@ -31,7 +33,14 @@ public ScsTopicClientBase(ITopicConfiguration config, string authToken, string e

protected Metadata MetadataWithCache(string cacheName)
{
return new Metadata() { { "cache", cacheName } };
if (this.hasSentOnetimeHeaders) {
return new Metadata() { { "cache", cacheName } };
}
this.hasSentOnetimeHeaders = true;
string sdkVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
Console.WriteLine($"cache: {cacheName}, agent:{sdkVersion}, runtime-version:{runtimeVer}");
return new Metadata() { { "cache", cacheName }, { "Agent", $"dotnet:{sdkVersion}" }, { "Runtime-Version", runtimeVer } };
}

protected DateTime CalculateDeadline()
Expand Down

0 comments on commit c3cdae2

Please sign in to comment.