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

Introduce Commands and CommandHandler in the StreamingJobMaintenanceService #74

Merged
merged 5 commits into from
May 16, 2024

Conversation

s-vitaliy
Copy link
Contributor

@s-vitaliy s-vitaliy commented May 15, 2024

Part of #47

This Pull Request changes how the StreamingJobMaintenanceService handles Job update events. In previous versions of the code, the OnJobEvent method that handles Job events performed invocations of dependent services to run actions in response to Job events. This led to code maintainability problems: if handling an event requires any additional context, we need to chain tasks deeply in the event handler.

Now, this service only converts the job events into instances of the KubernetesCommand class, without requesting any context using asynchronous methods. The actual handling of these events is performed by implementations of the ICommandHandler interface that are injected into this service.

This PR is the first in series of pull requests related to event handlers refactoring.

Scope

Implemented:

  • The abstract class KubernetesCommand and it's implementations
  • Handlers for SetAnnotationCommand, StreamingJobCommand and UpdateStatusCommand

Additional changes:

  • Add the Deconstruct method for the IStreamDefinition interface for pattern matching.
  • Removed the OnJobAdded handler since we don't use it.

Checklist

  • GitHub issue exists for this change.
  • Unit tests added and they pass.
  • Line Coverage is at least 80%.
  • Review requested on latest commit.

Copy link

Coverage after merging job-command-handlers into main will be

65.36%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src/Configurations
   MetricsPublisherActorConfiguration.cs100%100%100%100%
   MetricsReporterConfiguration.cs100%100%100%100%
src/Extensions
   JsonElementExtensions.cs0%100%0%0%22, 30
   V1JobExtensions.cs85.58%75%90.91%90.16%39, 39, 44, 60–61, 61, 61, 61, 61–64, 82, 82
src/Models
   StreamingClassOperatorResponse.cs100%100%100%100%
src/Models/StreamClass
   V1Beta1StreamClassSpec.cs100%100%100%100%
src/Models/StreamDefinitions/Base
   IStreamDefinition.cs90%83.33%100%100%29
src/Models/StreamStatuses/StreamStatus/V1Beta1
   V1Beta1StreamStatus.cs100%100%100%100%
src/Services/CommandHandlers
   SetAnnotationCommandHandler.cs32.26%0%50%33.33%26–30, 30, 30–43
   StreamingJobCommandHandler.cs83.33%66.67%100%87.50%25, 29, 32, 35
   UpdateStatusCommandHandler.cs100%100%100%100%
src/Services/Commands
   StreamDefinitionCommands.cs80.95%100%77.78%83.33%51, 53
   StreamingJobCommands.cs100%100%100%100%
src/Services/Maintenance
   HostedStreamingJobMaintenanceService.cs0%0%0%0%16–24, 27–29, 29, 29–36, 39–42
   StreamingJobMaintenanceService.cs86.44%70%100%94.44%105, 108, 108–109, 109, 109, 109–110, 112, 116, 116, 116, 120–121, 74, 78
src/Services/Metrics
   DeclaredMetrics.cs88.24%60%100%100%32, 32, 32, 32
   MetricsReporter.cs100%100%100%100%
src/Services/Metrics/Actors
   MetricsPublisherActor.cs85.71%50%100%86.05%90–92, 92, 92–95
src/Services/Models
   CustomResourceApiRequest.cs100%100%100%100%
   ResourceEvent.cs100%100%100%100%
src/Services/Operator
   StreamClassOperatorService.cs74.23%50%77.78%77.63%106–109, 124–127, 82, 82, 82, 85, 87, 92–94, 94, 94–99
   StreamOperatorService.cs92.93%86.54%100%95.24%101–107, 112, 120, 134, 134, 140, 162
   StreamOperatorServiceWorker.cs77.78%50%75%80%46–50, 55, 63
   StreamOperatorServiceWorkerFactory.cs100%100%100%100%
src/Services/Repositories
   StreamClassRepository.cs80%0%75%85.29%35, 35, 35–39
   StreamDefinitionRepository.cs0%0%0%0%100, 104–111, 30–37, 40–42, 42, 42–57, 60–62, 62, 62–83, 86–88, 88, 88–99
   StreamingJobTemplateRepository.cs0%0%0%0%20–27, 31–33, 33, 33, 33, 33, 33, 33, 33, 33–36, 39–47
src/Services/Streams
   StreamingJobOperatorService.cs0%0%0%0%101–104, 104, 104–106, 109–112, 112, 112–114, 117–120, 123–132, 28–38, 41, 44–51, 55–61, 61, 61–81, 81, 81, 81, 81–84, 84, 84–98

Copy link

Coverage after merging job-command-handlers into main will be

65.53%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src/Configurations
   MetricsPublisherActorConfiguration.cs100%100%100%100%
   MetricsReporterConfiguration.cs100%100%100%100%
src/Extensions
   JsonElementExtensions.cs0%100%0%0%22, 30
   V1JobExtensions.cs85.58%75%90.91%90.16%39, 39, 44, 60–61, 61, 61, 61, 61–64, 82, 82
src/Models
   StreamingClassOperatorResponse.cs100%100%100%100%
src/Models/StreamClass
   V1Beta1StreamClassSpec.cs100%100%100%100%
src/Models/StreamDefinitions/Base
   IStreamDefinition.cs90%83.33%100%100%29
src/Models/StreamStatuses/StreamStatus/V1Beta1
   V1Beta1StreamStatus.cs100%100%100%100%
src/Services/CommandHandlers
   SetAnnotationCommandHandler.cs32.26%0%50%33.33%26–30, 30, 30–43
   StreamingJobCommandHandler.cs83.33%66.67%100%87.50%25, 29, 32, 35
   UpdateStatusCommandHandler.cs100%100%100%100%
src/Services/Commands
   StreamDefinitionCommands.cs80.95%100%77.78%83.33%51, 53
   StreamingJobCommands.cs100%100%100%100%
src/Services/Maintenance
   HostedStreamingJobMaintenanceService.cs0%0%0%0%16–24, 27–29, 29, 29–36, 39–42
   StreamingJobMaintenanceService.cs86.44%70%100%94.44%105, 108, 108–109, 109, 109, 109–110, 112, 116, 116, 116, 120–121, 74, 78
src/Services/Metrics
   DeclaredMetrics.cs88.24%60%100%100%32, 32, 32, 32
   MetricsReporter.cs100%100%100%100%
src/Services/Metrics/Actors
   MetricsPublisherActor.cs85.71%50%100%86.05%90–92, 92, 92–95
src/Services/Models
   CustomResourceApiRequest.cs100%100%100%100%
   ResourceEvent.cs100%100%100%100%
src/Services/Operator
   StreamClassOperatorService.cs80.22%58.33%87.50%83.10%114–117, 79, 79, 83, 88–90, 90, 90–95
   StreamOperatorService.cs87.62%77.59%100%91.30%116–122, 127, 135, 149, 149, 155, 177, 65–66, 66, 66, 66, 66, 66, 66–70
   StreamOperatorServiceWorker.cs77.78%50%75%80%46–50, 55, 63
   StreamOperatorServiceWorkerFactory.cs100%100%100%100%
src/Services/Repositories
   StreamClassRepository.cs80%0%75%85.29%35, 35, 35–39
   StreamDefinitionRepository.cs0%0%0%0%100, 104–111, 30–37, 40–42, 42, 42–57, 60–62, 62, 62–83, 86–88, 88, 88–99
   StreamingJobTemplateRepository.cs0%0%0%0%20–27, 31–33, 33, 33, 33, 33, 33, 33, 33, 33–36, 39–47
src/Services/Streams
   StreamingJobOperatorService.cs0%0%0%0%101–104, 104, 104–106, 109–112, 112, 112–114, 117–120, 123–132, 28–38, 41, 44–51, 55–61, 61, 61–81, 81, 81, 81, 81–84, 84, 84–98

@s-vitaliy s-vitaliy changed the title Add command handlers Introduce Commands and CommandHandler in the StreamingJobMaintenanceService May 15, 2024
@s-vitaliy s-vitaliy marked this pull request as ready for review May 15, 2024 13:52
@s-vitaliy s-vitaliy requested a review from a team as a code owner May 15, 2024 13:52
Copy link

Coverage after merging job-command-handlers into main will be

67.99%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src/Configurations
   MetricsPublisherActorConfiguration.cs100%100%100%100%
   MetricsReporterConfiguration.cs100%100%100%100%
src/Extensions
   JsonElementExtensions.cs0%100%0%0%22, 30
   V1JobExtensions.cs85.58%75%90.91%90.16%39, 39, 44, 60–61, 61, 61, 61, 61–64, 82, 82
src/Models
   StreamingClassOperatorResponse.cs100%100%100%100%
src/Models/StreamClass
   V1Beta1StreamClassSpec.cs100%100%100%100%
src/Models/StreamDefinitions/Base
   IStreamDefinition.cs90%83.33%100%100%29
src/Models/StreamStatuses/StreamStatus/V1Beta1
   V1Beta1StreamStatus.cs100%100%100%100%
src/Services/CommandHandlers
   SetAnnotationCommandHandler.cs87.10%50%100%88.89%30–33
   StreamingJobCommandHandler.cs83.33%66.67%100%87.50%25, 29, 32, 35
   UpdateStatusCommandHandler.cs100%100%100%100%
src/Services/Commands
   StreamDefinitionCommands.cs100%100%100%100%
   StreamingJobCommands.cs100%100%100%100%
src/Services/Maintenance
   HostedStreamingJobMaintenanceService.cs0%0%0%0%16–24, 27–29, 29, 29–36, 39–42
   StreamingJobMaintenanceService.cs89.34%75%100%96.05%105, 112, 112–113, 113, 113, 113–114, 116, 120, 125, 74, 78
src/Services/Metrics
   DeclaredMetrics.cs88.24%60%100%100%32, 32, 32, 32
   MetricsReporter.cs100%100%100%100%
src/Services/Metrics/Actors
   MetricsPublisherActor.cs85.71%50%100%86.05%90–92, 92, 92–95
src/Services/Models
   CustomResourceApiRequest.cs100%100%100%100%
   ResourceEvent.cs100%100%100%100%
src/Services/Operator
   StreamClassOperatorService.cs80.22%58.33%87.50%83.10%114–117, 79, 79, 83, 88–90, 90, 90–95
   StreamOperatorService.cs87.62%77.59%100%91.30%116–122, 127, 135, 149, 149, 155, 177, 65–66, 66, 66, 66, 66, 66, 66–70
   StreamOperatorServiceWorker.cs77.78%50%75%80%46–50, 55, 63
   StreamOperatorServiceWorkerFactory.cs100%100%100%100%
src/Services/Repositories
   StreamClassRepository.cs80%0%75%85.29%35, 35, 35–39
   StreamDefinitionRepository.cs0%0%0%0%100, 104–111, 30–37, 40–42, 42, 42–57, 60–62, 62, 62–83, 86–88, 88, 88–99
   StreamingJobTemplateRepository.cs0%0%0%0%20–27, 31–33, 33, 33, 33, 33, 33, 33, 33, 33–36, 39–47
src/Services/Streams
   StreamingJobOperatorService.cs0%0%0%0%101–104, 104, 104–106, 109–112, 112, 112–114, 117–120, 123–132, 28–38, 41, 44–51, 55–61, 61, 61–81, 81, 81, 81, 81–84, 84, 84–98

@s-vitaliy s-vitaliy merged commit 828fcb9 into main May 16, 2024
2 checks passed
@s-vitaliy s-vitaliy deleted the job-command-handlers branch May 16, 2024 08:26
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.

2 participants