-
Notifications
You must be signed in to change notification settings - Fork 30
Metrics command group #468
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f88b446
Start work on metrics command group
d3e2e60
Dimensions command
2fe4cff
Dimension (values) command
e51e65e
Metrics CLI tests
bf8b46a
Metrics MCP tools
cae41fe
Port metrics CLI tests to cover the metrics MCP tools. Groups argumen…
6e01fc8
Fix string[] parameter binding
nblumhardt 7f95d88
Invoke Deserialize() as an extension method
nblumhardt 46e6cad
Quick README fix for non-pre Forwarder commands
nblumhardt 2b76a4c
Drop out Autofac from `mcp run` - yesterday's hack isn't holding up, …
02dc5db
PR feedback, basic metrics skill, fixes
4cd44a5
Patch up skill size test
nblumhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright © Datalust Pty Ltd | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using System; | ||
| using System.Globalization; | ||
| using System.Threading.Tasks; | ||
| using SeqCli.Api; | ||
| using SeqCli.Cli.Features; | ||
| using SeqCli.Config; | ||
| using Serilog; | ||
|
|
||
| namespace SeqCli.Cli.Commands.Metrics; | ||
|
|
||
| [Command("metrics", "dimension", "List distinct values for a metric dimension", | ||
| Example = "seqcli metrics dimension --accessor @Resource.service.name")] | ||
| class DimensionCommand : Command | ||
| { | ||
| readonly ConnectionFeature _connection; | ||
| readonly OutputFormatFeature _output; | ||
| readonly DateRangeFeature _range; | ||
| readonly StoragePathFeature _storagePath; | ||
| string? _accessor; | ||
| int _count = 30; | ||
| bool _trace; | ||
|
|
||
| public DimensionCommand() | ||
| { | ||
| Options.Add( | ||
| "d=|accessor=", | ||
| "The dimension accessor, e.g. `cpu.mode`", | ||
| v => _accessor= v); | ||
|
|
||
| Options.Add( | ||
| "c=|count=", | ||
| $"The maximum number of dimensions to retrieve; the default is {_count}", | ||
| v => _count = int.Parse(v, CultureInfo.InvariantCulture)); | ||
|
|
||
| _range = Enable<DateRangeFeature>(); | ||
| _output = Enable(new OutputFormatFeature(supportNative: true)); | ||
| _storagePath = Enable<StoragePathFeature>(); | ||
|
|
||
| Options.Add("trace", "Enable detailed (server-side) query tracing", _ => _trace = true); | ||
|
|
||
| _connection = Enable<ConnectionFeature>(); | ||
| } | ||
|
|
||
| protected override async Task<int> Run() | ||
| { | ||
| try | ||
| { | ||
| if (string.IsNullOrWhiteSpace(_accessor)) | ||
| { | ||
| Log.Error("A dimension `--accessor` must be specified"); | ||
| return 1; | ||
| } | ||
|
|
||
| var config = RuntimeConfigurationLoader.Load(_storagePath); | ||
| var output = _output.GetOutputFormat(config); | ||
| var connection = SeqConnectionFactory.Connect(_connection, config); | ||
|
|
||
| var result = await connection.Metrics.ListDimensionValuesAsync( | ||
| _accessor, | ||
| _count, | ||
| rangeStartUtc: _range.Start, | ||
| rangeEndUtc: _range.End, | ||
| trace: _trace); | ||
|
|
||
| if (output.Json) | ||
| { | ||
| // In the JSON case we write an array with all values. | ||
| output.WriteObject(result); | ||
| } | ||
| else | ||
| { | ||
| // Native and plain text formatting use one-per-line output (both allow multi-line strings, but | ||
| // string boundaries are clearer in native mode). | ||
| foreach (var value in result) | ||
| { | ||
| output.WriteObject(value); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Error(ex, "Could not retrieve metrics: {ErrorMessage}", ex.Message); | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright © Datalust Pty Ltd | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using System; | ||
| using System.Globalization; | ||
| using System.Threading.Tasks; | ||
| using SeqCli.Api; | ||
| using SeqCli.Cli.Features; | ||
| using SeqCli.Config; | ||
| using Serilog; | ||
|
|
||
| namespace SeqCli.Cli.Commands.Metrics; | ||
|
|
||
| [Command("metrics", "dimensions", "List the dimensions associated with a given metric", | ||
| Example = "seqcli metrics dimensions -m http.response.status_code")] | ||
| class DimensionsCommand : Command | ||
| { | ||
| readonly ConnectionFeature _connection; | ||
| readonly OutputFormatFeature _output; | ||
| readonly DateRangeFeature _range; | ||
| readonly StoragePathFeature _storagePath; | ||
| string? _metric; | ||
| int _count = 30; | ||
| bool _trace; | ||
|
|
||
| public DimensionsCommand() | ||
| { | ||
| Options.Add( | ||
| "m=|metric=", | ||
| "A metric name, for example `hats-sold` or `http.request.duration`; omit to list dimensions for all metrics", | ||
| v => _metric= v); | ||
|
|
||
| Options.Add( | ||
| "c=|count=", | ||
| $"The maximum number of dimensions to retrieve; the default is {_count}", | ||
| v => _count = int.Parse(v, CultureInfo.InvariantCulture)); | ||
|
|
||
| _range = Enable<DateRangeFeature>(); | ||
| _output = Enable<OutputFormatFeature>(); | ||
| _storagePath = Enable<StoragePathFeature>(); | ||
|
|
||
| Options.Add("trace", "Enable detailed (server-side) query tracing", _ => _trace = true); | ||
|
|
||
| _connection = Enable<ConnectionFeature>(); | ||
| } | ||
|
|
||
| protected override async Task<int> Run() | ||
| { | ||
| try | ||
| { | ||
| var config = RuntimeConfigurationLoader.Load(_storagePath); | ||
| var output = _output.GetOutputFormat(config); | ||
| var connection = SeqConnectionFactory.Connect(_connection, config); | ||
|
|
||
| var result = await connection.Metrics.ListDimensionsAsync( | ||
| _count, | ||
| _metric, | ||
| rangeStartUtc: _range.Start, | ||
| rangeEndUtc: _range.End, | ||
| trace: _trace); | ||
|
|
||
| if (output.Json) | ||
| { | ||
| output.WriteObject(result); | ||
| } | ||
| else | ||
| { | ||
| foreach (var dimension in result) | ||
| { | ||
| output.WriteText(dimension.Accessor); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Error(ex, "Could not retrieve metrics: {ErrorMessage}", ex.Message); | ||
| return 1; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.