|
7 | 7 | package catalog |
8 | 8 |
|
9 | 9 | import ( |
10 | | - "regexp" |
11 | | - "strings" |
12 | | - |
13 | 10 | log "github.com/DataDog/datadog-agent/comp/core/log/def" |
14 | 11 | workloadfilter "github.com/DataDog/datadog-agent/comp/core/workloadfilter/def" |
15 | 12 | "github.com/DataDog/datadog-agent/comp/core/workloadfilter/program" |
16 | 13 | "github.com/DataDog/datadog-agent/pkg/util/containers" |
17 | 14 | ) |
18 | 15 |
|
19 | | -// LegacyContainerMetricsProgram creates a program for filtering container metrics |
20 | | -func LegacyContainerMetricsProgram(filterConfig *FilterConfig, logger log.Component) program.FilterProgram { |
21 | | - programName := "LegacyContainerMetricsProgram" |
22 | | - include := filterConfig.ContainerIncludeMetrics |
23 | | - exclude := filterConfig.ContainerExcludeMetrics |
24 | | - return createFromOldFilters(programName, include, exclude, workloadfilter.ContainerType, logger) |
25 | | -} |
26 | | - |
27 | | -// LegacyContainerLogsProgram creates a program for filtering container logs |
28 | | -func LegacyContainerLogsProgram(filterConfig *FilterConfig, logger log.Component) program.FilterProgram { |
29 | | - programName := "LegacyContainerLogsProgram" |
30 | | - include := filterConfig.ContainerIncludeLogs |
31 | | - exclude := filterConfig.ContainerExcludeLogs |
32 | | - return createFromOldFilters(programName, include, exclude, workloadfilter.ContainerType, logger) |
33 | | -} |
34 | | - |
35 | | -// LegacyContainerACExcludeProgram creates a program for excluding containers via legacy `AC` filters |
36 | | -func LegacyContainerACExcludeProgram(filterConfig *FilterConfig, logger log.Component) program.FilterProgram { |
37 | | - programName := "LegacyContainerACExcludeProgram" |
38 | | - exclude := filterConfig.ACExclude |
39 | | - return createFromOldFilters(programName, nil, exclude, workloadfilter.ContainerType, logger) |
40 | | -} |
41 | | - |
42 | | -// LegacyContainerACIncludeProgram creates a program for including containers via legacy `AC` filters |
43 | | -func LegacyContainerACIncludeProgram(filterConfig *FilterConfig, logger log.Component) program.FilterProgram { |
44 | | - programName := "LegacyContainerACIncludeProgram" |
45 | | - include := filterConfig.ACInclude |
46 | | - return createFromOldFilters(programName, include, nil, workloadfilter.ContainerType, logger) |
47 | | -} |
48 | | - |
49 | | -// LegacyContainerGlobalProgram creates a program for filtering container globally |
50 | | -func LegacyContainerGlobalProgram(filterConfig *FilterConfig, logger log.Component) program.FilterProgram { |
51 | | - programName := "LegacyContainerGlobalProgram" |
52 | | - include := filterConfig.ContainerInclude |
53 | | - exclude := filterConfig.ContainerExclude |
54 | | - return createFromOldFilters(programName, include, exclude, workloadfilter.ContainerType, logger) |
55 | | -} |
56 | | - |
57 | | -// LegacyContainerSBOMProgram creates a program for filtering container SBOMs |
58 | | -func LegacyContainerSBOMProgram(filterConfig *FilterConfig, logger log.Component) program.FilterProgram { |
59 | | - programName := "LegacyContainerSBOMProgram" |
60 | | - include := filterConfig.SBOMContainerInclude |
61 | | - exclude := filterConfig.SBOMContainerExclude |
62 | | - return createFromOldFilters(programName, include, exclude, workloadfilter.ContainerType, logger) |
63 | | -} |
64 | | - |
65 | 16 | // ContainerPausedProgram creates a program for filtering paused containers |
66 | 17 | func ContainerPausedProgram(_ *FilterConfig, logger log.Component) program.FilterProgram { |
67 | | - programName := "ContainerPausedProgram" |
68 | | - var initErrors []error |
69 | | - |
70 | | - exclude := containers.GetPauseContainerExcludeList() |
71 | | - |
72 | | - excludeRegex := make([]*regexp.Regexp, 0, len(exclude)) |
73 | | - for _, pattern := range exclude { |
74 | | - pattern = strings.TrimPrefix(pattern, "image:") |
75 | | - regex, err := regexp.Compile(pattern) |
76 | | - if err != nil { |
77 | | - initErrors = append(initErrors, err) |
78 | | - logger.Warnf("Error compiling regex pattern for %s: %v", programName, err) |
79 | | - continue |
80 | | - } |
81 | | - excludeRegex = append(excludeRegex, regex) |
82 | | - } |
83 | | - |
84 | | - return &program.RegexProgram{ |
85 | | - Name: programName, |
86 | | - ExcludeRegex: excludeRegex, |
87 | | - ExtractField: func(entity workloadfilter.Filterable) string { |
88 | | - container, ok := entity.(*workloadfilter.Container) |
89 | | - if !ok { |
90 | | - return "" |
91 | | - } |
92 | | - return container.GetImage() |
93 | | - }, |
94 | | - InitializationErrors: initErrors, |
95 | | - } |
| 18 | + return createLegacyContainerProgram("ContainerPausedProgram", nil, containers.GetPauseContainerExcludeList(), logger) |
96 | 19 | } |
97 | 20 |
|
98 | 21 | // ContainerCELMetricsProgram creates a program for filtering container metrics via CEL rules |
|
0 commit comments