mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #45021 from shyamjvs/add-request-count
Automatic merge from submit-queue (batch tested with PRs 45033, 44961, 45021, 45097, 44938) Add request count to APICall metric Ref https://github.com/kubernetes/kubernetes/issues/44701 This should add beside the API call latencies, the count of the requests. cc @wojtek-t @gmarek
This commit is contained in:
commit
01321936b6
@ -167,6 +167,7 @@ type APICall struct {
|
|||||||
Resource string `json:"resource"`
|
Resource string `json:"resource"`
|
||||||
Verb string `json:"verb"`
|
Verb string `json:"verb"`
|
||||||
Latency LatencyMetric `json:"latency"`
|
Latency LatencyMetric `json:"latency"`
|
||||||
|
Count int `json:"count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type APIResponsiveness struct {
|
type APIResponsiveness struct {
|
||||||
@ -179,9 +180,10 @@ func (a APIResponsiveness) Less(i, j int) bool {
|
|||||||
return a.APICalls[i].Latency.Perc99 < a.APICalls[j].Latency.Perc99
|
return a.APICalls[i].Latency.Perc99 < a.APICalls[j].Latency.Perc99
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set request latency for a particular quantile in the APICall metric entry (creating one if necessary).
|
||||||
// 0 <= quantile <=1 (e.g. 0.95 is 95%tile, 0.5 is median)
|
// 0 <= quantile <=1 (e.g. 0.95 is 95%tile, 0.5 is median)
|
||||||
// Only 0.5, 0.9 and 0.99 quantiles are supported.
|
// Only 0.5, 0.9 and 0.99 quantiles are supported.
|
||||||
func (a *APIResponsiveness) addMetric(resource, verb string, quantile float64, latency time.Duration) {
|
func (a *APIResponsiveness) addMetricRequestLatency(resource, verb string, quantile float64, latency time.Duration) {
|
||||||
for i, apicall := range a.APICalls {
|
for i, apicall := range a.APICalls {
|
||||||
if apicall.Resource == resource && apicall.Verb == verb {
|
if apicall.Resource == resource && apicall.Verb == verb {
|
||||||
a.APICalls[i] = setQuantileAPICall(apicall, quantile, latency)
|
a.APICalls[i] = setQuantileAPICall(apicall, quantile, latency)
|
||||||
@ -211,6 +213,18 @@ func setQuantile(metric *LatencyMetric, quantile float64, latency time.Duration)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add request count to the APICall metric entry (creating one if necessary).
|
||||||
|
func (a *APIResponsiveness) addMetricRequestCount(resource, verb string, count int) {
|
||||||
|
for i, apicall := range a.APICalls {
|
||||||
|
if apicall.Resource == resource && apicall.Verb == verb {
|
||||||
|
a.APICalls[i].Count += count
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apicall := APICall{Resource: resource, Verb: verb, Count: count}
|
||||||
|
a.APICalls = append(a.APICalls, apicall)
|
||||||
|
}
|
||||||
|
|
||||||
func readLatencyMetrics(c clientset.Interface) (APIResponsiveness, error) {
|
func readLatencyMetrics(c clientset.Interface) (APIResponsiveness, error) {
|
||||||
var a APIResponsiveness
|
var a APIResponsiveness
|
||||||
|
|
||||||
@ -231,7 +245,9 @@ func readLatencyMetrics(c clientset.Interface) (APIResponsiveness, error) {
|
|||||||
for _, sample := range samples {
|
for _, sample := range samples {
|
||||||
// Example line:
|
// Example line:
|
||||||
// apiserver_request_latencies_summary{resource="namespaces",verb="LIST",quantile="0.99"} 908
|
// apiserver_request_latencies_summary{resource="namespaces",verb="LIST",quantile="0.99"} 908
|
||||||
if sample.Metric[model.MetricNameLabel] != "apiserver_request_latencies_summary" {
|
// apiserver_request_count{resource="pods",verb="LIST",client="kubectl",code="200",contentType="json"} 233
|
||||||
|
if sample.Metric[model.MetricNameLabel] != "apiserver_request_latencies_summary" &&
|
||||||
|
sample.Metric[model.MetricNameLabel] != "apiserver_request_count" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,12 +256,20 @@ func readLatencyMetrics(c clientset.Interface) (APIResponsiveness, error) {
|
|||||||
if ignoredResources.Has(resource) || ignoredVerbs.Has(verb) {
|
if ignoredResources.Has(resource) || ignoredVerbs.Has(verb) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
latency := sample.Value
|
|
||||||
quantile, err := strconv.ParseFloat(string(sample.Metric[model.QuantileLabel]), 64)
|
switch sample.Metric[model.MetricNameLabel] {
|
||||||
if err != nil {
|
case "apiserver_request_latencies_summary":
|
||||||
return a, err
|
latency := sample.Value
|
||||||
|
quantile, err := strconv.ParseFloat(string(sample.Metric[model.QuantileLabel]), 64)
|
||||||
|
if err != nil {
|
||||||
|
return a, err
|
||||||
|
}
|
||||||
|
a.addMetricRequestLatency(resource, verb, quantile, time.Duration(int64(latency))*time.Microsecond)
|
||||||
|
case "apiserver_request_count":
|
||||||
|
count := sample.Value
|
||||||
|
a.addMetricRequestCount(resource, verb, int(count))
|
||||||
|
|
||||||
}
|
}
|
||||||
a.addMetric(resource, verb, quantile, time.Duration(int64(latency))*time.Microsecond)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return a, err
|
return a, err
|
||||||
|
Loading…
Reference in New Issue
Block a user