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

Implement update commands for commonly-used entities #345

Merged
merged 3 commits into from
May 3, 2024

Conversation

nblumhardt
Copy link
Member

@nblumhardt nblumhardt commented May 3, 2024

Also fixes #346.

Automating with a shell and seqcli is great, except when an existing entity needs to be edited. So far no commands support any kind of update or edit, because there's so much variation between entities and complexity in specifying properties.

This PR proposes an immediate blanket solution, using the JSON format to round-trip edits.

seqcli signal update [<args>]

Update an existing signal

Example:
  seqcli signal update --json '{...}'

Arguments:
      --json=VALUE           The updated signal in JSON format; this can be
                               produced using `seqcli signal list --json`
      --json-stdin           Read the updated signal as JSON from `STDIN`
  -s, --server=VALUE         The URL of the Seq server; by default the `
                               connection.serverUrl` config value will be used
  -a, --apikey=VALUE         The API key to use when connecting to the server;
                               by default the `connection.apiKey` config
                               value will be used
      --profile=VALUE        A connection profile to use; by default the `
                               connection.serverUrl` and `connection.apiKey`
                               config values will be used
      --verbose              Print verbose output to `STDERR`

This works well with modern shells, e.g. PowerShell (edited for clarity):

PS > $warnings = (seqcli signal list -i signal-m33302 --json | ConvertFrom-Json)

PS > $warnings.Title                                                                                                                
Warnings

PS > $warnings.Title = "Freak-outs"

PS > (echo $warnings | ConvertTo-Json) | seqcli signal update --json-stdin        

PS > seqcli signal list -i signal-m33302 --json                                 
{"Title": "Freak-outs", "Description": "Automatically created", "Filters": [{"Description": null, "DescriptionIsExcluded": false, "Filter": "@Level in ['w', 'wa', 'war', 'wrn', 'warn', 'warning'] ci", "FilterNonStrict": null}], "Columns": [], "IsProtected": false, "IsIndexSuppressed": true, "Grouping": "Explicit", "ExplicitGroupName": "@Level", "OwnerId": null, "Id": "signal-m33302"}

Future type-specific extensions to update might provide alternative ways of setting properties.

@@ -77,7 +77,7 @@ static class TemplateSetImporter
var resourceGroup = await connection.Client.GetAsync<ResourceGroup>(apiRoot, link.Key);

// ExpressionIndexes with mapped ids or identical expressions are assumed to be equivalent.
var immutableTarget = template.ResourceGroup != "ExpressionIndexes";
var immutableTarget = template.ResourceGroup == "ExpressionIndexes";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this bug breaks template import in the latest version


namespace SeqCli.EndToEnd.Support;

public class TestConfiguration(Args args)
{
static int ServerListenPort => 9989;
static int _nextServerPort = 9989;
readonly int _serverListenPort = Interlocked.Increment(ref _nextServerPort);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are to support running each test case against a new, unique server instance. Previously, a failure in one test could leave the server in an unsuitable state for later tests, making it difficult to see which test actually failed.

@@ -77,7 +77,7 @@ static class TemplateSetImporter
var resourceGroup = await connection.Client.GetAsync<ResourceGroup>(apiRoot, link.Key);

// ExpressionIndexes with mapped ids or identical expressions are assumed to be equivalent.
var immutableTarget = template.ResourceGroup != "ExpressionIndexes";
var immutableTarget = template.ResourceGroup.Equals("ExpressionIndexes", StringComparison.OrdinalIgnoreCase);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you flipped the bool here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; yes, that one's the fix 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the condition "worked" because it failed to take different casings of "ExpressionIndexes" into account, and so happened to return the correct value for that case.

@nblumhardt nblumhardt merged commit 3f16c7d into datalust:dev May 3, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

seqcli template import does not update existing entities in 2024.3.867
2 participants