Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Hints per container input #3416

Merged
merged 14 commits into from
Oct 6, 2023
Merged
32 changes: 32 additions & 0 deletions changelog/fragments/1694692246-hintspercontainer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: enhancement

# Change summary; a 80ish characters long description of the change.
summary: Hints Autodiscovery for Elastic Agent - Define configuration through annotations for specific containers inside a pod

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component:

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: https://github.com/owner/repo/1234
47 changes: 39 additions & 8 deletions internal/pkg/composable/providers/kubernetes/hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,48 @@ func GetHintsMapping(k8sMapping map[string]interface{}, logger *logp.Logger, pre
composableMapping: mapstr.M{},
processors: []mapstr.M{},
}
var hints mapstr.M
var containerProcessors []mapstr.M

if ann, ok := k8sMapping["annotations"]; ok {
annotations, _ := ann.(mapstr.M)
hints := utils.GenerateHints(annotations, "", prefix)
if len(hints) > 0 {
logger.Debugf("Extracted hints are :%v", hints)
hintData.composableMapping = GenerateHintsMapping(hints, k8sMapping, logger, cID)
logger.Debugf("Generated hints mappings are :%v", hintData.composableMapping)

hintData.processors = utils.GetConfigs(annotations, prefix, processorhints)
logger.Debugf("Generated Processors are :%v", hintData.processors)

if containerEntries, err := annotations.GetValue(prefix + ".hints"); err == nil {
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved
entries, _ := containerEntries.(mapstr.M)
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved
if len(entries) > 0 {
for key := range entries {
parts := strings.Split(key, "/")
if con, ok := k8sMapping["container"]; ok {
containers, _ := con.(mapstr.M)
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved
if cname, err := containers.GetValue("name"); err == nil {
if parts[0] == cname {
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved
// If there are hints like co.elastic.hints.<container_name>/ then add add the values after the / to the corresponding container
gizas marked this conversation as resolved.
Show resolved Hide resolved
hints = utils.GenerateHints(annotations, parts[0], prefix)
// Processors for specific container
// We need to make an extra check if we have processors added only to the specific containers
containerProcessors = utils.GetConfigs(annotations, prefix, "hints."+parts[0]+"/processors")

} else {
// If there are top level hints like co.elastic.hints/ then just add the values after the /
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved
hints = utils.GenerateHints(annotations, "", prefix)
}
if len(hints) > 0 {
logger.Debugf("Extracted hints are :%v", hints)
hintData.composableMapping = GenerateHintsMapping(hints, k8sMapping, logger, cID)
logger.Debugf("Generated hints mappings are :%v", hintData.composableMapping)

hintData.processors = utils.GetConfigs(annotations, prefix, processorhints)
// Only if there are processors defined in a specific container we append them to the processors of the pod
if len(containerProcessors) > 0 {
hintData.processors = append(hintData.processors, containerProcessors...)
}
logger.Debugf("Generated Processors are :%v", hintData.processors)
}
}
}
}
}

}

}
Expand Down