Skip to content

Commit

Permalink
Revert "feat(server): log app Spec along with event (argoproj#16416)" (
Browse files Browse the repository at this point in the history
…argoproj#18458)

This reverts commit 820f4d8.

Signed-off-by: jannfis <[email protected]>
  • Loading branch information
jannfis authored May 30, 2024
1 parent 1450f10 commit ef37b39
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions util/argo/audit_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package argo

import (
"context"
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -46,27 +45,14 @@ 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,
})
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:
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit ef37b39

Please sign in to comment.