Skip to content

Commit 8d50f1d

Browse files
authored
[helm/elastic-agent] upgrade helm chart to collect rotated logs (#11129)
Updates the elastic-agent helm chart to allow the collection of rotated logs, including the GZIP-compressed logs. AI tools were used to generate the deploy/helm/elastic-agent/CONTRIBUTING.md
1 parent a54754b commit 8d50f1d

File tree

12 files changed

+534
-25
lines changed

12 files changed

+534
-25
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: feature
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: "BETA: upgrade helm chart to collect rotated logs"
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; a word indicating the component this changeset affects.
22+
component: helm-chart
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/elastic-agent/pull/11129
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
issue: https://github.com/elastic/elastic-agent/issues/10889
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<!--
2+
(NOTE: AI was used on this file)
3+
-->
4+
5+
# Contributing to Elastic Agent Helm Chart
6+
7+
This is an **INCOMPLETE** set of tips and explanations for developers who want
8+
to modify or contribute to the Elastic Agent Helm chart.
9+
10+
## Testing Your Changes Locally
11+
12+
By default, the agent is installed on the `kube-system` namespace. Thus you'll
13+
need to pass `-n kube-system` to the `helm` invocations that interact with the
14+
k8s cluster.
15+
16+
### Rendering the Chart
17+
18+
Use `helm template` to render the chart and verify the output without actually
19+
installing it:
20+
21+
```bash
22+
# Using a values file
23+
helm template elastic-agent . -f values.yaml
24+
25+
# Or setting values directly
26+
helm template elastic-agent . --set kubernetes.enabled=true --set outputs.default.type=ESPlainAuthAPI
27+
```
28+
29+
This works just like `helm install` but only generates the Kubernetes manifests
30+
without applying them to the cluster.
31+
32+
### Testing with Different Examples
33+
34+
Test your changes against the example configurations in the `examples/` directory:
35+
36+
```bash
37+
helm template elastic-agent . -f examples/kubernetes-default/agent-kubernetes-values.yaml
38+
```
39+
40+
### Applying Changes to an Existing Deployment
41+
42+
If you have already installed the chart and want to test modifications, use
43+
`helm upgrade`:
44+
45+
```bash
46+
# Using a values file
47+
helm upgrade elastic-agent . -f your-values.yaml
48+
49+
# Or using --set to override specific values
50+
helm upgrade elastic-agent . --set agent.version=9.3.0
51+
52+
# Combine both approaches
53+
helm upgrade elastic-agent . -f your-values.yaml --set kubernetes.enabled=false
54+
```
55+
56+
## Editing the README
57+
58+
The README.md was originally generated using [helm-docs](https://github.com/norwoodj/helm-docs).
59+
However, it has diverged from the auto-generated version since.
60+
`helm-docs` is still usefull to can pick up changes to the `values.yaml` and
61+
format them as the others. However, running it will completely override the
62+
README.md.
63+
You might use `helm-docs` to render the changes you made to `values.yaml`. Then,
64+
find you changes, copy it, restore the README.md and manually add your changes.
65+
66+
67+
### Adding New Values Documentation
68+
69+
When you add new values to `values.yaml`, make sure to:
70+
1. Add appropriate comments above the value (helm-docs uses these)
71+
2. Update the schema in `values.schema.json` accordingly
72+
73+
Example format in `values.yaml`:
74+
```yaml
75+
# -- Enable the new feature
76+
# @section -- 6 - Elastic-Agent Configuration
77+
newFeature:
78+
# -- Enable/disable the feature
79+
enabled: false
80+
# -- Configuration for the feature
81+
config: {}
82+
```
83+
84+
85+
## Useful Commands Reference
86+
87+
```bash
88+
# Install chart in a cluster with values file
89+
helm install elastic-agent . -f values.yaml -n kube-system
90+
91+
# Install chart with --set flags
92+
helm install elastic-agent . --set outputs.default.type=ESPlainAuthAPI --set outputs.default.api_key=your_key -n kube-system
93+
94+
# Combine values file and --set (--set takes precedence)
95+
helm install elastic-agent . -f values.yaml --set agent.version=9.3.0 -n kube-system
96+
97+
# Upgrade existing installation
98+
helm upgrade elastic-agent . -f values.yaml -n kube-system
99+
100+
# Dry-run to see what would change
101+
helm upgrade elastic-agent . -f values.yaml -n kube-system --dry-run --debug
102+
103+
# Uninstall
104+
helm uninstall elastic-agent -n kube-system
105+
```

deploy/helm/elastic-agent/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
<!--
2-
(NOTE: Do not edit README.md directly. It is a generated file!)
3-
( To make changes, please modify README.md.gotmpl and run `helm-docs`)
4-
-->
5-
61
# elastic-agent
72

83
![Version: 9.1.0-beta](https://img.shields.io/badge/Version-9.1.0--beta-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 9.1.0](https://img.shields.io/badge/AppVersion-9.1.0-informational?style=flat-square)
@@ -87,6 +82,7 @@ The chart built-in [kubernetes integration](https://docs.elastic.co/integrations
8782
| kubernetes.containers.state.enabled | bool | `true` | enable containers state stream (kube-state-metrics) [ref](https://www.elastic.co/guide/en/beats/metricbeat/8.11/metricbeat-metricset-kubernetes-state_container.html) |
8883
| kubernetes.containers.state.vars | object | `{}` | containers state stream vars |
8984
| kubernetes.containers.logs.enabled | bool | `true` | enable containers logs stream [ref](https://www.elastic.co/docs/current/integrations/kubernetes/container-logs) |
85+
| kubernetes.containers.logs.rotated_logs | bool | `false` | BETA: enable rotated logs ingestion. WARNING: enabling it might cause date re-ingestion on existing deployments. [ref](https://www.elastic.co/docs/reference/integrations/kubernetes/container-logs#ingesting-rotated-container-logs) |
9086
| kubernetes.containers.logs.vars | object | `{}` | containers logs stream vars |
9187
| kubernetes.containers.audit_logs.enabled | bool | `false` | enable containers audit logs stream [ref](https://www.elastic.co/docs/current/integrations/kubernetes/audit-logs) |
9288
| kubernetes.pods.metrics.enabled | bool | `true` | enable pods metric stream (kubelet) [ref](https://www.elastic.co/docs/current/integrations/kubernetes/kubelet#pod) |

deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_logs_containers.tpl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ Config input for container logs
1717
namespace: {{ .Values.kubernetes.namespace }}
1818
use_output: {{ .Values.kubernetes.output }}
1919
streams:
20+
{{- if $.Values.kubernetes.containers.logs.rotated_logs }}
21+
- id: kubernetes-container-logs-${kubernetes.pod.uid}-${kubernetes.container.name}
22+
gzip_experimental: true
23+
paths:
24+
- '/var/log/pods/${kubernetes.namespace}_${kubernetes.pod.name}_${kubernetes.pod.uid}/${kubernetes.container.name}/*.log*'
25+
{{ else }}
2026
- id: kubernetes-container-logs-${kubernetes.pod.name}-${kubernetes.container.id}
27+
paths:
28+
- '/var/log/containers/*${kubernetes.container.id}.log'
29+
{{ end }}
2130
data_stream:
2231
dataset: kubernetes.container_logs
2332
type: logs
24-
paths:
25-
- '/var/log/containers/*${kubernetes.container.id}.log'
2633
prospector.scanner.symlinks: {{ dig "vars" "symlinks" true .Values.kubernetes.containers.logs }}
2734
parsers:
2835
- container:

deploy/helm/elastic-agent/values.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@
229229
"type": "boolean",
230230
"description": "Enable containers logs stream."
231231
},
232+
"rotated_logs": {
233+
"type": "boolean",
234+
"description": "BETA: enable rotated logs ingestion. WARNING: enabling it might cause date re-ingestion on existing deployments. [ref](https://www.elastic.co/docs/reference/integrations/kubernetes/container-logs#ingesting-rotated-container-logs)."
235+
},
232236
"vars": {
233237
"type": "object",
234238
"description": "Stream variables.",

deploy/helm/elastic-agent/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ kubernetes:
151151
# -- enable containers logs stream [ref](https://www.elastic.co/docs/current/integrations/kubernetes/container-logs)
152152
# @section -- 2 - Kubernetes integration
153153
enabled: true
154+
# -- BETA: enable rotated logs ingestion. WARNING: enabling it might cause date re-ingestion on existing deployments. [ref](https://www.elastic.co/docs/reference/integrations/kubernetes/container-logs#ingesting-rotated-container-logs)
155+
rotated_logs: false
154156
# -- containers logs stream vars
155157
# @section -- 2 - Kubernetes integration
156158
vars: {}

pkg/testing/runner/runner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,10 @@ func (r *Runner) runK8sInstances(ctx context.Context, instances []StateInstance)
277277
// run the actual tests on the host
278278
result, runErr := batch.OS.Runner.Run(ctx, r.cfg.VerboseMode, nil, logger, r.cfg.AgentVersion, prefix, batch.Batch, env)
279279
if runErr != nil {
280-
logger.Logf("Failed to execute tests on instance: %s", err)
281-
err = fmt.Errorf("failed to execute tests on instance %s: %w", instance.Name, err)
280+
logger.Logf("Failed to execute tests on instance: %s",
281+
runErr)
282+
err = fmt.Errorf("failed to execute tests on instance %s: %w",
283+
instance.Name, runErr)
282284
}
283285
resultsMx.Lock()
284286
results[batch.ID] = result

0 commit comments

Comments
 (0)