-
Notifications
You must be signed in to change notification settings - Fork 237
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 8 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,42 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package healthcheck | ||
|
|
||
| import ( | ||
| "sync" | ||
|
|
||
| "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 | ||
| mux sync.RWMutex | ||
|
||
| } | ||
|
|
||
| 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 { | ||
| t.mux.RLock() | ||
| defer t.mux.RUnlock() | ||
| 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" | ||
|
|
@@ -94,6 +95,8 @@ func Translate(jsonConfig interface{}, os string) (*otelcol.Config, error) { | |
| pipelines.Translators.Extensions.Set(server.NewTranslator()) | ||
|
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 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{ | ||
| Receivers: map[component.ID]component.Config{}, | ||
| Exporters: map[component.ID]component.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 dont think this is the correct way to fix the translator tests. What happens if a unit test actually has the health extension enabled ?
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.
Yeah, that's right. I fixed it to properly add the health check extension to expected results in Kubernetes mode instead of removing it, so the tests work correctly whether the extension is enabled or not.