Skip to content

Commit

Permalink
Split eventcounter and meters in metrics configuration (#3843)
Browse files Browse the repository at this point in the history
* Split eventcounter and meters in metrics configuration

* Update src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsSettingsFactory.cs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
wiktork and github-actions[bot] authored Mar 3, 2023
1 parent deb10b9 commit 97a9c61
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 55 deletions.
58 changes: 32 additions & 26 deletions documentation/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,16 @@
"items": {
"$ref": "#/definitions/MetricProvider"
}
},
"Meters": {
"type": [
"array",
"null"
],
"description": "Names of meters to collect from the System.Diagnostics.Metrics provider.",
"items": {
"$ref": "#/definitions/MeterConfiguration"
}
}
}
},
Expand All @@ -1297,35 +1307,31 @@
"items": {
"type": "string"
}
},
"MetricType": {
"description": "The type of metrics this provider consumes",
"default": "All",
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/MetricProviderType"
}
]
}
}
},
"MetricProviderType": {
"type": "string",
"description": "",
"x-enumFlags": true,
"x-enumNames": [
"EventCounter",
"Meter",
"All"
],
"enum": [
"EventCounter",
"Meter",
"All"
]
"MeterConfiguration": {
"type": "object",
"additionalProperties": false,
"properties": {
"MeterName": {
"type": [
"null",
"string"
],
"description": "Name of the custom meter."
},
"InstrumentNames": {
"type": [
"array",
"null"
],
"description": "Names of the custom instruments.",
"items": {
"type": "string"
}
}
}
},
"StorageOptions": {
"type": "object",
Expand Down
24 changes: 14 additions & 10 deletions src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class MetricsOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricsOptions_Providers))]
public List<MetricProvider> Providers { get; set; } = new List<MetricProvider>(0);

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricsOptions_Meters))]
public List<MeterConfiguration> Meters { get; set; } = new List<MeterConfiguration>(0);
}

public class MetricProvider
Expand All @@ -58,19 +63,18 @@ public class MetricProvider
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricProvider_CounterNames))]
public List<string> CounterNames { get; set; } = new List<string>(0);
}

public class MeterConfiguration
{
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricProvider_MetricType))]
[DefaultValue(MetricsOptionsDefaults.MetricType)]
public MetricProviderType? MetricType { get; set; }
}
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MeterConfiguration_MeterName))]
public string MeterName { get; set; }

[Flags]
public enum MetricProviderType
{
EventCounter = 0x1,
Meter = 0x2,
All = 0xFF
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MeterConfiguration_InstrumentNames))]
public List<string> InstrumentNames { get; set; } = new List<string>(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ internal static class MetricsOptionsDefaults
public const int MetricCount = 3;

public const bool IncludeDefaultProviders = true;

public const MetricProviderType MetricType = MetricProviderType.All;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,6 @@
<value>The maximum number of time series that can be tracked. Each unique combination of provider name, metric name, and dimension values counts as one time series. Tracking more time series uses more memory in the target process so this bound guards against unintentional high memory use.</value>
<comment>The description provided for the MaxTimeSeries parameter on MetricsOptions.</comment>
</data>
<data name="DisplayAttributeDescription_MetricProvider_MetricType" xml:space="preserve">
<value>The type of metrics this provider consumes</value>
<comment>The description provided for the MetricType parameter on MetricProvider.</comment>
</data>
<data name="DisplayAttributeDescription_GlobalCounterOptions_Providers" xml:space="preserve">
<value>Dictionary of provider names and their global configuration.</value>
</data>
Expand Down Expand Up @@ -799,4 +795,13 @@
<value>The array of meters for metrics to collect.</value>
<comment>The description provided for the Meters parameter on CollectLiveMetricsOptions.</comment>
</data>
</root>
<data name="DisplayAttributeDescription_MeterConfiguration_InstrumentNames" xml:space="preserve">
<value>Names of the custom instruments.</value>
</data>
<data name="DisplayAttributeDescription_MeterConfiguration_MeterName" xml:space="preserve">
<value>Name of the custom meter.</value>
</data>
<data name="DisplayAttributeDescription_MetricsOptions_Meters" xml:space="preserve">
<value>Names of meters to collect from the System.Diagnostics.Metrics provider.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static MetricsPipelineSettings CreateSettings(GlobalCounterOptions counte
Timeout.Infinite, counterOptions.GetIntervalSeconds(),
counterOptions.GetMaxHistograms(),
counterOptions.GetMaxTimeSeries(),
() => ConvertCounterGroups(options.Providers));
() => ConvertCounterGroups(options.Providers, options.Meters));
}

public static MetricsPipelineSettings CreateSettings(GlobalCounterOptions counterOptions, int durationSeconds,
Expand Down Expand Up @@ -71,22 +71,32 @@ private static MetricsPipelineSettings CreateSettings(bool includeDefaults,
};
}

private static List<EventPipeCounterGroup> ConvertCounterGroups(IList<MetricProvider> providers)
private static List<EventPipeCounterGroup> ConvertCounterGroups(IList<MetricProvider> providers, IList<MeterConfiguration> meters)
{
List<EventPipeCounterGroup> counterGroups = new();

if (providers?.Count > 0)
{
foreach (MetricProvider customProvider in providers)
{
var customCounterGroup = new EventPipeCounterGroup { ProviderName = customProvider.ProviderName };
if (customProvider.CounterNames.Count > 0)
var customCounterGroup = new EventPipeCounterGroup { ProviderName = customProvider.ProviderName, Type = CounterGroupType.EventCounter };
if (customProvider.CounterNames?.Count > 0)
{
customCounterGroup.CounterNames = customProvider.CounterNames.ToArray();
}
counterGroups.Add(customCounterGroup);
}
}

customCounterGroup.Type = (CounterGroupType)customProvider.MetricType.GetValueOrDefault(MetricsOptionsDefaults.MetricType);

if (meters?.Count > 0)
{
foreach (MeterConfiguration meter in meters)
{
var customCounterGroup = new EventPipeCounterGroup { ProviderName = meter.MeterName, Type = CounterGroupType.Meter };
if (meter.InstrumentNames?.Count > 0)
{
customCounterGroup.CounterNames = meter.InstrumentNames.ToArray();
}
counterGroups.Add(customCounterGroup);
}
}
Expand Down

0 comments on commit 97a9c61

Please sign in to comment.