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

Work on timeout #1874

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions controllers/devworkspace/solver/che_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ func routeForHealthzEndpoint(cfg *gateway.TraefikConfig, dwId string, endpoints
Middlewares: middlewares,
Priority: priority,
}

cfg.AddRetryHealthz(routerName, 4, "2500ms")
}
}
}
Expand Down Expand Up @@ -687,6 +689,7 @@ func addEndpointToTraefikConfig(componentName string, e dwo.Endpoint, cfg *gatew
priority+1,
fmt.Sprintf("http://127.0.0.1:%d", e.TargetPort),
[]string{prefix})
cfg.AddRetryHealthz(healthzName, 2, "500ms")
}
}

Expand Down
16 changes: 10 additions & 6 deletions controllers/devworkspace/solver/che_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestCreateRelocatedObjectsK8S(t *testing.T) {
wsid := "wsid-m1-9999"
assert.Contains(t, workspaceConfig.HTTP.Routers, wsid)
assert.Len(t, workspaceConfig.HTTP.Routers[wsid].Middlewares, 2)
assert.Len(t, workspaceConfig.HTTP.Middlewares, 3)
assert.Len(t, workspaceConfig.HTTP.Middlewares, 4)

mwares := []string{wsid + gateway.StripPrefixMiddlewareSuffix}
for _, mware := range mwares {
Expand All @@ -356,7 +356,7 @@ func TestCreateRelocatedObjectsK8S(t *testing.T) {

workspaceMainConfig := gateway.TraefikConfig{}
assert.NoError(t, yaml.Unmarshal([]byte(traefikMainWorkspaceConfig), &workspaceMainConfig))
assert.Len(t, workspaceMainConfig.HTTP.Middlewares, 5)
assert.Len(t, workspaceMainConfig.HTTP.Middlewares, 6)

wsid = "wsid"
mwares = []string{
Expand Down Expand Up @@ -402,6 +402,7 @@ func TestCreateRelocatedObjectsK8S(t *testing.T) {
assert.NotContains(t, workspaceMainConfig.HTTP.Routers[healthzName].Middlewares, "wsid"+gateway.AuthMiddlewareSuffix)
assert.Contains(t, workspaceMainConfig.HTTP.Routers[healthzName].Middlewares, "wsid"+gateway.StripPrefixMiddlewareSuffix)
assert.NotContains(t, workspaceMainConfig.HTTP.Routers[healthzName].Middlewares, "wsid"+gateway.HeaderRewriteMiddlewareSuffix)
assert.Contains(t, workspaceMainConfig.HTTP.Routers[healthzName].Middlewares, healthzName+gateway.RetryHealthzMiddlewareSuffix)
})

t.Run("testHealthzEndpointInWorkspaceRoute", func(t *testing.T) {
Expand All @@ -411,6 +412,7 @@ func TestCreateRelocatedObjectsK8S(t *testing.T) {
assert.Equal(t, workspaceConfig.HTTP.Routers[healthzName].Rule, "Path(`/9999/healthz`)")
assert.NotContains(t, workspaceConfig.HTTP.Routers[healthzName].Middlewares, healthzName+gateway.AuthMiddlewareSuffix)
assert.Contains(t, workspaceConfig.HTTP.Routers[healthzName].Middlewares, healthzName+gateway.StripPrefixMiddlewareSuffix)
assert.Contains(t, workspaceConfig.HTTP.Routers[healthzName].Middlewares, healthzName+gateway.RetryHealthzMiddlewareSuffix)
})

})
Expand Down Expand Up @@ -477,7 +479,7 @@ func TestCreateRelocatedObjectsK8SLegacy(t *testing.T) {
wsid := "wsid-m1-9999"
assert.Contains(t, workspaceConfig.HTTP.Routers, wsid)
assert.Len(t, workspaceConfig.HTTP.Routers[wsid].Middlewares, 2)
assert.Len(t, workspaceConfig.HTTP.Middlewares, 3)
assert.Len(t, workspaceConfig.HTTP.Middlewares, 4)

mwares := []string{wsid + gateway.StripPrefixMiddlewareSuffix}
for _, mware := range mwares {
Expand All @@ -493,7 +495,7 @@ func TestCreateRelocatedObjectsK8SLegacy(t *testing.T) {

workspaceMainConfig := gateway.TraefikConfig{}
assert.NoError(t, yaml.Unmarshal([]byte(traefikMainWorkspaceConfig), &workspaceMainConfig))
assert.Len(t, workspaceMainConfig.HTTP.Middlewares, 5)
assert.Len(t, workspaceMainConfig.HTTP.Middlewares, 6)

wsid = "wsid"
mwares = []string{
Expand Down Expand Up @@ -541,6 +543,7 @@ func TestCreateRelocatedObjectsK8SLegacy(t *testing.T) {
assert.NotContains(t, workspaceMainConfig.HTTP.Routers[healthzName].Middlewares, "wsid"+gateway.AuthMiddlewareSuffix)
assert.Contains(t, workspaceMainConfig.HTTP.Routers[healthzName].Middlewares, "wsid"+gateway.StripPrefixMiddlewareSuffix)
assert.NotContains(t, workspaceMainConfig.HTTP.Routers[healthzName].Middlewares, "wsid"+gateway.HeaderRewriteMiddlewareSuffix)

})

t.Run("testHealthzEndpointInWorkspaceRoute", func(t *testing.T) {
Expand All @@ -551,6 +554,7 @@ func TestCreateRelocatedObjectsK8SLegacy(t *testing.T) {
assert.Equal(t, workspaceConfig.HTTP.Routers[healthzName].Priority, 101+len("/m1/9999"))
assert.NotContains(t, workspaceConfig.HTTP.Routers[healthzName].Middlewares, healthzName+gateway.AuthMiddlewareSuffix)
assert.Contains(t, workspaceConfig.HTTP.Routers[healthzName].Middlewares, healthzName+gateway.StripPrefixMiddlewareSuffix)
assert.Contains(t, workspaceConfig.HTTP.Routers[healthzName].Middlewares, healthzName+gateway.RetryHealthzMiddlewareSuffix)
})

})
Expand Down Expand Up @@ -606,7 +610,7 @@ func TestCreateRelocatedObjectsOpenshift(t *testing.T) {

workspaceMainConfig := gateway.TraefikConfig{}
assert.NoError(t, yaml.Unmarshal([]byte(traefikMainWorkspaceConfig), &workspaceMainConfig))
assert.Len(t, workspaceMainConfig.HTTP.Middlewares, 6)
assert.Len(t, workspaceMainConfig.HTTP.Middlewares, 7)

wsid = "wsid"
mwares := []string{
Expand Down Expand Up @@ -714,7 +718,7 @@ func TestCreateRelocatedObjectsOpenshiftLegacy(t *testing.T) {

workspaceMainConfig := gateway.TraefikConfig{}
assert.NoError(t, yaml.Unmarshal([]byte(traefikMainWorkspaceConfig), &workspaceMainConfig))
assert.Len(t, workspaceMainConfig.HTTP.Middlewares, 6)
assert.Len(t, workspaceMainConfig.HTTP.Middlewares, 7)

wsid = "wsid"
mwares := []string{
Expand Down
11 changes: 10 additions & 1 deletion pkg/deploy/gateway/traefik_config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
ErrorsMiddlewareSuffix = "-errors"
HeadersMiddlewareSuffix = "-headers"
RetryMiddlewareSuffix = "-retry"
RetryHealthzMiddlewareSuffix = "-retry-healthz"
)

func CreateEmptyTraefikConfig() *TraefikConfig {
Expand Down Expand Up @@ -130,7 +131,15 @@ func (cfg *TraefikConfig) AddResponseHeaders(componentName string, headers map[s
}

func (cfg *TraefikConfig) AddRetry(componentName string, attempts int, initialInterval string) {
middlewareName := componentName + RetryMiddlewareSuffix
cfg.addRetry(componentName, RetryMiddlewareSuffix, attempts, initialInterval)
}

func (cfg *TraefikConfig) AddRetryHealthz(componentName string, attempts int, initialInterval string) {
cfg.addRetry(componentName, RetryHealthzMiddlewareSuffix, attempts, initialInterval)
}

func (cfg *TraefikConfig) addRetry(componentName, suffix string, attempts int, initialInterval string) {
middlewareName := componentName + suffix
cfg.HTTP.Routers[componentName].Middlewares = append(cfg.HTTP.Routers[componentName].Middlewares, middlewareName)
cfg.HTTP.Middlewares[middlewareName] = &TraefikConfigMiddleware{
Retry: &TraefikConfigRetry{
Expand Down
Loading