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

suppress health check noise #1650

Merged
merged 1 commit into from
Dec 15, 2020
Merged
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
22 changes: 15 additions & 7 deletions dataclients/kubernetes/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
log "github.com/sirupsen/logrus"

"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters/accesslog"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/predicates/source"
)
Expand Down Expand Up @@ -348,9 +349,19 @@ func shuntRoute(r *eskip.Route) {
}

func healthcheckRoute(healthy, reverseSourcePredicate bool) *eskip.Route {
status := http.StatusOK
logFilters := []*eskip.Filter{{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can also call logFilters as just filters, because their main gig is not the logging part but the status.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged

Name: builtin.StatusName,
Args: []interface{}{http.StatusOK}},
}
if !healthy {
status = http.StatusServiceUnavailable
logFilters[0].Args = []interface{}{http.StatusServiceUnavailable}
}
// log if unhealthy or a debug loglevel
if healthy && !log.IsLevelEnabled(log.DebugLevel) {
logFilters = append(logFilters, &eskip.Filter{
Name: accesslog.DisableAccessLogName,
Args: []interface{}{200},
})
Comment on lines +352 to +364
Copy link
Member

@AlexanderYastrebov AlexanderYastrebov Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative could be

        var healthcheckFilters []*eskip.Filter
	if healthy {
		if log.IsLevelEnabled(log.DebugLevel) {
			healthcheckFilters, _ = eskip.ParseFilters(`status(200)`)
		} else {
			healthcheckFilters, _ = eskip.ParseFilters(`disableAccessLog(200) -> status(200)`)
		}
	} else {
		healthcheckFilters, _ = eskip.ParseFilters(`status(503)`)
	}
adjusted test
diff --git a/dataclients/kubernetes/kube_test.go b/dataclients/kubernetes/kube_test.go
index cd899715..8a3e60f1 100644
--- a/dataclients/kubernetes/kube_test.go
+++ b/dataclients/kubernetes/kube_test.go
@@ -410,10 +410,11 @@ func checkHealthcheck(t *testing.T, got []*eskip.Route, expected, healthy, rever
                                return
                        }
 
-                       if healthy && f.Args[0] != http.StatusOK {
-                               t.Error("invalid healthcheck status", f.Args[0], http.StatusOK)
-                       } else if !healthy && f.Args[0] != http.StatusServiceUnavailable {
-                               t.Error("invalid healthcheck status", f.Args[0], http.StatusServiceUnavailable)
+                       status := int(f.Args[0].(float64))
+                       if healthy && status != http.StatusOK {
+                               t.Error("invalid healthcheck status", status, http.StatusOK)
+                       } else if !healthy && status != http.StatusServiceUnavailable {
+                               t.Error("invalid healthcheck status", status, http.StatusServiceUnavailable)
                        }
 
                        return
Also related to #1537

Copy link
Contributor Author

@universam1 universam1 Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parsing functionality is awesome to know!

My personal preference is to use static type compiler support whenever possible, not sure how expensive runtime parsing is but I’d expect a magnitude!?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more about readabilty, skipper parses hundreds of routes on route table update anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally don’t parse filters like this in the dataclient if it’s not eskip or inline route

}

var p []*eskip.Predicate
Expand All @@ -370,11 +381,8 @@ func healthcheckRoute(healthy, reverseSourcePredicate bool) *eskip.Route {
Id: healthcheckRouteID,
Predicates: p,
Path: healthcheckPath,
Filters: []*eskip.Filter{{
Name: builtin.StatusName,
Args: []interface{}{status}},
},
Shunt: true,
Filters: logFilters,
Shunt: true,
}
}

Expand Down