Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add metric reporting to check-endpoints
- Loading branch information
Showing
6 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package controller | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/openshift/cluster-kube-apiserver-operator/pkg/cmd/checkendpoints/trace" | ||
"k8s.io/component-base/metrics" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
) | ||
|
||
var ( | ||
registerMetrics sync.Once | ||
|
||
endpointCheckCounter = metrics.NewCounterVec(&metrics.CounterOpts{ | ||
Name: "openshift_kube_apiserver_endpoint_check_count", | ||
Help: "Report status of endpoint checks for each API server pod over time.", | ||
}, []string{"endpoint", "tcpConnect", "dnsResolve"}) | ||
|
||
tcpConnectLatencyGauge = metrics.NewGaugeVec(&metrics.GaugeOpts{ | ||
Name: "openshift_kube_apiserver_endpoint_check_tcp_connect_latency_gauge", | ||
Help: "Report latency of TCP connect to endpoint for each API server pod over time.", | ||
}, []string{"endpoint"}) | ||
|
||
dnsResolveLatencyGauge = metrics.NewGaugeVec(&metrics.GaugeOpts{ | ||
Name: "openshift_kube_apiserver_endpoint_check_dns_resolve_latency_gauge", | ||
Help: "Report latency of DNS resolve of endpoint for each API server pod over time.", | ||
}, []string{"endpoint"}) | ||
) | ||
|
||
func RegisterMetrics() { | ||
registerMetrics.Do(func() { | ||
legacyregistry.MustRegister(endpointCheckCounter) | ||
legacyregistry.MustRegister(tcpConnectLatencyGauge) | ||
legacyregistry.MustRegister(dnsResolveLatencyGauge) | ||
}) | ||
} | ||
|
||
func updateMetrics(address string, latency *trace.LatencyInfo, checkErr error) { | ||
endpointCheckCounter.With(getCounterMetricLabels(address, latency, checkErr)).Inc() | ||
if latency.Connect > 0 { | ||
tcpConnectLatencyGauge.WithLabelValues(address).Set(float64(latency.Connect.Nanoseconds())) | ||
} | ||
if latency.DNS > 0 { | ||
dnsResolveLatencyGauge.WithLabelValues(address).Set(float64(latency.DNS.Nanoseconds())) | ||
} | ||
} | ||
|
||
func getCounterMetricLabels(address string, latency *trace.LatencyInfo, checkErr error) map[string]string { | ||
labels := map[string]string{ | ||
"endpoint": address, | ||
"dnsResolve": "", | ||
"tcpConnect": "", | ||
} | ||
if isDNSError(checkErr) { | ||
labels["dnsResolve"] = "failure" | ||
return labels | ||
} | ||
if latency.DNS != 0 { | ||
labels["dnsResolve"] = "success" | ||
} | ||
if checkErr != nil { | ||
labels["tcpConnect"] = "failure" | ||
return labels | ||
} | ||
labels["tcpConnect"] = "success" | ||
return labels | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.