-
Notifications
You must be signed in to change notification settings - Fork 25
seqcli index (list|suppress) and seqcli expressionindex (create|list|remove) commands
#337
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
63f414a
stubbed index commands
liammclennan 1b26754
Adding index commands
liammclennan 0e985ff
Complete index and expression index commands
liammclennan 494999a
Delete test
liammclennan 917cf12
PR feedback
liammclennan fed611a
Mark template export test case with min API version
nblumhardt e95cc7b
Version-gated end-to-end tests for new index-related commands
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "sdk": { | ||
| "version": "8.0.203" | ||
| "version": "8.0.204" | ||
| } | ||
| } |
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,70 @@ | ||
| // Copyright © Datalust Pty Ltd and Contributors | ||
| // | ||
| // 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.Threading.Tasks; | ||
| using Seq.Api.Model.Signals; | ||
| using SeqCli.Cli.Features; | ||
| using SeqCli.Config; | ||
| using SeqCli.Connection; | ||
| using SeqCli.Signals; | ||
| using SeqCli.Syntax; | ||
| using SeqCli.Util; | ||
| using Serilog; | ||
|
|
||
| namespace SeqCli.Cli.Commands.ExpressionIndex; | ||
|
|
||
| [Command("expressionindex", "create", "Create an expression index", | ||
| Example = "seqcli expressionindex create --expression \"ServerName\"")] | ||
| class CreateCommand : Command | ||
| { | ||
| readonly SeqConnectionFactory _connectionFactory; | ||
|
|
||
| readonly ConnectionFeature _connection; | ||
| readonly OutputFormatFeature _output; | ||
|
|
||
| string? _expression; | ||
|
|
||
| public CreateCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) | ||
| { | ||
| _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
|
||
| Options.Add( | ||
| "e=|expression=", | ||
| "The expression to index", | ||
| v => _expression = ArgumentString.Normalize(v)); | ||
|
|
||
| _connection = Enable<ConnectionFeature>(); | ||
| _output = Enable(new OutputFormatFeature(config.Output)); | ||
| } | ||
|
|
||
| protected override async Task<int> Run() | ||
| { | ||
| var connection = _connectionFactory.Connect(_connection); | ||
|
|
||
| if (string.IsNullOrEmpty(_expression)) | ||
| { | ||
| Log.Error("An `expression` must be specified"); | ||
| return 1; | ||
| } | ||
|
|
||
| var index = await connection.ExpressionIndexes.TemplateAsync(); | ||
| index.Expression = _expression; | ||
| index = await connection.ExpressionIndexes.AddAsync(index); | ||
|
|
||
| _output.WriteEntity(index); | ||
|
|
||
| return 0; | ||
| } | ||
| } |
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,41 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using SeqCli.Cli.Features; | ||
| using SeqCli.Config; | ||
| using SeqCli.Connection; | ||
|
|
||
| namespace SeqCli.Cli.Commands.ExpressionIndex; | ||
|
|
||
| [Command("expressionindex", "list", "List expression indexes", Example="seqcli expressionindex list")] | ||
| class ListCommand : Command | ||
| { | ||
| readonly SeqConnectionFactory _connectionFactory; | ||
|
|
||
| readonly ConnectionFeature _connection; | ||
| readonly OutputFormatFeature _output; | ||
| string? _id; | ||
|
|
||
| public ListCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) | ||
| { | ||
| if (config == null) throw new ArgumentNullException(nameof(config)); | ||
| _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
|
||
| Options.Add( | ||
| "i=|id=", | ||
| "The id of a single expression index to list", | ||
| id => _id = id); | ||
|
|
||
| _output = Enable(new OutputFormatFeature(config.Output)); | ||
| _connection = Enable<ConnectionFeature>(); | ||
| } | ||
|
|
||
| protected override async Task<int> Run() | ||
| { | ||
| var connection = _connectionFactory.Connect(_connection); | ||
| var list = _id is not null | ||
| ? [await connection.ExpressionIndexes.FindAsync(_id)] | ||
| : await connection.ExpressionIndexes.ListAsync(); | ||
| _output.ListEntities(list); | ||
| return 0; | ||
| } | ||
| } |
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,59 @@ | ||
| // Copyright 2018 Datalust Pty Ltd and Contributors | ||
| // | ||
| // 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.Linq; | ||
| using System.Threading.Tasks; | ||
| using SeqCli.Cli.Features; | ||
| using SeqCli.Connection; | ||
| using Serilog; | ||
|
|
||
| namespace SeqCli.Cli.Commands.ExpressionIndex; | ||
|
|
||
| [Command("expressionindex", "remove", "Remove an expression index from the server", | ||
| Example = "seqcli expressionindex -i expressionindex-2529")] | ||
| class RemoveCommand : Command | ||
| { | ||
| readonly SeqConnectionFactory _connectionFactory; | ||
|
|
||
| readonly ConnectionFeature _connection; | ||
| string? _id; | ||
|
|
||
| public RemoveCommand(SeqConnectionFactory connectionFactory) | ||
| { | ||
| _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
|
||
| Options.Add( | ||
| "i=|id=", | ||
| "The id of an expression index to remove", | ||
| id => _id = id); | ||
|
|
||
| _connection = Enable<ConnectionFeature>(); | ||
| } | ||
|
|
||
| protected override async Task<int> Run() | ||
| { | ||
| if (_id == null) | ||
| { | ||
| Log.Error("An `id` must be specified"); | ||
| return 1; | ||
| } | ||
|
|
||
| var connection = _connectionFactory.Connect(_connection); | ||
| var toRemove = await connection.ExpressionIndexes.FindAsync(_id); | ||
| await connection.ExpressionIndexes.RemoveAsync(toRemove); | ||
|
|
||
| return 0; | ||
| } | ||
| } |
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,61 @@ | ||
| // Copyright 2018 Datalust Pty Ltd and Contributors | ||
| // | ||
| // 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.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Seq.Api.Model.Indexes; | ||
| using SeqCli.Cli.Features; | ||
| using SeqCli.Config; | ||
| using SeqCli.Connection; | ||
|
|
||
| namespace SeqCli.Cli.Commands.Index; | ||
|
|
||
| [Command("index", "list", "List indexes", Example="seqcli index list")] | ||
| class ListCommand : Command | ||
| { | ||
| readonly SeqConnectionFactory _connectionFactory; | ||
|
|
||
| readonly ConnectionFeature _connection; | ||
| readonly OutputFormatFeature _output; | ||
| string? _id; | ||
|
|
||
| public ListCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) | ||
| { | ||
| if (config == null) throw new ArgumentNullException(nameof(config)); | ||
| _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
|
||
| Options.Add( | ||
| "i=|id=", | ||
| "The id of a single index to list", | ||
| id => _id = id); | ||
|
|
||
| _output = Enable(new OutputFormatFeature(config.Output)); | ||
| _connection = Enable<ConnectionFeature>(); | ||
| } | ||
|
|
||
| protected override async Task<int> Run() | ||
| { | ||
| var connection = _connectionFactory.Connect(_connection); | ||
|
|
||
| var list = _id is not null | ||
| ? [await connection.Indexes.FindAsync(_id)] | ||
| : await connection.Indexes.ListAsync(); | ||
|
|
||
| _output.ListEntities(list); | ||
|
|
||
| return 0; | ||
| } | ||
| } |
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,59 @@ | ||
| // Copyright 2018 Datalust Pty Ltd and Contributors | ||
| // | ||
| // 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.Threading.Tasks; | ||
| using Seq.Api.Model.Indexes; | ||
| using SeqCli.Cli.Features; | ||
| using SeqCli.Config; | ||
| using SeqCli.Connection; | ||
| using Serilog; | ||
|
|
||
| namespace SeqCli.Cli.Commands.Index; | ||
|
|
||
| [Command("index", "suppress", "Suppress an index", Example="seqcli index suppress -i index-2191448f1d9b4f22bd32c6edef752748")] | ||
| class SuppressCommand : Command | ||
| { | ||
| readonly SeqConnectionFactory _connectionFactory; | ||
| readonly ConnectionFeature _connection; | ||
| string? _id; | ||
|
|
||
| public SuppressCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) | ||
| { | ||
| if (config == null) throw new ArgumentNullException(nameof(config)); | ||
| _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
|
||
| Options.Add( | ||
| "i=|id=", | ||
| "The id of an index to suppress", | ||
| id => _id = id); | ||
|
|
||
| _connection = Enable<ConnectionFeature>(); | ||
| } | ||
|
|
||
| protected override async Task<int> Run() | ||
| { | ||
| if (_id == null) | ||
| { | ||
| Log.Error("An `id` must be specified"); | ||
| return 1; | ||
| } | ||
|
|
||
| var connection = _connectionFactory.Connect(_connection); | ||
| var toSuppress = await connection.Indexes.FindAsync(_id); | ||
| await connection.Indexes.SuppressAsync(toSuppress); | ||
|
|
||
| return 0; | ||
| } | ||
| } |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW checking for trailing
xand addingeswould work in most cases, matching theycase below?