Repository: clouditor/clouditor
Pull request #1165 (2023-07-11 13:29:45)

Added missing context in Orchestrator hook
Added missing context in Orchestrator hook

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/clouditor/clouditor/pull/1165?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) Report
> Merging [#1165](https://app.codecov.io/gh/clouditor/clouditor/pull/1165?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) (d18ecbd) into [main](https://app.codecov.io/gh/clouditor/clouditor/commit/e497a60d5f9f44e05435e995916ad91094ad6abf?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) (e497a60) will **decrease** coverage by `0.05%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head d18ecbd differs from pull request most recent head 9360e4b. Consider uploading reports for the commit 9360e4b to get more accurate results

```diff
@@            Coverage Diff             @@
##             main    #1165      +/-   ##
==========================================
- Coverage   83.73%   83.69%   -0.05%     
==========================================
  Files          93       93              
  Lines        8873     8873              
==========================================
- Hits         7430     7426       -4     
- Misses       1103     1106       +3     
- Partials      340      341       +1     
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `83.69% <100.00%> (-0.05%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://app.codecov.io/gh/clouditor/clouditor/pull/1165?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) | Coverage Δ | |
|---|---|---|
| [service/orchestrator/orchestrator.go](https://app.codecov.io/gh/clouditor/clouditor/pull/1165?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9vcmNoZXN0cmF0b3Ivb3JjaGVzdHJhdG9yLmdv) | `75.97% <ø> (ø)` | |
| [service/orchestrator/assessment\_results.go](https://app.codecov.io/gh/clouditor/clouditor/pull/1165?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9vcmNoZXN0cmF0b3IvYXNzZXNzbWVudF9yZXN1bHRzLmdv) | `91.62% <100.00%> (ø)` | |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/clouditor/clouditor/pull/1165/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)



Patch:
diff --git a/service/orchestrator/assessment_results.go b/service/orchestrator/assessment_results.go
index d0c021db..fc117bbe 100644
--- a/service/orchestrator/assessment_results.go
+++ b/service/orchestrator/assessment_results.go
@@ -188,7 +188,7 @@ func (svc *Service) StoreAssessmentResult(ctx context.Context, req *orchestrator
 		return nil, status.Errorf(codes.Internal, "database error: %v", err)
 	}
 
-	go svc.informHook(req.Result, nil)
+	go svc.informHook(ctx, req.Result, nil)
 
 	res = &orchestrator.StoreAssessmentResultResponse{}
 
@@ -249,20 +249,20 @@ func (s *Service) StoreAssessmentResults(stream orchestrator.Orchestrator_StoreA
 	}
 }
 
-func (s *Service) RegisterAssessmentResultHook(hook func(result *assessment.AssessmentResult, err error)) {
+func (s *Service) RegisterAssessmentResultHook(hook assessment.ResultHookFunc) {
 	s.hookMutex.Lock()
 	defer s.hookMutex.Unlock()
 	s.AssessmentResultHooks = append(s.AssessmentResultHooks, hook)
 }
 
-func (s *Service) informHook(result *assessment.AssessmentResult, err error) {
+func (s *Service) informHook(ctx context.Context, result *assessment.AssessmentResult, err error) {
 	s.mu.Lock()
 	defer s.mu.Unlock()
 	// Inform our hook, if we have any
 	if s.AssessmentResultHooks != nil {
 		for _, hook := range s.AssessmentResultHooks {
 			// TODO(all): We could do hook concurrent again (assuming different hooks don't interfere with each other)
-			hook(result, err)
+			hook(ctx, result, err)
 		}
 	}
 }
diff --git a/service/orchestrator/orchestrator.go b/service/orchestrator/orchestrator.go
index e70433fb..a5e3eaf3 100644
--- a/service/orchestrator/orchestrator.go
+++ b/service/orchestrator/orchestrator.go
@@ -66,7 +66,7 @@ type Service struct {
 	hookMutex sync.RWMutex
 
 	// Hook
-	AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+	AssessmentResultHooks []assessment.ResultHookFunc
 	// mu is used for (un)locking result hook calls
 	mu sync.Mutex
 


Test patch:
diff --git a/service/assessment/benchmark_test.go b/service/assessment/benchmark_test.go
index ecd270fc..ff59528a 100644
--- a/service/assessment/benchmark_test.go
+++ b/service/assessment/benchmark_test.go
@@ -63,7 +63,7 @@ func createEvidences(n int, m int, b *testing.B) int {
 
 	svc := NewService(WithOrchestratorAddress(addr), WithEvidenceStoreAddress(addr))
 
-	orchestratorService.RegisterAssessmentResultHook(func(result *assessment.AssessmentResult, err error) {
+	orchestratorService.RegisterAssessmentResultHook(func(ctx context.Context, result *assessment.AssessmentResult, err error) {
 		wg.Done()
 		current := atomic.AddInt64(&count, 1)
 		log.Debugf("Current count: %v", current)
diff --git a/service/orchestrator/assessment_results_test.go b/service/orchestrator/assessment_results_test.go
index db18a882..cf7e9dbf 100644
--- a/service/orchestrator/assessment_results_test.go
+++ b/service/orchestrator/assessment_results_test.go
@@ -600,14 +600,14 @@ func TestAssessmentResultHook(t *testing.T) {
 	)
 	wg.Add(2)
 
-	firstHookFunction := func(assessmentResult *assessment.AssessmentResult, err error) {
+	firstHookFunction := func(ctx context.Context, assessmentResult *assessment.AssessmentResult, err error) {
 		hookCallCounter++
 		log.Println("Hello from inside the firstHookFunction")
 
 		wg.Done()
 	}
 
-	secondHookFunction := func(assessmentResult *assessment.AssessmentResult, err error) {
+	secondHookFunction := func(ctx context.Context, assessmentResult *assessment.AssessmentResult, err error) {
 		hookCallCounter++
 		log.Println("Hello from inside the secondHookFunction")
 
diff --git a/service/orchestrator/catalogs_test.go b/service/orchestrator/catalogs_test.go
index 9d4a8a5a..1df89345 100644
--- a/service/orchestrator/catalogs_test.go
+++ b/service/orchestrator/catalogs_test.go
@@ -329,7 +329,7 @@ func TestService_RemoveCatalog(t *testing.T) {
 func TestService_GetCategory(t *testing.T) {
 	type fields struct {
 		cloudServiceHooks     []orchestrator.CloudServiceHookFunc
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)
@@ -426,7 +426,7 @@ func TestService_GetCategory(t *testing.T) {
 func TestService_GetControl(t *testing.T) {
 	type fields struct {
 		cloudServiceHooks     []orchestrator.CloudServiceHookFunc
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)
@@ -556,7 +556,7 @@ func TestService_ListControls(t *testing.T) {
 
 func TestService_loadCatalogs(t *testing.T) {
 	type fields struct {
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)
diff --git a/service/orchestrator/cloud_service_test.go b/service/orchestrator/cloud_service_test.go
index 4bc60fa7..f7a431d0 100644
--- a/service/orchestrator/cloud_service_test.go
+++ b/service/orchestrator/cloud_service_test.go
@@ -383,7 +383,7 @@ func TestService_CreateDefaultTargetCloudService(t *testing.T) {
 
 func TestService_ListCloudServices(t *testing.T) {
 	type fields struct {
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)
@@ -531,7 +531,7 @@ func TestService_GetCloudServiceStatistics(t *testing.T) {
 	type fields struct {
 		cloudServiceHooks     []orchestrator.CloudServiceHookFunc
 		toeHooks              []orchestrator.TargetOfEvaluationHookFunc
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)
diff --git a/service/orchestrator/metrics_test.go b/service/orchestrator/metrics_test.go
index e1b86b58..d3fff69d 100644
--- a/service/orchestrator/metrics_test.go
+++ b/service/orchestrator/metrics_test.go
@@ -80,7 +80,7 @@ var (
 
 func TestService_loadMetrics(t *testing.T) {
 	type fields struct {
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)
@@ -629,7 +629,7 @@ func TestService_ListMetrics(t *testing.T) {
 	type fields struct {
 		cloudServiceHooks     []orchestrator.CloudServiceHookFunc
 		toeHooks              []orchestrator.TargetOfEvaluationHookFunc
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)
@@ -701,7 +701,7 @@ func TestService_ListMetrics(t *testing.T) {
 
 func TestService_GetMetricImplementation(t *testing.T) {
 	type fields struct {
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		events                chan *orchestrator.MetricChangeEvent
@@ -798,7 +798,7 @@ func TestService_GetMetricImplementation(t *testing.T) {
 
 func TestService_UpdateMetricImplementation(t *testing.T) {
 	type fields struct {
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		catalogsFolder        string
@@ -929,7 +929,7 @@ func TestService_UpdateMetricImplementation(t *testing.T) {
 
 func TestService_GetMetricConfiguration(t *testing.T) {
 	type fields struct {
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		catalogsFolder        string
@@ -1075,7 +1075,7 @@ func TestService_GetMetricConfiguration(t *testing.T) {
 
 func TestService_ListMetricConfigurations(t *testing.T) {
 	type fields struct {
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		catalogsFolder        string
@@ -1183,7 +1183,7 @@ func TestService_ListMetricConfigurations(t *testing.T) {
 
 func TestService_UpdateMetricConfiguration(t *testing.T) {
 	type fields struct {
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)
diff --git a/service/orchestrator/toe_test.go b/service/orchestrator/toe_test.go
index c1686c57..935d2ec6 100644
--- a/service/orchestrator/toe_test.go
+++ b/service/orchestrator/toe_test.go
@@ -55,7 +55,7 @@ func TestService_CreateTargetOfEvaluation(t *testing.T) {
 
 	type fields struct {
 		cloudServiceHooks     []orchestrator.CloudServiceHookFunc
-		AssessmentResultHooks []func(result *assessment.AssessmentResult, err error)
+		AssessmentResultHooks []assessment.ResultHookFunc
 		storage               persistence.Storage
 		metricsFile           string
 		loadMetricsFunc       func() ([]*assessment.Metric, error)