forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: reduce unnecessary K8s calls for CRDs during reconciliation (ar…
…goproj#3246) * reduce K8s calls for CRDs during reconciliation * additional metric labels to k8s API requests (server, verb, kind, namespace)
- Loading branch information
Showing
9 changed files
with
78 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,37 +1,24 @@ | ||
package metrics | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/argoproj/pkg/kubeclientmetrics" | ||
"k8s.io/client-go/rest" | ||
|
||
"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" | ||
) | ||
|
||
type metricsRoundTripper struct { | ||
roundTripper http.RoundTripper | ||
app *v1alpha1.Application | ||
metricsServer *MetricsServer | ||
} | ||
|
||
func (mrt *metricsRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) { | ||
resp, err := mrt.roundTripper.RoundTrip(r) | ||
statusCode := 0 | ||
if resp != nil { | ||
statusCode = resp.StatusCode | ||
} | ||
mrt.metricsServer.IncKubernetesRequest(mrt.app, statusCode) | ||
return resp, err | ||
} | ||
|
||
// AddMetricsTransportWrapper adds a transport wrapper which increments 'argocd_app_k8s_request_total' counter on each kubernetes request | ||
func AddMetricsTransportWrapper(server *MetricsServer, app *v1alpha1.Application, config *rest.Config) *rest.Config { | ||
wrap := config.WrapTransport | ||
config.WrapTransport = func(rt http.RoundTripper) http.RoundTripper { | ||
if wrap != nil { | ||
rt = wrap(rt) | ||
} | ||
return &metricsRoundTripper{roundTripper: rt, metricsServer: server, app: app} | ||
inc := func(resourceInfo kubeclientmetrics.ResourceInfo) error { | ||
namespace := resourceInfo.Namespace | ||
kind := resourceInfo.Kind | ||
statusCode := strconv.Itoa(resourceInfo.StatusCode) | ||
server.IncKubernetesRequest(app, resourceInfo.Server, statusCode, string(resourceInfo.Verb), kind, namespace) | ||
return nil | ||
} | ||
return config | ||
|
||
newConfig := kubeclientmetrics.AddMetricsTransportWrapper(config, inc) | ||
return newConfig | ||
} |