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

Add tags to every metric #5625

Merged
merged 5 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
8 changes: 0 additions & 8 deletions src/Nethermind/Nethermind.Init/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ namespace Nethermind.Init
public static class Metrics
{
[Description("Version number")]
[MetricsStaticDescriptionTag(nameof(ProductInfo.Version), typeof(ProductInfo))]
[MetricsStaticDescriptionTag(nameof(ProductInfo.Commit), typeof(ProductInfo))]
[MetricsStaticDescriptionTag(nameof(ProductInfo.Runtime), typeof(ProductInfo))]
[MetricsStaticDescriptionTag(nameof(ProductInfo.BuildTimestamp), typeof(ProductInfo))]
[MetricsStaticDescriptionTag(nameof(ProductInfo.Instance), typeof(ProductInfo))]
[MetricsStaticDescriptionTag(nameof(ProductInfo.Network), typeof(ProductInfo))]
[MetricsStaticDescriptionTag(nameof(ProductInfo.SyncType), typeof(ProductInfo))]
[MetricsStaticDescriptionTag(nameof(ProductInfo.PruningMode), typeof(ProductInfo))]
public static long Version { get; set; }
}
}
28 changes: 22 additions & 6 deletions src/Nethermind/Nethermind.Monitoring/Metrics/MetricsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using Nethermind.Core;
using Nethermind.Core.Attributes;
using Nethermind.Core.Collections;
using Nethermind.Monitoring.Config;
using Prometheus;

Expand Down Expand Up @@ -52,16 +54,30 @@ public void RegisterMetrics(Type type)

private static Gauge CreateMemberInfoMetricsGauge(MemberInfo member)
{
Dictionary<string, string> staticLabels = member
.GetCustomAttributes<MetricsStaticDescriptionTagAttribute>()
.ToDictionary(
attribute => attribute.Label,
attribute => GetStaticMemberInfo(attribute.Informer, attribute.Label));
Dictionary<string, string> staticTags = GetCommonStaticTags();

member.GetCustomAttributes<MetricsStaticDescriptionTagAttribute>()
.ForEach(attribute => staticTags.Add(attribute.Label, GetStaticMemberInfo(attribute.Informer, attribute.Label)));

string description = member.GetCustomAttribute<DescriptionAttribute>()?.Description;
string name = BuildGaugeName(member);

return CreateGauge(name, description, staticLabels);
return CreateGauge(name, description, staticTags);
}

// Tags that all metrics share
private static Dictionary<string, string> GetCommonStaticTags()
LukaszRozmej marked this conversation as resolved.
Show resolved Hide resolved
{
Dictionary<string, string> tags = new();
tags.Add(nameof(ProductInfo.Instance), ProductInfo.Instance);
tags.Add(nameof(ProductInfo.Network), ProductInfo.Network);
tags.Add(nameof(ProductInfo.SyncType), ProductInfo.SyncType);
tags.Add(nameof(ProductInfo.PruningMode), ProductInfo.PruningMode);
tags.Add(nameof(ProductInfo.Version), ProductInfo.Version);
tags.Add(nameof(ProductInfo.Commit), ProductInfo.Commit);
tags.Add(nameof(ProductInfo.Runtime), ProductInfo.Runtime);
tags.Add(nameof(ProductInfo.BuildTimestamp), ProductInfo.BuildTimestamp.ToUnixTimeSeconds().ToString());
return tags;
}

private static ObservableInstrument<double> CreateDiagnosticsMetricsObservableGauge(Meter meter, MemberInfo member, Func<double> observer)
Expand Down