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

Wire event watcher for LateConnections events #887

Merged
merged 2 commits into from
Jun 17, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/openshift/api v0.0.0-20200609191024-dca637550e8c
github.com/openshift/build-machinery-go v0.0.0-20200512074546-3744767c4131
github.com/openshift/client-go v0.0.0-20200608144219-584632b8fc73
github.com/openshift/library-go v0.0.0-20200615120640-a506fa41d3fb
github.com/openshift/library-go v0.0.0-20200617100204-823c70af3f78
github.com/prometheus/client_golang v1.1.0
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ github.com/openshift/client-go v0.0.0-20200608144219-584632b8fc73 h1:JePLt9EpNLF
github.com/openshift/client-go v0.0.0-20200608144219-584632b8fc73/go.mod h1:+66gk3dEqw9e+WoiXjJFzWlS1KGhj9ZRHi/RI/YG/ZM=
github.com/openshift/kubernetes-kube-storage-version-migrator v0.0.3-0.20200312103335-32e07ea4f8ca h1:YNtyJnE53QuEUSjl7L1AARocI021o7cU2bvh4prDtiE=
github.com/openshift/kubernetes-kube-storage-version-migrator v0.0.3-0.20200312103335-32e07ea4f8ca/go.mod h1:unEnEWccGeVxaXSRsWTjRsNxMqYXmuQjzjcPFQ91H9M=
github.com/openshift/library-go v0.0.0-20200615120640-a506fa41d3fb h1:Y9TC71a5/luZNV/mXu9+opX3w+aYogZpKPQlxUgra4o=
github.com/openshift/library-go v0.0.0-20200615120640-a506fa41d3fb/go.mod h1:gckhmPaUyPXT9HFUIeA8YgUzn3OzM5PhS2azW+Y8VmU=
github.com/openshift/library-go v0.0.0-20200617100204-823c70af3f78 h1:TiftgJc3FYZwvW05TpRCZoHNPvIzg7Vz5hunqdFw9sI=
github.com/openshift/library-go v0.0.0-20200617100204-823c70af3f78/go.mod h1:gckhmPaUyPXT9HFUIeA8YgUzn3OzM5PhS2azW+Y8VmU=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
7 changes: 7 additions & 0 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/targetconfigcontroller"
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/terminationobserver"
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/v410_00_assets"
"github.com/openshift/library-go/pkg/operator/eventwatch"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/openshift/library-go/pkg/operator/certrotation"
"github.com/openshift/library-go/pkg/operator/encryption"
Expand Down Expand Up @@ -104,6 +106,10 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
controllerContext.EventRecorder,
)

eventWatcher := eventwatch.New().
WithEventHandler(operatorclient.TargetNamespace, "LateConnections", terminationobserver.ProcessLateConnectionEvents).
Copy link
Member

Choose a reason for hiding this comment

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

@mfojtik who's producing this event, asking for a friend 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ToController(kubeInformersForNamespaces.InformersFor(operatorclient.TargetNamespace), kubeClient.CoreV1(), controllerContext.EventRecorder)

staticResourceController := staticresourcecontroller.NewStaticResourceController(
"KubeAPIServerStaticResources",
v410_00_assets.Asset,
Expand Down Expand Up @@ -284,6 +290,7 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
go featureUpgradeableController.Run(ctx, 1)
go certRotationTimeUpgradeableController.Run(ctx, 1)
go terminationObserver.Run(ctx, 1)
go eventWatcher.Run(ctx, 1)
go boundSATokenSignerController.Run(ctx, 1)
go staleConditionsController.Run(ctx, 1)
go connectivityCheckController.Run(ctx, 1)
Expand Down
28 changes: 28 additions & 0 deletions pkg/operator/terminationobserver/late_connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package terminationobserver

import (
v1 "k8s.io/api/core/v1"
"k8s.io/component-base/metrics"
)

// ProcessLateConnectionEvents increment openshift_kube_apiserver_lateconnections_count counter for apiserver reported in LateConnections event.
// The apiserver received connections very late in the graceful termination process, possibly a sign for a broken load balancer setup.
func ProcessLateConnectionEvents(event *v1.Event) error {
// best-effort to guess the source (apiserver) from event
name := event.InvolvedObject.Name
if len(name) == 0 {
name = event.Source.Component
}
if len(name) == 0 {
name = event.Source.Host
}
apiServerLateConnectionsCounter.WithLabelValues(event.InvolvedObject.Name).Inc()
return nil
}

var (
apiServerLateConnectionsCounter = metrics.NewCounterVec(&metrics.CounterOpts{
Name: "openshift_kube_apiserver_lateconnections_count",
Help: "Report observed late connection count for each API server instance over time",
}, []string{"name"})
)
1 change: 1 addition & 0 deletions pkg/operator/terminationobserver/termination_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func RegisterMetrics() {
registerMetrics.Do(func() {
legacyregistry.MustRegister(apiServerTerminationEventGauge)
legacyregistry.MustRegister(apiServerTerminationCounter)
legacyregistry.MustRegister(apiServerLateConnectionsCounter)
})
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ github.com/openshift/client-go/operatorcontrolplane/informers/externalversions/i
github.com/openshift/client-go/operatorcontrolplane/informers/externalversions/operatorcontrolplane
github.com/openshift/client-go/operatorcontrolplane/informers/externalversions/operatorcontrolplane/v1alpha1
github.com/openshift/client-go/operatorcontrolplane/listers/operatorcontrolplane/v1alpha1
# github.com/openshift/library-go v0.0.0-20200615120640-a506fa41d3fb
# github.com/openshift/library-go v0.0.0-20200617100204-823c70af3f78
github.com/openshift/library-go/pkg/assets
github.com/openshift/library-go/pkg/certs
github.com/openshift/library-go/pkg/config/client
Expand Down Expand Up @@ -257,6 +257,7 @@ github.com/openshift/library-go/pkg/operator/encryption/secrets
github.com/openshift/library-go/pkg/operator/encryption/state
github.com/openshift/library-go/pkg/operator/encryption/statemachine
github.com/openshift/library-go/pkg/operator/events
github.com/openshift/library-go/pkg/operator/eventwatch
github.com/openshift/library-go/pkg/operator/genericoperatorclient
github.com/openshift/library-go/pkg/operator/loglevel
github.com/openshift/library-go/pkg/operator/management
Expand Down