diff --git a/util/argo/audit_logger.go b/util/argo/audit_logger.go index 104b0dcd6143e..1645e8d7d65d8 100644 --- a/util/argo/audit_logger.go +++ b/util/argo/audit_logger.go @@ -2,7 +2,6 @@ package argo import ( "context" - "encoding/json" "fmt" "time" @@ -46,7 +45,7 @@ const ( EventReasonOperationCompleted = "OperationCompleted" ) -func (l *AuditLogger) logEvent(objMeta ObjectRef, gvk schema.GroupVersionKind, info EventInfo, message string, logFields map[string]interface{}) { +func (l *AuditLogger) logEvent(objMeta ObjectRef, gvk schema.GroupVersionKind, info EventInfo, message string, logFields map[string]string) { logCtx := log.WithFields(log.Fields{ "type": info.Type, "reason": info.Reason, @@ -54,19 +53,6 @@ func (l *AuditLogger) logEvent(objMeta ObjectRef, gvk schema.GroupVersionKind, i for field, val := range logFields { logCtx = logCtx.WithField(field, val) } - logFieldStrings := make(map[string]string) - for field, val := range logFields { - if valStr, ok := val.(string); ok { - logFieldStrings[field] = valStr - continue - } - vJsonStr, err := json.Marshal(val) - if err != nil { - logCtx.Errorf("Unable to marshal audit event field %v: %v", field, err) - continue - } - logFieldStrings[field] = string(vJsonStr) - } switch gvk.Kind { case application.ApplicationKind: @@ -80,7 +66,7 @@ func (l *AuditLogger) logEvent(objMeta ObjectRef, gvk schema.GroupVersionKind, i event := v1.Event{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%v.%x", objMeta.Name, t.UnixNano()), - Annotations: logFieldStrings, + Annotations: logFields, }, Source: v1.EventSource{ Component: l.component, @@ -115,14 +101,13 @@ func (l *AuditLogger) LogAppEvent(app *v1alpha1.Application, info EventInfo, mes ResourceVersion: app.ObjectMeta.ResourceVersion, UID: app.ObjectMeta.UID, } - fields := map[string]interface{}{ + fields := map[string]string{ "dest-server": app.Spec.Destination.Server, "dest-namespace": app.Spec.Destination.Namespace, } if user != "" { fields["user"] = user } - fields["spec"] = app.Spec l.logEvent(objectMeta, v1alpha1.ApplicationSchemaGroupVersionKind, info, message, fields) } @@ -133,7 +118,7 @@ func (l *AuditLogger) LogAppSetEvent(app *v1alpha1.ApplicationSet, info EventInf ResourceVersion: app.ObjectMeta.ResourceVersion, UID: app.ObjectMeta.UID, } - fields := make(map[string]interface{}) + fields := map[string]string{} if user != "" { fields["user"] = user } @@ -147,7 +132,7 @@ func (l *AuditLogger) LogResourceEvent(res *v1alpha1.ResourceNode, info EventInf ResourceVersion: res.ResourceRef.Version, UID: types.UID(res.ResourceRef.UID), } - fields := make(map[string]interface{}) + fields := map[string]string{} if user != "" { fields["user"] = user }