Skip to content

Commit 7628efa

Browse files
chore: configurable event name trimming for reporting (#6394)
1 parent 9017582 commit 7628efa

File tree

2 files changed

+365
-2
lines changed

2 files changed

+365
-2
lines changed

enterprise/reporting/reporting.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ type DefaultReporter struct {
8282
eventSamplingDuration config.ValueLoader[time.Duration]
8383
eventSampler event_sampler.EventSampler
8484

85+
eventNameMaxLength config.ValueLoader[int]
86+
eventNamePrefixLength config.ValueLoader[int]
87+
eventNameSuffixLength config.ValueLoader[int]
88+
8589
useCommonClient config.ValueLoader[bool]
8690
commonClient *client.Client
8791
}
@@ -106,6 +110,9 @@ func NewDefaultReporter(ctx context.Context, conf *config.Config, log logger.Log
106110
eventSamplingDuration := conf.GetReloadableDurationVar(60, time.Minute, "Reporting.eventSampling.durationInMinutes")
107111
eventSamplerType := conf.GetReloadableStringVar("badger", "Reporting.eventSampling.type")
108112
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")
109116
// only send reports for wh actions sources if whActionsOnly is configured
110117
whActionsOnly := config.GetBool("REPORTING_WH_ACTIONS_ONLY", false)
111118
if whActionsOnly {
@@ -145,6 +152,9 @@ func NewDefaultReporter(ctx context.Context, conf *config.Config, log logger.Log
145152
eventSamplingEnabled: eventSamplingEnabled,
146153
eventSamplingDuration: eventSamplingDuration,
147154
eventSampler: eventSampler,
155+
eventNameMaxLength: eventNameMaxLength,
156+
eventNamePrefixLength: eventNamePrefixLength,
157+
eventNameSuffixLength: eventNameSuffixLength,
148158
useCommonClient: useCommonClient,
149159
commonClient: client.New(client.RouteMetrics, conf, log, stats),
150160
}
@@ -668,6 +678,15 @@ func (r *DefaultReporter) Report(ctx context.Context, metrics []*types.PUReporte
668678
return nil
669679
}
670680

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+
671690
stmt, err := txn.PrepareContext(ctx, pq.CopyIn(ReportsTable,
672691
"workspace_id", "namespace", "instance_id",
673692
"source_definition_id",
@@ -716,8 +735,8 @@ func (r *DefaultReporter) Report(ctx context.Context, metrics []*types.PUReporte
716735
}
717736

718737
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:]))
721740
}
722741

723742
_, err = stmt.Exec(

0 commit comments

Comments
 (0)