Bläddra i källkod

add ignorable error code that does not save to db (#3962)

Co-authored-by: Porter Support <93286801+portersupport@users.noreply.github.com>
Feroze Mohideen 2 år sedan
förälder
incheckning
6b1d60a75e

+ 5 - 0
internal/porter_app/notifications/notification.go

@@ -80,6 +80,11 @@ func HandleNotification(ctx context.Context, inp HandleNotificationInput) error
 	// 5. hydrate notification with a Porter error containing user-facing details
 	hydratedNotification = hydrateNotificationWithError(ctx, hydratedNotification)
 
+	// if we can ignore this error, then we don't need to save it
+	if hydratedNotification.Error.Code == porter_error.PorterErrorCode_Ignorable {
+		return nil
+	}
+
 	// 6. based on notification + k8s deployment, update the status of the matching deploy event
 	if hydratedNotification.Deployment.Status == DeploymentStatus_Failure ||
 		(hydratedNotification.Deployment.Status == DeploymentStatus_Pending &&

+ 6 - 2
internal/porter_app/notifications/porter_error/codes.go

@@ -25,6 +25,8 @@ type PorterErrorCode int
 const (
 	// PorterErrorCode_Unknown is the default error code
 	PorterErrorCode_Unknown PorterErrorCode = 0
+	// PorterErrorCode_Ignorable is the error code for an ignorable error
+	PorterErrorCode_Ignorable PorterErrorCode = 1
 	// PorterErrorCode_NonZeroExitCode is the error code for a generic non-zero exit code
 	PorterErrorCode_NonZeroExitCode PorterErrorCode = 10
 	// PorterErrorCode_NonZeroExitCode_SIGKILL is the error code for a non-zero exit code due to a SIGKILL
@@ -81,16 +83,18 @@ func ErrorCode(agentSummary, agentDetail string) PorterErrorCode {
 		return PorterErrorCode_MemoryLimitExceeded
 	}
 
+	// this is often a false alarm. if it is actually blocking deploy, we will get a PorterErrorCode_MemoryLimitExceeded_ScaleUp
 	if strings.Contains(agentSummary, "requested more memory than is available") {
-		return PorterErrorCode_MemoryLimitExceeded
+		return PorterErrorCode_Ignorable
 	}
 
 	if strings.Contains(agentSummary, "requesting too much memory and cannot scale up") {
 		return PorterErrorCode_MemoryLimitExceeded_ScaleUp
 	}
 
+	// this is often a false alarm. if it is actually blocking deploy, we will get a PorterErrorCode_CPULimitExceeded_ScaleUp
 	if strings.Contains(agentSummary, "requesting more cpu than is available") {
-		return PorterErrorCode_CPULimitExceeded
+		return PorterErrorCode_Ignorable
 	}
 
 	if strings.Contains(agentSummary, "requesting too much cpu and cannot scale up") {

+ 10 - 5
internal/porter_app/notifications/translate.go

@@ -38,6 +38,12 @@ func createError(ctx context.Context, errorCode porter_error.PorterErrorCode, ag
 	ctx, span := telemetry.NewSpan(ctx, "create-error")
 	defer span.End()
 
+	telemetry.WithAttributes(span,
+		telemetry.AttributeKV{Key: "agent-summary", Value: agentSummary},
+		telemetry.AttributeKV{Key: "agent-detail", Value: agentDetail},
+		telemetry.AttributeKV{Key: "error-code", Value: int(errorCode)},
+	)
+
 	porterError := porter_error.PorterError{
 		Code:            errorCode,
 		Summary:         translateAgentSummary(agentSummary, serviceName),
@@ -46,11 +52,10 @@ func createError(ctx context.Context, errorCode porter_error.PorterErrorCode, ag
 		Documentation:   []string{},
 	}
 
-	telemetry.WithAttributes(span,
-		telemetry.AttributeKV{Key: "agent-summary", Value: agentSummary},
-		telemetry.AttributeKV{Key: "agent-detail", Value: agentDetail},
-		telemetry.AttributeKV{Key: "error-code", Value: int(errorCode)},
-	)
+	// if we can ignore the error, there is nothing to hydrate
+	if errorCode == porter_error.PorterErrorCode_Ignorable {
+		return porterError
+	}
 
 	errorDetailsProvider, ok := porter_error.ErrorCodeToProvider[errorCode]
 	if ok {