Skip to content

Commit

Permalink
Test with healthcheckv2
Browse files Browse the repository at this point in the history
Signed-off-by: Janario Oliveira <janario.oliveira@gmail.com>
  • Loading branch information
janario committed May 14, 2024
1 parent 70ba297 commit ca88a7e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 23 deletions.
71 changes: 52 additions & 19 deletions internal/manifests/collector/adapters/config_to_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type probeConfiguration struct {

const (
defaultHealthCheckPath = "/"
defaultHealthCheckV2Path = "/health/status"
defaultHealthCheckPort = 13133
)

Expand All @@ -70,7 +71,7 @@ func ConfigToContainerProbe(config map[interface{}]interface{}) (*corev1.Probe,
healthCheckServiceExtensions := make([]string, 0)
for _, ext := range serviceExtensions {
parsedExt, ok := ext.(string)
if ok && strings.HasPrefix(parsedExt, "health_check") {
if ok && (strings.HasPrefix(parsedExt, "health_check") || strings.HasPrefix(parsedExt, "healthcheckv2")) {
healthCheckServiceExtensions = append(healthCheckServiceExtensions, parsedExt)
}
}
Expand All @@ -91,15 +92,15 @@ func ConfigToContainerProbe(config map[interface{}]interface{}) (*corev1.Probe,
for _, healthCheckForProbe := range healthCheckServiceExtensions {
healthCheckExtension, ok := extensions[healthCheckForProbe]
if ok {
return createProbeFromExtension(healthCheckExtension)
return createProbeFromExtension(healthCheckForProbe, healthCheckExtension)
}
}

return nil, errNoExtensionHealthCheck
}

func createProbeFromExtension(extension interface{}) (*corev1.Probe, error) {
probeCfg := extractProbeConfigurationFromExtension(extension)
func createProbeFromExtension(name string, extension interface{}) (*corev1.Probe, error) {
probeCfg := extractProbeConfigurationFromExtension(name, extension)
return &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Expand All @@ -110,38 +111,70 @@ func createProbeFromExtension(extension interface{}) (*corev1.Probe, error) {
}, nil
}

func extractProbeConfigurationFromExtension(ext interface{}) probeConfiguration {
func extractProbeConfigurationFromExtension(name string, ext interface{}) probeConfiguration {
extensionCfg, ok := ext.(map[interface{}]interface{})
if !ok {
return defaultProbeConfiguration()
return defaultProbeConfiguration(name)
}
return probeConfiguration{
path: extractPathFromExtensionConfig(extensionCfg),
port: extractPortFromExtensionConfig(extensionCfg),
path: extractPathFromExtensionConfig(name, extensionCfg),
port: extractPortFromExtensionConfig(name, extensionCfg),
}
}

func defaultProbeConfiguration() probeConfiguration {
func defaultProbeConfiguration(name string) probeConfiguration {
var path string
if strings.HasPrefix(name, "healthcheckv2") {
path = defaultHealthCheckV2Path
} else {
path = defaultHealthCheckPath
}
return probeConfiguration{
path: defaultHealthCheckPath,
path: path,
port: intstr.FromInt(defaultHealthCheckPort),
}
}

func extractPathFromExtensionConfig(cfg map[interface{}]interface{}) string {
if path, ok := cfg["path"]; ok {
if parsedPath, ok := path.(string); ok {
return parsedPath
func extractPathFromExtensionConfig(name string, cfg map[interface{}]interface{}) string {
if strings.HasPrefix(name, "healthcheckv2") {
if http, ok := cfg["http"].(map[interface{}]interface{}); ok {
if status, ok := http["status"].(map[interface{}]interface{}); ok {
if path, ok := status["path"]; ok {
if parsedPath, ok := path.(string); ok {
return parsedPath
}
}
}
}
return defaultHealthCheckV2Path
} else {
if path, ok := cfg["path"]; ok {
if parsedPath, ok := path.(string); ok {
return parsedPath
}
}
return defaultHealthCheckPath
}
return defaultHealthCheckPath
}

func extractPortFromExtensionConfig(cfg map[interface{}]interface{}) intstr.IntOrString {
endpoint, ok := cfg["endpoint"]
if !ok {
return defaultHealthCheckEndpoint()
func extractPortFromExtensionConfig(name string, cfg map[interface{}]interface{}) intstr.IntOrString {
var endpoint interface{}
if strings.HasPrefix(name, "healthcheckv2") {
if http, ok := cfg["http"].(map[interface{}]interface{}); ok {
ep, ok := http["endpoint"]
if !ok {
return defaultHealthCheckEndpoint()
}
endpoint = ep
}
} else {
ep, ok := cfg["endpoint"]
if !ok {
return defaultHealthCheckEndpoint()
}
endpoint = ep
}

parsedEndpoint, ok := endpoint.(string)
if !ok {
return defaultHealthCheckEndpoint()
Expand Down
26 changes: 22 additions & 4 deletions tests/e2e/high-availability-rollout/00-install-collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,34 @@ metadata:
spec:
mode: ($mode)
replicas: 2
#image: <repo>:healthcheckv2
# lifecycle:
# preStop:
# exec:
# command:
# - sleep
# - '3'
# - '1'
config: |
extensions:
health_check:
endpoint: ${POD_IP}:13133
#health_check:
# endpoint: ${POD_IP}:13133
healthcheckv2:
use_v2: true
component_health:
include_permanent_errors: false
include_recoverable_errors: true
recovery_duration: 5m
http:
endpoint: "${POD_IP}:13133"
status:
enabled: true
path: "/health/status"
config:
enabled: true
path: "/health/config"
grpc:
endpoint: "${POD_IP}:13132"
transport: "tcp"
receivers:
otlp:
protocols:
Expand All @@ -28,7 +45,8 @@ spec:
service:
extensions:
- health_check
#- health_check
- healthcheckv2
pipelines:
traces:
receivers: [otlp]
Expand Down

0 comments on commit ca88a7e

Please sign in to comment.