Add per-report distributor path overrides

This commit is contained in:
2026-06-20 02:46:05 +00:00
parent 021e5dd8b1
commit fd48ebecb8
4 changed files with 377 additions and 14 deletions

View File

@@ -17,6 +17,10 @@ func (cfg Config) ReportModuleOverrides() (map[report.ID][]module.ConfigItem, er
})
}
func (cfg Config) ReportDistributorPathOverrides() (map[report.ID][]string, error) {
return traverseReportDistributorPathOverrides(cfg)
}
func normalizeReportModules(cfg *Config) error {
if cfg.Reports == nil {
cfg.Reports = map[string]ReportConfig{}
@@ -35,6 +39,11 @@ func validateReportModules(cfg Config) error {
return err
}
func validateReportDistributorPathOverrides(cfg Config) error {
_, err := traverseReportDistributorPathOverrides(cfg)
return err
}
type reportModuleTraversalOptions struct {
normalizeOptions bool
updateConfig bool
@@ -82,6 +91,76 @@ func traverseReportModules(cfg *Config, opts reportModuleTraversalOptions) (map[
return overrides, nil
}
func traverseReportDistributorPathOverrides(cfg Config) (map[report.ID][]string, error) {
overrides := map[report.ID][]string{}
if cfg.Reports == nil {
return overrides, nil
}
reportRegistry := report.DefaultRegistry()
seenReports := map[report.ID]string{}
for key, reportCfg := range cfg.Reports {
reportID, err := report.IDForConfigKey(key)
if err != nil {
return nil, fmt.Errorf("reports.%s: %w", key, err)
}
if previous, ok := seenReports[reportID]; ok {
return nil, fmt.Errorf("reports.%s duplicates report override %q", key, previous)
}
seenReports[reportID] = key
if _, err := reportRegistry.Lookup(reportID); err != nil {
return nil, fmt.Errorf("reports.%s: %w", key, err)
}
if !reportCfg.Distributor.pathTemplatesSet {
continue
}
if err := validateReportDistributorPathTemplates(key, reportCfg.Distributor.PathTemplates); err != nil {
return nil, err
}
overrides[reportID] = append([]string(nil), reportCfg.Distributor.PathTemplates...)
}
return overrides, nil
}
func validateReportDistributorPathTemplates(reportKey string, templates []string) error {
name := fmt.Sprintf("reports.%s.distributor.path_templates", reportKey)
if len(templates) == 0 {
return fmt.Errorf("%s must contain at least one entry", name)
}
values := sampleDistributorTemplateValues()
seen := map[string]struct{}{}
for i, template := range templates {
itemName := fmt.Sprintf("%s[%d]", name, i)
rendered, err := renderDistributorTemplate(itemName, template, values, distributorTemplateVariables)
if err != nil {
return err
}
if err := ValidateDistributorReportPath(itemName, rendered); err != nil {
return err
}
if _, ok := seen[rendered]; ok {
return fmt.Errorf("%s renders duplicate path %q", name, rendered)
}
seen[rendered] = struct{}{}
}
return nil
}
func sampleDistributorTemplateValues() DistributorTemplateValues {
return DistributorTemplateValues{
LocationID: "location",
ReportID: "report",
RunID: "run",
ArtifactGroup: "artifact",
BatchOutputName: "report.md",
ValidStartDate: "2026-05-29",
ValidEndDate: "2026-05-30",
ValidStartTime: "0000",
ValidEndTime: "0000",
ValidStartStamp: "2026-05-29T0000",
ValidEndStamp: "2026-05-30T0000",
}
}
func moduleItemsFromConfig(registry briefing.ModuleRegistry, reportKey string, items []ModuleConfigItem, normalizeOptions bool) ([]module.ConfigItem, []ModuleConfigItem, error) {
out := make([]module.ConfigItem, 0, len(items))
normalizedItems := append([]ModuleConfigItem(nil), items...)