Skip to content
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

fix(health): support new Camel health check format (1.9.x) #3314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/common/traits/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestHealthTrait(t *testing.T) {
//
Eventually(IntegrationCondition(ns, "java", v1.IntegrationConditionReady), TestTimeoutMedium).Should(And(
WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionRuntimeNotReadyReason)),
WithTransform(IntegrationConditionMessage, HavePrefix(fmt.Sprintf("[Pod %s runtime is not ready: map[consumer:route1:DOWN context:UP", pod.Name))),
WithTransform(IntegrationConditionMessage, HavePrefix(fmt.Sprintf("[Pod %s runtime is not ready: map[route.context.name:camel-1 route.id:route1 route.status:Stopped]", pod.Name))),
))
// Check the Integration is still in running phase
Eventually(IntegrationPhase(ns, "java"), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning))
Expand Down
15 changes: 13 additions & 2 deletions pkg/controller/integration/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package integration

import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
Expand All @@ -37,16 +38,26 @@ const (
)

type HealthCheck struct {
Status HealthCheckState `json:"state,omitempty"`
Status HealthCheckState `json:"status,omitempty"`
Checks []HealthCheckResponse `json:"checks,omitempty"`
}

type HealthCheckResponse struct {
Name string `json:"name,omitempty"`
Status HealthCheckState `json:"state,omitempty"`
Status HealthCheckState `json:"status,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
}

func NewHealthCheck(body []byte) (*HealthCheck, error) {
health := HealthCheck{}
err := json.Unmarshal(body, &health)
if err != nil {
return nil, err
}

return &health, nil
}

func proxyGetHTTPProbe(ctx context.Context, c kubernetes.Interface, p *corev1.Probe, pod *corev1.Pod, container *corev1.Container) ([]byte, error) {
if p.HTTPGet == nil {
return nil, fmt.Errorf("missing probe handler for %s/%s", pod.Namespace, pod.Name)
Expand Down
87 changes: 87 additions & 0 deletions pkg/controller/integration/health_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewHealthCheck(t *testing.T) {
body := []byte(`
{
"status": "DOWN",
"checks": [
{
"name": "camel-routes",
"status": "DOWN",
"data": {
"route.id": "route1",
"route.context.name": "camel-1",
"route.status": "Stopped"
}
},
{
"name": "context",
"status": "UP",
"data": {
"context.name": "camel-1",
"context.version": "3.16.0",
"context.status": "Started"
}
},
{
"name": "camel-consumers",
"status": "DOWN",
"data": {
"route.id": "route1",
"route.context.name": "camel-1",
"route.status": "Stopped"
}
}
]
}
`)
health, err := NewHealthCheck(body)
assert.NoError(t, err)
assert.Equal(t, HealthCheckStateDown, health.Status)
assert.Len(t, health.Checks, 3)
assert.Equal(t, "camel-routes", health.Checks[0].Name)
assert.Equal(t, HealthCheckStateDown, health.Checks[0].Status)
assert.True(t, reflect.DeepEqual(health.Checks[0].Data, map[string]interface{}{
"route.id": "route1",
"route.context.name": "camel-1",
"route.status": "Stopped",
}))
assert.Equal(t, "context", health.Checks[1].Name)
assert.Equal(t, HealthCheckStateUp, health.Checks[1].Status)
assert.True(t, reflect.DeepEqual(health.Checks[1].Data, map[string]interface{}{
"context.name": "camel-1",
"context.version": "3.16.0",
"context.status": "Started",
}))
assert.Equal(t, "camel-consumers", health.Checks[2].Name)
assert.Equal(t, HealthCheckStateDown, health.Checks[2].Status)
assert.True(t, reflect.DeepEqual(health.Checks[2].Data, map[string]interface{}{
"route.id": "route1",
"route.context.name": "camel-1",
"route.status": "Stopped",
}))
}
Loading