Skip to content

Commit 14ef2e8

Browse files
Add health check extension for liveness & readiness probes (#1779)
1 parent 0fc6a68 commit 14ef2e8

11 files changed

Lines changed: 154 additions & 0 deletions

translator/tocwconfig/sampleConfig/appsignals_and_eks_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ extensions:
313313
objects:
314314
- endpointslices
315315
- services
316+
health_check/health_check:
317+
endpoint: 0.0.0.0:13133
318+
path: /
316319
server:
317320
listen_addr: :4311
318321
tls_ca_path: /etc/amazon-cloudwatch-observability-agent-client-cert/tls-ca.crt
@@ -1538,6 +1541,7 @@ service:
15381541
- k8smetadata
15391542
- entitystore
15401543
- server
1544+
- health_check/health_check
15411545
pipelines:
15421546
metrics/application_signals:
15431547
exporters:

translator/tocwconfig/sampleConfig/appsignals_and_k8s_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ extensions:
314314
objects:
315315
- endpointslices
316316
- services
317+
health_check/health_check:
318+
endpoint: 0.0.0.0:13133
319+
path: /
317320
server:
318321
listen_addr: :4311
319322
tls_ca_path: /etc/amazon-cloudwatch-observability-agent-client-cert/tls-ca.crt
@@ -1533,6 +1536,7 @@ service:
15331536
- k8smetadata
15341537
- entitystore
15351538
- server
1539+
- health_check/health_check
15361540
pipelines:
15371541
metrics/application_signals:
15381542
exporters:

translator/tocwconfig/sampleConfig/appsignals_fallback_and_eks_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ extensions:
313313
objects:
314314
- endpointslices
315315
- services
316+
health_check/health_check:
317+
endpoint: 0.0.0.0:13133
318+
path: /
316319
server:
317320
listen_addr: :4311
318321
tls_ca_path: /etc/amazon-cloudwatch-observability-agent-client-cert/tls-ca.crt
@@ -1538,6 +1541,7 @@ service:
15381541
- k8smetadata
15391542
- entitystore
15401543
- server
1544+
- health_check/health_check
15411545
pipelines:
15421546
metrics/application_signals:
15431547
exporters:

translator/tocwconfig/sampleConfig/appsignals_over_fallback_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ extensions:
318318
tls_ca_path: /etc/amazon-cloudwatch-observability-agent-client-cert/tls-ca.crt
319319
tls_cert_path: /etc/amazon-cloudwatch-observability-agent-server-cert/server.crt
320320
tls_key_path: /etc/amazon-cloudwatch-observability-agent-server-cert/server.key
321+
health_check/health_check:
322+
endpoint: 0.0.0.0:13133
323+
path: /
321324
processors:
322325
awsapplicationsignals:
323326
limiter:
@@ -1538,6 +1541,7 @@ service:
15381541
- k8smetadata
15391542
- entitystore
15401543
- server
1544+
- health_check/health_check
15411545
pipelines:
15421546
metrics/application_signals:
15431547
exporters:

translator/tocwconfig/sampleConfig/otlp_metrics_cloudwatchlogs_eks_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ extensions:
5353
k8smetadata:
5454
objects:
5555
- endpointslices
56+
health_check/health_check:
57+
endpoint: 0.0.0.0:13133
58+
path: /
5659
server:
5760
listen_addr: :4311
5861
tls_ca_path: /etc/amazon-cloudwatch-observability-agent-client-cert/tls-ca.crt
@@ -107,6 +110,7 @@ service:
107110
- agenthealth/statuscode
108111
- entitystore
109112
- server
113+
- health_check/health_check
110114
pipelines:
111115
metrics/hostOtlpMetrics/cloudwatchlogs:
112116
exporters:

translator/tocwconfig/sampleConfig/otlp_metrics_eks_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ extensions:
3131
k8smetadata:
3232
objects:
3333
- endpointslices
34+
health_check/health_check:
35+
endpoint: 0.0.0.0:13133
36+
path: /
3437
server:
3538
listen_addr: :4311
3639
tls_ca_path: /etc/amazon-cloudwatch-observability-agent-client-cert/tls-ca.crt
@@ -91,6 +94,7 @@ service:
9194
- agenthealth/statuscode
9295
- entitystore
9396
- server
97+
- health_check/health_check
9498
pipelines:
9599
metrics/hostOtlpMetrics:
96100
exporters:

translator/tocwconfig/sampleConfig/statsd_eks_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ extensions:
2828
kubernetes_mode: EKS
2929
mode: ec2
3030
region: us-west-2
31+
health_check/health_check:
32+
endpoint: 0.0.0.0:13133
33+
path: /
3134
server:
3235
listen_addr: :4311
3336
tls_ca_path: /etc/amazon-cloudwatch-observability-agent-client-cert/tls-ca.crt
@@ -44,6 +47,7 @@ service:
4447
- agenthealth/statuscode
4548
- entitystore
4649
- server
50+
- health_check/health_check
4751
pipelines:
4852
metrics/hostCustomMetrics:
4953
exporters:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package healthcheck
5+
6+
import (
7+
"go.opentelemetry.io/collector/component"
8+
"go.opentelemetry.io/collector/confmap"
9+
10+
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common"
11+
)
12+
13+
type healthCheckTranslator struct {
14+
name string
15+
}
16+
17+
var _ common.Translator[component.Config, component.ID] = (*healthCheckTranslator)(nil)
18+
19+
func NewHealthCheckTranslator() common.Translator[component.Config, component.ID] {
20+
return &healthCheckTranslator{name: "health_check"}
21+
}
22+
23+
func (t *healthCheckTranslator) ID() component.ID {
24+
return component.NewIDWithName(component.MustNewType("health_check"), t.name)
25+
}
26+
27+
func (t *healthCheckTranslator) Translate(_ *confmap.Conf) (component.Config, error) {
28+
cfg := &struct {
29+
Endpoint string `mapstructure:"endpoint"`
30+
Path string `mapstructure:"path"`
31+
}{
32+
Endpoint: "0.0.0.0:13133",
33+
Path: "/",
34+
}
35+
36+
return cfg, nil
37+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package healthcheck
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"go.opentelemetry.io/collector/confmap"
11+
)
12+
13+
func TestHealthCheckTranslator(t *testing.T) {
14+
translator := NewHealthCheckTranslator()
15+
assert.Equal(t, "health_check", translator.ID().Type().String())
16+
17+
conf := confmap.New()
18+
cfg, err := translator.Translate(conf)
19+
assert.NoError(t, err)
20+
21+
// Assert the config has the expected fields
22+
healthCheckCfg, ok := cfg.(*struct {
23+
Endpoint string `mapstructure:"endpoint"`
24+
Path string `mapstructure:"path"`
25+
})
26+
assert.True(t, ok)
27+
assert.Equal(t, "0.0.0.0:13133", healthCheckCfg.Endpoint)
28+
assert.Equal(t, "/", healthCheckCfg.Path)
29+
}

translator/translate/otel/translate_otel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/aws/amazon-cloudwatch-agent/translator/context"
2424
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common"
2525
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/entitystore"
26+
healthcheckextension "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/healthcheck"
2627
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/server"
2728
pipelinetranslator "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/pipeline"
2829
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/pipeline/applicationsignals"
@@ -92,6 +93,7 @@ func Translate(jsonConfig interface{}, os string) (*otelcol.Config, error) {
9293
}
9394
if context.CurrentContext().KubernetesMode() != "" {
9495
pipelines.Translators.Extensions.Set(server.NewTranslator())
96+
pipelines.Translators.Extensions.Set(healthcheckextension.NewHealthCheckTranslator())
9597
}
9698

9799
cfg := &otelcol.Config{

0 commit comments

Comments
 (0)