diff options
Diffstat (limited to 'internal/grpc/middleware/featureflag/featureflag_handler.go')
-rw-r--r-- | internal/grpc/middleware/featureflag/featureflag_handler.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/grpc/middleware/featureflag/featureflag_handler.go b/internal/grpc/middleware/featureflag/featureflag_handler.go new file mode 100644 index 000000000..1342b4d5f --- /dev/null +++ b/internal/grpc/middleware/featureflag/featureflag_handler.go @@ -0,0 +1,33 @@ +package featureflag + +import ( + "context" + "sort" + "strings" + + "github.com/sirupsen/logrus" + "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag" +) + +// FieldsProducer adds feature_flags logging fields to gRPC logs. Only enabled flags are available. +// The log field looks something like following. +// +// { +// "feature_flags": "feature_a feature_b feature_c" +// } +func FieldsProducer(ctx context.Context, err error) logrus.Fields { + var enabledFlags []string + for flag, value := range featureflag.FromContext(ctx) { + if value { + enabledFlags = append(enabledFlags, flag.Name) + } + } + if len(enabledFlags) == 0 { + return nil + } + + sort.Strings(enabledFlags) + return logrus.Fields{ + "feature_flags": strings.Join(enabledFlags, " "), + } +} |