From 184d738466d1f318df2ec543cdc97e05c0225fcd Mon Sep 17 00:00:00 2001 From: Matheus Nogueira Date: Tue, 5 Sep 2023 19:00:34 -0300 Subject: [PATCH] fix: check if target is localhost in executor --- server/executor/trigger_executer_worker.go | 9 +++++---- server/executor/trigger_result_processor_worker.go | 2 +- server/test/trigger/trigger.go | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/executor/trigger_executer_worker.go b/server/executor/trigger_executer_worker.go index 84d0f9e739..9bb0313bc8 100644 --- a/server/executor/trigger_executer_worker.go +++ b/server/executor/trigger_executer_worker.go @@ -75,6 +75,7 @@ func (r triggerExecuterWorker) ProcessItem(ctx context.Context, job Job) { response.Result.Error = &trigger.TriggerError{ ConnectionError: isConnectionError(err), RunningOnContainer: isServerRunningInsideContainer(), + TargetsLocalhost: isTargetLocalhost(job.Test.Trigger), ErrorMessage: err.Error(), } } @@ -121,13 +122,13 @@ func isConnectionError(err error) bool { return false } -func isTargetLocalhost(job Job) bool { +func isTargetLocalhost(t trigger.Trigger) bool { var endpoint string - switch job.Test.Trigger.Type { + switch t.Type { case trigger.TriggerTypeHTTP: - endpoint = job.Test.Trigger.HTTP.URL + endpoint = t.HTTP.URL case trigger.TriggerTypeGRPC: - endpoint = job.Test.Trigger.GRPC.Address + endpoint = t.GRPC.Address } url, err := url.Parse(endpoint) diff --git a/server/executor/trigger_result_processor_worker.go b/server/executor/trigger_result_processor_worker.go index e4b67b6995..28882037ce 100644 --- a/server/executor/trigger_result_processor_worker.go +++ b/server/executor/trigger_result_processor_worker.go @@ -62,7 +62,7 @@ func (r triggerResultProcessorWorker) ProcessItem(ctx context.Context, job Job) if triggerResult.Error.ConnectionError { r.emitUnreachableEndpointEvent(ctx, job, err) - if isTargetLocalhost(job) && triggerResult.Error.RunningOnContainer { + if triggerResult.Error.TargetsLocalhost && triggerResult.Error.RunningOnContainer { r.emitMismatchEndpointEvent(ctx, job, err) } } diff --git a/server/test/trigger/trigger.go b/server/test/trigger/trigger.go index 0809ae629a..025834cbea 100644 --- a/server/test/trigger/trigger.go +++ b/server/test/trigger/trigger.go @@ -25,6 +25,7 @@ type ( TriggerError struct { ConnectionError bool `json:"connectionError"` RunningOnContainer bool `json:"runningOnContainer"` + TargetsLocalhost bool `json:"targetsLocalhost"` ErrorMessage string `json:"message"` } )