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

Merry: Projections Management with CLI #627

Merged
merged 42 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c1c6aeb
Create prerelease with new contracts
jakhog Feb 10, 2022
5d7e59e
Expose the definitions of IProjections
jakhog Feb 10, 2022
d6694dd
Introduce IProjections to keep track of all Projection processors.
jakhog Feb 10, 2022
3ddd19d
Start moving responsibility for running Projections into the Projecti…
jakhog Feb 10, 2022
24d0fa5
Implement the resetting when definitions have changed.
jakhog Feb 10, 2022
e30e69d
Get Projection status from Projections
jakhog Feb 10, 2022
352f77e
Implement Start and Dispose, it should work as before now.
jakhog Feb 10, 2022
12c42b8
Fix last logger messages
jakhog Feb 10, 2022
1d48f0e
Expose gRPC reflections service on all endpoints
jakhog Feb 11, 2022
914934b
Add Alias to Projections
jakhog Feb 11, 2022
e822806
Expose the Projections Management service
jakhog Feb 11, 2022
5ce4dab
It should be OK for the Runtime to have a higher major than the head
jakhog Feb 11, 2022
d0f4330
Move conversion of Projection definition fields to own class so it ca…
jakhog Feb 11, 2022
d7d6134
Move conversion of stream processor state so it can be reused for pro…
jakhog Feb 11, 2022
586521c
Implement replaying of projections by passing along an action to perf…
jakhog Feb 11, 2022
d6b891a
Make the specs run again.
jakhog Feb 11, 2022
9970388
Verify that action is actually performed. And cleanup unused usings
jakhog Feb 11, 2022
0f6874b
Make sure we dont reprocess events if resetting action fails
jakhog Feb 11, 2022
e80b7c6
Merge pull request #631 from dolittle/keep-track-of-projections
jakhog Feb 12, 2022
42f318c
Merge remote-tracking branch 'origin/master' into merge-keyselectors
jakhog Feb 12, 2022
86a7f88
Add some missing docs
jakhog Feb 12, 2022
e9c6bde
Add more logs
jakhog Feb 12, 2022
68fa14f
Introduce a TaskGroup that implements the pattern of waiting for mult…
jakhog Feb 12, 2022
a99e9c4
Specs for TaskGroup
jakhog Feb 12, 2022
fb33847
Use TaskGroup where it fits
jakhog Feb 12, 2022
10df33b
Merge pull request #632 from dolittle/merge-keyselectors
jakhog Feb 12, 2022
f563db8
Handle exceptions nicely in Projections managment service.
jakhog Feb 12, 2022
f2385ee
Docs
jakhog Feb 12, 2022
9f33f41
Log messages
jakhog Feb 12, 2022
f8a7336
Implement EventHandlers GetOne method
jakhog Feb 12, 2022
0f82ffd
Fix some codacy issues.
jakhog Feb 12, 2022
5a9e3d8
Merge pull request #633 from dolittle/exceptions-and-logs
jakhog Feb 12, 2022
2af6f59
Implement "projections list"
jakhog Feb 12, 2022
51b2fa7
Use GetOne for EventHandlers
jakhog Feb 12, 2022
661ae10
Implement Get
jakhog Feb 13, 2022
5734554
Implement Replay
jakhog Feb 13, 2022
21e7e04
Merge pull request #634 from dolittle/cli
jakhog Feb 13, 2022
363150c
Update Documentation with new CLI commands
jakhog Feb 13, 2022
dc8b1a7
Add the M1 contrib package to the CLI
jakhog Feb 14, 2022
cb4810a
Merge pull request #635 from dolittle/cli-arm-grpc
jakhog Feb 14, 2022
86f02ca
Update Source/Events.Processing.Management/Projections/Log.cs
jakhog Feb 14, 2022
f7b8302
Upgrade to released Contracts
jakhog Feb 14, 2022
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 .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Release

env:
PRERELEASE_BRANCHES: pippin # Comma separated list of prerelease branch names. 'alpha,rc, ...'
PRERELEASE_BRANCHES: merry, pippin

on:
pull_request:
Expand Down
10 changes: 5 additions & 5 deletions Documentation/CLI/Runtime/EventHandlers/get.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Get
description: Gets details of a specific Event Handler currently registered a Client to the Runtime
description: Gets details of a specific Event Handler currently registered by Clients to the Runtime
weight: 20
repository: https://github.com/dolittle/Runtime
---
Expand All @@ -11,15 +11,15 @@ dolittle runtime eventhandlers get <identifier> [options]

### Arguments

| Argument | Description |
|----------|---------------------------------------------------------|
| `<identifier>` | The identifier of the Event Handler to get details for. Format: id/alias[:scope] |
| Argument | Description |
|----------------|----------------------------------------------------------------------------------|
| `<identifier>` | The identifier of the Event Handler to get details for. Format: id/alias[:scope] |

### Options

| Option | Description |
|-------------------------|----------------------------------------------------------------------------------------------------------|
| `--tenant <id>` | Only show Event Handler information for the specified Tenant. |
| `--tenant <id>` | Only show Stream Processor status for the specified Tenant. |
| `--runtime host[:port]` | The address to the management endpoint of a Runtime. See [details]({{< ref "../../Runtime#details" >}}). |
| `--output table\|json` | Select the format the output of the subcommand. Defaults to table. |
| `--wide` | If set, prints more details in table format for a wider output. |
Expand Down
16 changes: 8 additions & 8 deletions Documentation/CLI/Runtime/EventHandlers/replay.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Replay
description: Initiates reprocessing of events for a specific Event Handler currently registered a Client to the Runtime
description: Initiates reprocessing of events for a specific Event Handler currently registered by Clients to the Runtime
weight: 30
repository: https://github.com/dolittle/Runtime
---
Expand All @@ -16,9 +16,9 @@ dolittle runtime eventhandlers replay all <identifier> [options]

### Arguments

| Argument | Description |
|----------|---------------------------------------------------------|
| `<identifier>` | The identifier of the Event Handler to replay. Format: id/alias[:scope] |
| Argument | Description |
|----------------|-------------------------------------------------------------------------|
| `<identifier>` | The identifier of the Event Handler to replay. Format: id/alias[:scope] |

### Options

Expand All @@ -39,10 +39,10 @@ dolittle runtime eventhandlers replay from <identifier> <position> [options]

### Arguments

| Argument | Description |
|--------------|---------------------------------------------------------------------------------------------------------------------------|
| `<identifier>` | The identifier of the Event Handler to replay. Format: id/alias[:scope] |
| `<position>` | The position _in the Event Handler stream_ to star reprocessing events from. Cannot be greater than the current position. |
| Argument | Description |
|----------------|---------------------------------------------------------------------------------------------------------------------------|
| `<identifier>` | The identifier of the Event Handler to replay. Format: id/alias[:scope] |
| `<position>` | The position _in the Event Handler stream_ to star reprocessing events from. Cannot be greater than the current position. |

### Options

Expand Down
21 changes: 21 additions & 0 deletions Documentation/CLI/Runtime/Projections/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: Projections
description: Commands related to management of Projections
weight: 10
repository: https://github.com/dolittle/Runtime
---

```shell
dolittle runtime projections [subcommand]
```

### Options

| Option | Description |
|-------------------------|----------------------------------------------------------------------------------------------------------|
| `--runtime host[:port]` | The address to the management endpoint of a Runtime. See [details]({{< ref "../../Runtime#details" >}}). |
| `--output table\|json` | Select the format the output of the subcommand. Defaults to table. |
| `--wide` | If set, prints more details in table format for a wider output. |
| `--help` | Show help information. |

### Subcommands
27 changes: 27 additions & 0 deletions Documentation/CLI/Runtime/Projections/get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Get
description: Gets details of a specific Projection currently registered by Clients to the Runtime
weight: 20
repository: https://github.com/dolittle/Runtime
---

```shell
dolittle runtime projection get <identifier> <scope> [options]
```

### Arguments

| Argument | Description |
|----------------|-------------------------------------------------------------------------------------------------------------------------|
| `<identifier>` | The identifier or alias of the Projection to get details for |
| `<scope>` | The scope of the Projection to get details for. Only required when the identifier or alias matches multiple projections |

### Options

| Option | Description |
|-------------------------|----------------------------------------------------------------------------------------------------------|
| `--tenant <id>` | Only show Stream Processor status for the specified Tenant. |
| `--runtime host[:port]` | The address to the management endpoint of a Runtime. See [details]({{< ref "../../Runtime#details" >}}). |
| `--output table\|json` | Select the format the output of the subcommand. Defaults to table. |
| `--wide` | If set, prints more details in table format for a wider output. |
| `--help` | Show help information. |
20 changes: 20 additions & 0 deletions Documentation/CLI/Runtime/Projections/list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: List
description: Lists all the Projections currently registered by Clients to the Runtime
weight: 10
repository: https://github.com/dolittle/Runtime
---

```shell
dolittle runtime projections list [options]
```

### Options

| Option | Description |
|-------------------------|----------------------------------------------------------------------------------------------------------|
| `--tenant <id>` | Only show Stream Processor status for the specified Tenant. |
| `--runtime host[:port]` | The address to the management endpoint of a Runtime. See [details]({{< ref "../../Runtime#details" >}}). |
| `--output table\|json` | Select the format the output of the subcommand. Defaults to table. |
| `--wide` | If set, prints more details in table format for a wider output. |
| `--help` | Show help information. |
27 changes: 27 additions & 0 deletions Documentation/CLI/Runtime/Projections/replay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Replay
description: Initiates a replay of a Projection currently registered by Clients to the Runtime
weight: 30
repository: https://github.com/dolittle/Runtime
---

Initiates a replay of all events to rebuild Projection read models. This command drops all persisted read models, and potential copies in MongoDB, and restarts the Projection to build new ones.

```shell
dolittle runtime projection replay <identifier> <scope> [options]
```

### Arguments

| Argument | Description |
|----------------|----------------------------------------------------------------------------------------------------------------|
| `<identifier>` | The identifier or alias of the Projection to replay |
| `<scope>` | The scope of the Projection to replay. Only required when the identifier or alias matches multiple projections |

### Options

| Option | Description |
|-------------------------|----------------------------------------------------------------------------------------------------------|
| `--tenant <id>` | Only replay the Projection for the specified Tenant. If not provided, replays for all Tenants |
| `--runtime host[:port]` | The address to the management endpoint of a Runtime. See [details]({{< ref "../../Runtime#details" >}}). |
| `--help` | Show help information. |
3 changes: 3 additions & 0 deletions Documentation/CLI/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ This section helps you learn about how to use the Dolittle CLI tool. If you're n
| `dolittle runtime eventhandlers get` | Get details about a running Event Handler | [Details]({{< ref "Runtime/EventHandlers/get" >}}) |
| `dolittle runtime eventhandlers replay` | Replay events for a running Event Handler | [Details]({{< ref "Runtime/EventHandlers/replay" >}}) |
| `dolittle runtime eventtypes list` | List all registered Event Types | [Details]({{< ref "Runtime/EventTypes/list" >}}) |
| `dolittle runtime projections list` | List all running Projections | [Details]({{< ref "Runtime/Projections/list" >}}) |
| `dolittle runtime projections get` | Get details about a running Projection | [Details]({{< ref "Runtime/Projections/get" >}}) |
| `dolittle runtime projections replay` | Replay a running Projection | [Details]({{< ref "Runtime/Projections/replay" >}}) |

## How to install

Expand Down
1 change: 1 addition & 0 deletions Source/CLI/CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<ItemGroup>
<PackageReference Include="ConsoleTables" Version="$(ConsoleTablesVersion)" />
<PackageReference Include="Contrib.Grpc.Core.M1" Version="$(GrpcVersion)" />
<PackageReference Include="Docker.DotNet" Version="$(DockerDotNetVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsVersion)" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="$(McMasterVersion)" />
Expand Down
5 changes: 3 additions & 2 deletions Source/CLI/Runtime/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ namespace Dolittle.Runtime.CLI.Runtime;
/// The "dolittle runtime" command.
/// </summary>
[Command("runtime", Description = "Manage a Runtime")]
[Subcommand(typeof(EventHandlers.Command))]
[Subcommand(typeof(Aggregates.Command))]
[Subcommand(typeof(EventHandlers.Command))]
[Subcommand(typeof(EventTypes.Command))]
[Subcommand(typeof(Projections.Command))]
public class Command : CommandBase
{
/// <summary>
Expand All @@ -32,4 +33,4 @@ public Command(ICanLocateRuntimes runtimes, IDiscoverEventTypes eventTypesDiscov
/// <param name="cli">The <see cref="CommandLineApplication"/> that is executed.</param>
public void OnExecute(CommandLineApplication cli)
=> cli.ShowHelp();
}
}
3 changes: 2 additions & 1 deletion Source/CLI/Runtime/EventHandlers/EventHandlerStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using Dolittle.Runtime.Artifacts;
using Dolittle.Runtime.CLI.Runtime.Events.Processing;
using Dolittle.Runtime.Events.Processing.EventHandlers;
using Dolittle.Runtime.Events.Store;

Expand Down Expand Up @@ -32,4 +33,4 @@ public record EventHandlerStatus(
/// Gets a value indicating whether the Event Handler is in the default Scope.
/// </summary>
public bool IsInDefaultScope => Id.Scope.Equals(ScopeId.Default);
}
}
39 changes: 13 additions & 26 deletions Source/CLI/Runtime/EventHandlers/Get/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Dolittle.Runtime.ApplicationModel;
using Dolittle.Runtime.CLI.Options;
using Dolittle.Runtime.CLI.Runtime.Events.Processing;
using Dolittle.Runtime.CLI.Runtime.EventTypes;
using Dolittle.Runtime.Serialization.Json;
using McMaster.Extensions.CommandLineUtils;
Expand Down Expand Up @@ -42,14 +43,14 @@ public Command(ICanLocateRuntimes runtimes, IManagementClient client, IResolveEv
TenantId Tenant { get; init; }

/// <summary>
/// The Event Handler identifier argument used to provide the unique identifier of the Event Handler to replay.
/// The Event Handler identifier argument used to provide the unique identifier of the Event Handler to get.
/// </summary>
[Required]
[Argument(0, Description = "The Event Handler identifier of the Event Handler to get details for")]
EventHandlerIdOrAlias EventHandlerIdentifier { get; init; }

/// <summary>
/// The entrypoint for the "dolittle runtime eventhandlers list" command.
/// The entrypoint for the "dolittle runtime eventhandlers get" command.
/// </summary>
/// <param name="cli">The <see cref="CommandLineApplication"/> that is executed.</param>
public async Task OnExecuteAsync(CommandLineApplication cli)
Expand Down Expand Up @@ -83,30 +84,16 @@ Task WriteTableOutput(CommandLineApplication cli, EventHandlerStatus status)
=> Wide
? WriteDetailedOutput(cli, status)
: WriteSimpleOutput(cli, status);

async Task WriteSimpleOutput(CommandLineApplication cli, EventHandlerStatus status)
{
if (status.Partitioned)
{
await WriteOutput(cli, status.States.Cast<PartitionedTenantScopedStreamProcessorStatus>().Select(CreateSimpleStateView)).ConfigureAwait(false);
}
else
{
await WriteOutput(cli, status.States.Cast<UnpartitionedTenantScopedStreamProcessorStatus>().Select(CreateSimpleStateView)).ConfigureAwait(false);
}
}

async Task WriteDetailedOutput(CommandLineApplication cli, EventHandlerStatus status)
{
if (status.Partitioned)
{
await WriteOutput(cli, MergePartitionedStates(status)).ConfigureAwait(false);
}
else
{
await WriteOutput(cli, status.States.Cast<UnpartitionedTenantScopedStreamProcessorStatus>().Select(CreateDetailedStateView)).ConfigureAwait(false);
}
}
Task WriteSimpleOutput(CommandLineApplication cli, EventHandlerStatus status)
=> status.Partitioned
? WriteOutput(cli, status.States.Cast<PartitionedTenantScopedStreamProcessorStatus>().Select(CreateSimpleStateView))
: WriteOutput(cli, status.States.Cast<UnpartitionedTenantScopedStreamProcessorStatus>().Select(CreateSimpleStateView));

Task WriteDetailedOutput(CommandLineApplication cli, EventHandlerStatus status)
=> status.Partitioned
? WriteOutput(cli, MergePartitionedStates(status))
: WriteOutput(cli, status.States.Cast<UnpartitionedTenantScopedStreamProcessorStatus>().Select(CreateDetailedStateView));

static IEnumerable<PartitionedEventHandlerDetailedView> MergePartitionedStates(EventHandlerStatus status)
{
Expand Down Expand Up @@ -150,4 +137,4 @@ static PartitionedEventHandlerDetailedView CreateDetailedStateView(PartitionedTe
failingPartition?.FailureReason,
failingPartition?.RetryTime ?? default,
failingPartition?.ProcessingAttempts ?? 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace Dolittle.Runtime.CLI.Runtime.EventHandlers.Get;

/// <summary>
/// Represents a simple view of an Event Handler state.
/// Represents a simple view of an Event Handler Stream Processor state.
/// </summary>
/// <param name="Tenant">The Tenant.</param>
/// <param name="Position">The stream position-</param>
/// <param name="Position">The stream position.</param>
/// <param name="Status">The status.</param>
public record EventHandlerSimpleView(Guid Tenant, ulong Position, string Status);
public record EventHandlerSimpleView(Guid Tenant, ulong Position, string Status);
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Dolittle.Runtime.CLI.Runtime.EventHandlers.Get;

/// <summary>
/// Represents a detailed view of a partitioned Event Handler state.
/// Represents a detailed view of a partitioned Event Handler Stream Processor state.
/// </summary>
/// <param name="Tenant">The Tenant.</param>
/// <param name="Position">The stream position-</param>
/// <param name="Position">The stream position.</param>
/// <param name="Status">The status.</param>
/// <param name="LastSuccessfulOrFailedProcessing">When the last event was successfully processed or failed processing.</param>
/// <param name="Partition">The Partition identifier.</param>
Expand All @@ -24,4 +24,4 @@ public record PartitionedEventHandlerDetailedView(
string Partition,
string FailureReason,
DateTimeOffset RetryTime,
uint ProcessingAttempts);
uint ProcessingAttempts);
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Dolittle.Runtime.CLI.Runtime.EventHandlers.Get;

/// <summary>
/// Represents a detailed view of an unpartitioned Event Handler state.
/// Represents a detailed view of an unpartitioned Event Handler Stream Processor state.
/// </summary>
/// <param name="Tenant">The Tenant.</param>
/// <param name="Position">The stream position-</param>
/// <param name="Position">The stream position.</param>
/// <param name="Status">The status.</param>
/// <param name="FailureReason">The reason for failure.</param>
/// <param name="RetryTime">The retry time.</param>
Expand All @@ -22,4 +22,4 @@ public record UnpartitionedEventHandlerDetailedView(
string FailureReason,
DateTimeOffset RetryTime,
uint ProcessingAttempts,
DateTimeOffset LastSuccessfullyProcessed);
DateTimeOffset LastSuccessfullyProcessed);
23 changes: 23 additions & 0 deletions Source/CLI/Runtime/EventHandlers/GetOneEventHandlerFailed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using Dolittle.Runtime.Events.Processing.EventHandlers;

namespace Dolittle.Runtime.CLI.Runtime.EventHandlers;

/// <summary>
/// Exception that gets thrown when getting one Event Handler fails.
/// </summary>
public class GetOneEventHandlerFailed : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="GetOneEventHandlerFailed"/> class.
/// </summary>
/// <param name="eventHandler">The Event Handler that getting one failed for.</param>
/// <param name="reason">The reason why getting one Event Handler failed.</param>
public GetOneEventHandlerFailed(EventHandlerId eventHandler, string reason)
: base($"Could not get event handler {eventHandler.EventHandler} in scope {eventHandler.Scope} because {reason}")
{
}
}
Loading