Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "8.0.203"
"version": "8.0.204"
}
}
70 changes: 70 additions & 0 deletions src/SeqCli/Cli/Commands/ExpressionIndex/CreateCommand.cs
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;
}
}
41 changes: 41 additions & 0 deletions src/SeqCli/Cli/Commands/ExpressionIndex/ListCommand.cs
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;
}
}
59 changes: 59 additions & 0 deletions src/SeqCli/Cli/Commands/ExpressionIndex/RemoveCommand.cs
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;
}
}
61 changes: 61 additions & 0 deletions src/SeqCli/Cli/Commands/Index/ListCommand.cs
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;
}
}
59 changes: 59 additions & 0 deletions src/SeqCli/Cli/Commands/Index/SuppressCommand.cs
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;
}
}
2 changes: 1 addition & 1 deletion src/SeqCli/SeqCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="newtonsoft.json" Version="13.0.3" />
<PackageReference Include="Seq.Api" Version="2024.3.0-dev-00239" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
Expand All @@ -38,7 +39,6 @@
<PackageReference Include="Superpower" Version="3.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
<PackageReference Include="Seq.Api" Version="2024.2.0" />
<PackageReference Include="Seq.Apps" Version="2023.4.0" />
<PackageReference Include="Seq.Syntax" Version="1.0.0" />
<PackageReference Include="Tavis.UriTemplates" Version="2.0.0" />
Expand Down
13 changes: 10 additions & 3 deletions src/SeqCli/Templates/Export/EntityName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ public static string FromEntityType(Type entityType)

public static string ToResourceGroup(string resource)
{
if (!resource.EndsWith("y"))
return resource + "s";
if (resource.EndsWith('y'))
{
return resource.TrimEnd('y') + "ies";
}
Copy link
Member

Choose a reason for hiding this comment

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

FWIW checking for trailing x and adding es would work in most cases, matching the y case below?


return resource.TrimEnd('y') + "ies";
if (resource.EndsWith('x'))
{
return resource + "es";
}

return resource + "s";
}
}
11 changes: 10 additions & 1 deletion src/SeqCli/Templates/Export/TemplateSetExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Seq.Api.Model;
using Seq.Api.Model.Alerting;
using Seq.Api.Model.Dashboarding;
using Seq.Api.Model.Indexing;
using Seq.Api.Model.Retention;
using Seq.Api.Model.Signals;
using Seq.Api.Model.SqlQueries;
Expand Down Expand Up @@ -78,8 +79,16 @@ await ExportTemplates<RetentionPolicyEntity>(
() => _connection.RetentionPolicies.ListAsync(),
retentionPolicy => retentionPolicy.Id.Replace("retentionpolicy-", ""),
templateValueMap);
}

await ExportTemplates<ExpressionIndexEntity>(
id => _connection.ExpressionIndexes.FindAsync(id),
() => _connection.ExpressionIndexes.ListAsync(),
expressionIndex => expressionIndex.Expression.All(char.IsLetterOrDigit)
? expressionIndex.Expression
: expressionIndex.Id.Replace("expressionindex-", ""),
templateValueMap);
}

async Task ExportTemplates<TEntity>(
Func<string, Task<TEntity>> findEntity,
Func<Task<List<TEntity>>> listEntities,
Expand Down
2 changes: 1 addition & 1 deletion src/SeqCli/Templates/Import/TemplateSetImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static class TemplateSetImporter
bool merge)
{
var ordering = new[] {"users", "signals", "apps", "appinstances",
"dashboards", "sqlqueries", "workspaces", "retentionpolicies", "alerts"}.ToList();
"dashboards", "sqlqueries", "workspaces", "retentionpolicies", "alerts", "expressionindexes"}.ToList();

var sorted = templates.OrderBy(t => ordering.IndexOf(t.ResourceGroup));

Expand Down
Loading