Generalize distributor report path rendering

This commit is contained in:
2026-06-20 02:49:39 +00:00
parent fd48ebecb8
commit 8709b5f4d8
7 changed files with 128 additions and 37 deletions

View File

@@ -18,6 +18,7 @@ type DistributorTemplateValues struct {
ValidEndTime string
ValidStartStamp string
ValidEndStamp string
StormID string
BundleID string
}
@@ -41,6 +42,7 @@ var distributorTemplateVariables = map[string]struct{}{
"valid_end_time": {},
"valid_start_stamp": {},
"valid_end_stamp": {},
"storm_id": {},
}
var distributorIdempotencyTemplateVariables = map[string]struct{}{
@@ -55,6 +57,7 @@ var distributorIdempotencyTemplateVariables = map[string]struct{}{
"valid_end_time": {},
"valid_start_stamp": {},
"valid_end_stamp": {},
"storm_id": {},
"bundle_id": {},
}
@@ -129,23 +132,23 @@ func RenderDistributorBatchIdempotencyKey(template string, values DistributorBat
return rendered, nil
}
func RenderDistributorReportPaths(templates []string, values DistributorTemplateValues) ([]string, error) {
func RenderDistributorReportPaths(name string, templates []string, values DistributorTemplateValues) ([]string, error) {
if len(templates) == 0 {
return nil, fmt.Errorf("notify.distributor.report_path_templates must contain at least one entry")
return nil, fmt.Errorf("%s must contain at least one entry", name)
}
paths := make([]string, 0, len(templates))
seen := make(map[string]struct{}, len(templates))
for i, template := range templates {
name := fmt.Sprintf("notify.distributor.report_path_templates[%d]", i)
rendered, err := renderDistributorTemplate(name, template, values, distributorTemplateVariables)
itemName := fmt.Sprintf("%s[%d]", name, i)
rendered, err := renderDistributorTemplate(itemName, template, values, distributorTemplateVariables)
if err != nil {
return nil, err
}
if err := ValidateDistributorReportPath(name, rendered); err != nil {
if err := ValidateDistributorReportPath(itemName, rendered); err != nil {
return nil, err
}
if _, ok := seen[rendered]; ok {
return nil, fmt.Errorf("notify.distributor.report_path_templates renders duplicate path %q", rendered)
return nil, fmt.Errorf("%s renders duplicate path %q", name, rendered)
}
seen[rendered] = struct{}{}
paths = append(paths, rendered)
@@ -243,6 +246,8 @@ func distributorTemplateValue(variable string, values DistributorTemplateValues)
return values.ValidStartStamp
case "valid_end_stamp":
return values.ValidEndStamp
case "storm_id":
return values.StormID
case "bundle_id":
return values.BundleID
default: