-
Notifications
You must be signed in to change notification settings - Fork 263
Add health check extension for liveness & readiness probes #1779
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
Changes from 10 commits
36c8164
0b89b7b
a2b3b46
f418b61
0f82478
ee4eb0c
2411e2c
ab2ffec
77a9c61
805faf8
f4d3972
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package healthcheck | ||
|
|
||
| import ( | ||
| "go.opentelemetry.io/collector/component" | ||
| "go.opentelemetry.io/collector/confmap" | ||
|
|
||
| "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common" | ||
| ) | ||
|
|
||
| type healthCheckTranslator struct { | ||
| name string | ||
| } | ||
|
|
||
| var _ common.Translator[component.Config, component.ID] = (*healthCheckTranslator)(nil) | ||
|
|
||
| func NewHealthCheckTranslator() common.Translator[component.Config, component.ID] { | ||
| return &healthCheckTranslator{name: "health_check"} | ||
| } | ||
|
|
||
| func (t *healthCheckTranslator) ID() component.ID { | ||
| return component.NewIDWithName(component.MustNewType("health_check"), t.name) | ||
| } | ||
|
|
||
| func (t *healthCheckTranslator) Translate(_ *confmap.Conf) (component.Config, error) { | ||
| cfg := &struct { | ||
| Endpoint string `mapstructure:"endpoint"` | ||
| Path string `mapstructure:"path"` | ||
| }{ | ||
| Endpoint: "0.0.0.0:13133", | ||
| Path: "/", | ||
| } | ||
|
|
||
| return cfg, nil | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package healthcheck | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "go.opentelemetry.io/collector/confmap" | ||
| ) | ||
|
|
||
| func TestHealthCheckTranslator(t *testing.T) { | ||
| translator := NewHealthCheckTranslator() | ||
| assert.Equal(t, "health_check", translator.ID().Type().String()) | ||
|
|
||
| conf := confmap.New() | ||
| cfg, err := translator.Translate(conf) | ||
| assert.NoError(t, err) | ||
|
|
||
| // Assert the config has the expected fields | ||
| healthCheckCfg, ok := cfg.(*struct { | ||
| Endpoint string `mapstructure:"endpoint"` | ||
| Path string `mapstructure:"path"` | ||
| }) | ||
| assert.True(t, ok) | ||
| assert.Equal(t, "0.0.0.0:13133", healthCheckCfg.Endpoint) | ||
| assert.Equal(t, "/", healthCheckCfg.Path) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ import ( | |
| "github.com/aws/amazon-cloudwatch-agent/translator/context" | ||
| "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common" | ||
| "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/entitystore" | ||
| healthcheckextension "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/healthcheck" | ||
| "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/server" | ||
| pipelinetranslator "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/pipeline" | ||
| "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/pipeline/applicationsignals" | ||
|
|
@@ -92,6 +93,7 @@ func Translate(jsonConfig interface{}, os string) (*otelcol.Config, error) { | |
| } | ||
| if context.CurrentContext().KubernetesMode() != "" { | ||
| pipelines.Translators.Extensions.Set(server.NewTranslator()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. I moved it under the Kubernetes mode check since we only need the health check extension for Kubernetes environments. |
||
| pipelines.Translators.Extensions.Set(healthcheckextension.NewHealthCheckTranslator()) | ||
| } | ||
|
|
||
| cfg := &otelcol.Config{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I agree with this approach to add the health extension for the sake of unit tests. I would have updated all the expected yaml for kubernetes to expect the health extension.
Although I am open to disagreeing to my proposal since this is primarily for fixing unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially thought I wasn't supposed to edit the YAML files, but I agree with the proposal and have updated the expected Kubernetes YAML to include the health extension.