Skip to content

Commit 53b607a

Browse files
committed
Update ClientSettingsFactory.cs
#!components: grid-bot ~ Fix prometheus counter labels. ~ Fix parsing issue within GetSettingForApplication
1 parent ff180a6 commit 53b607a

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

services/grid-bot/lib/utility/Implementation/ClientSettingsFactory.cs

+11-21
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ public class ClientSettingsFactory : IClientSettingsFactory
4444
private readonly Counter _settingsRefreshCounter = Metrics.CreateCounter(
4545
"rbx_client_settings_refresh",
4646
"Number of times the client settings have been refreshed.",
47-
"mount", "path"
47+
"application"
4848
);
4949
private readonly Counter _settingsWriteCounter = Metrics.CreateCounter(
5050
"rbx_client_settings_write",
5151
"Number of times the client settings have been written.",
52-
"mount", "path"
52+
"application"
5353
);
5454
private readonly Counter _settingsReadCounter = Metrics.CreateCounter(
5555
"rbx_client_settings_read",
5656
"Number of times the client settings have been read.",
57-
"mount", "path"
57+
"application"
5858
);
5959

6060

@@ -264,7 +264,7 @@ private Dictionary<string, object> ParseSecrets(Secrets secrets, MetaData metada
264264
private void DoCommit(string applicationName, Secrets data, MetaData metadata)
265265
{
266266
var serializedData = data.ToDictionary(k => k.Key, v => v.Value.ToString());
267-
_settingsWriteCounter.WithLabels(_mount, _path).Inc();
267+
_settingsWriteCounter.WithLabels(applicationName).Inc();
268268

269269
if (_settings.ClientSettingsViaVault)
270270
{
@@ -299,7 +299,6 @@ _client.V1.Secrets.KeyValue.V2 .WriteSecretAsync(
299299
private IDictionary<string, Secrets> DoRefresh(IDictionary<string, Secrets> oldSettings)
300300
{
301301
_logger?.Debug("Refreshing settings, FromVault = {0}", _settings.ClientSettingsViaVault);
302-
_settingsRefreshCounter.WithLabels(_mount, _path).Inc();
303302

304303
var settings = new Dictionary<string, Secrets>();
305304

@@ -311,6 +310,8 @@ private IDictionary<string, Secrets> DoRefresh(IDictionary<string, Secrets> oldS
311310
// For each key, read the secret
312311
foreach (var (applicationName, applicationData, applicationMetaData) in data)
313312
{
313+
_settingsRefreshCounter.WithLabels(applicationName).Inc();
314+
314315
var parsedSecrets = ParseSecrets(applicationData, applicationMetaData);
315316
settings.Add(applicationName, parsedSecrets);
316317
}
@@ -348,16 +349,7 @@ public IDictionary<string, Secrets> RawSettings
348349
/// <inheritdoc cref="IClientSettingsFactory.Refresh"/>
349350
public void Refresh()
350351
{
351-
_settingsCacheLock.EnterWriteLock();
352-
353-
try
354-
{
355-
_settingsCacheRefreshAhead.LazyValue.Refresh();
356-
}
357-
finally
358-
{
359-
_settingsCacheLock.ExitWriteLock();
360-
}
352+
_settingsCacheRefreshAhead.LazyValue.Refresh();
361353
}
362354

363355
/// <inheritdoc cref="IClientSettingsFactory.GetSettingsForApplication(string, bool)"/>
@@ -368,7 +360,7 @@ public Secrets GetSettingsForApplication(string application, bool withDependenci
368360

369361
_settingsCacheLock.EnterReadLock();
370362

371-
_settingsReadCounter.WithLabels(_mount, _path).Inc();
363+
_settingsReadCounter.WithLabels(application).Inc();
372364

373365
try
374366
{
@@ -438,13 +430,11 @@ public T GetSettingForApplication<T>(string application, string setting, bool wi
438430

439431
try
440432
{
441-
var str = ((JsonElement)value).GetString();
442-
443433
return typeof(T) switch
444434
{
445-
Type t when t == typeof(string) => (T)(object)str.ToString(),
446-
Type t when t == typeof(bool) => (T)(object)bool.Parse(str),
447-
Type t when t == typeof(int) => (T)(object)long.Parse(str),
435+
Type t when t == typeof(string) => (T)(object)value.ToString(),
436+
Type t when t == typeof(bool) => (T)value,
437+
Type t when t == typeof(int) => (T)value,
448438
_ => throw new ArgumentException(string.Format("'{0}' is not a supported type!", typeof(T).Name)),
449439
};
450440
}

0 commit comments

Comments
 (0)