@@ -82,6 +82,10 @@ type DefaultReporter struct {
82
82
eventSamplingDuration config.ValueLoader [time.Duration ]
83
83
eventSampler event_sampler.EventSampler
84
84
85
+ eventNameMaxLength config.ValueLoader [int ]
86
+ eventNamePrefixLength config.ValueLoader [int ]
87
+ eventNameSuffixLength config.ValueLoader [int ]
88
+
85
89
useCommonClient config.ValueLoader [bool ]
86
90
commonClient * client.Client
87
91
}
@@ -106,6 +110,9 @@ func NewDefaultReporter(ctx context.Context, conf *config.Config, log logger.Log
106
110
eventSamplingDuration := conf .GetReloadableDurationVar (60 , time .Minute , "Reporting.eventSampling.durationInMinutes" )
107
111
eventSamplerType := conf .GetReloadableStringVar ("badger" , "Reporting.eventSampling.type" )
108
112
eventSamplingCardinality := conf .GetReloadableIntVar (100000 , 1 , "Reporting.eventSampling.cardinality" )
113
+ eventNameMaxLength := conf .GetReloadableIntVar (50 , 1 , "Reporting.eventNameTrimming.maxLength" )
114
+ eventNamePrefixLength := conf .GetReloadableIntVar (40 , 1 , "Reporting.eventNameTrimming.prefixLength" )
115
+ eventNameSuffixLength := conf .GetReloadableIntVar (10 , 1 , "Reporting.eventNameTrimming.suffixLength" )
109
116
// only send reports for wh actions sources if whActionsOnly is configured
110
117
whActionsOnly := config .GetBool ("REPORTING_WH_ACTIONS_ONLY" , false )
111
118
if whActionsOnly {
@@ -145,6 +152,9 @@ func NewDefaultReporter(ctx context.Context, conf *config.Config, log logger.Log
145
152
eventSamplingEnabled : eventSamplingEnabled ,
146
153
eventSamplingDuration : eventSamplingDuration ,
147
154
eventSampler : eventSampler ,
155
+ eventNameMaxLength : eventNameMaxLength ,
156
+ eventNamePrefixLength : eventNamePrefixLength ,
157
+ eventNameSuffixLength : eventNameSuffixLength ,
148
158
useCommonClient : useCommonClient ,
149
159
commonClient : client .New (client .RouteMetrics , conf , log , stats ),
150
160
}
@@ -668,6 +678,15 @@ func (r *DefaultReporter) Report(ctx context.Context, metrics []*types.PUReporte
668
678
return nil
669
679
}
670
680
681
+ maxLength := r .eventNameMaxLength .Load ()
682
+ prefixLength := r .eventNamePrefixLength .Load ()
683
+ suffixLength := r .eventNameSuffixLength .Load ()
684
+ if prefixLength <= 0 || suffixLength <= 0 || prefixLength >= maxLength || suffixLength >= maxLength || prefixLength + suffixLength != maxLength {
685
+ err := fmt .Errorf ("invalid event name trimming configuration: prefixLength=%d, suffixLength=%d, maxLength=%d. prefixLength and suffixLength must be > 0, prefixLength < maxLength, suffixLength < maxLength, and prefixLength + suffixLength = maxLength" , prefixLength , suffixLength , maxLength )
686
+ r .log .Errorn (`[ Reporting ]: Invalid event name trimming configuration` , obskit .Error (err ))
687
+ return err
688
+ }
689
+
671
690
stmt , err := txn .PrepareContext (ctx , pq .CopyIn (ReportsTable ,
672
691
"workspace_id" , "namespace" , "instance_id" ,
673
692
"source_definition_id" ,
@@ -716,8 +735,8 @@ func (r *DefaultReporter) Report(ctx context.Context, metrics []*types.PUReporte
716
735
}
717
736
718
737
runeEventName := []rune (metric .StatusDetail .EventName )
719
- if len (runeEventName ) > 50 {
720
- metric .StatusDetail .EventName = fmt .Sprintf ("%s...%s" , string (runeEventName [:40 ]), string (runeEventName [len (runeEventName )- 10 :]))
738
+ if len (runeEventName ) > maxLength {
739
+ metric .StatusDetail .EventName = fmt .Sprintf ("%s...%s" , string (runeEventName [:prefixLength ]), string (runeEventName [len (runeEventName )- suffixLength :]))
721
740
}
722
741
723
742
_ , err = stmt .Exec (
0 commit comments