mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix: duration metrics precision (#4393)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
parent
3d9417a58a
commit
0cc4d9b1f0
5 changed files with 13 additions and 13 deletions
|
@ -29,7 +29,7 @@ func (h *handlers) handleGenerate(
|
|||
request *admissionv1.AdmissionRequest,
|
||||
policies []kyvernov1.PolicyInterface,
|
||||
policyContext *engine.PolicyContext,
|
||||
admissionRequestTimestamp int64,
|
||||
admissionRequestTimestamp time.Time,
|
||||
latencySender *chan int64,
|
||||
generateEngineResponsesSenderForAdmissionReviewDurationMetric *chan []*response.EngineResponse,
|
||||
generateEngineResponsesSenderForAdmissionRequestsCountMetric *chan []*response.EngineResponse,
|
||||
|
@ -80,7 +80,7 @@ func (h *handlers) handleGenerate(
|
|||
}
|
||||
|
||||
// sending the admission request latency to other goroutine (reporting the metrics) over the channel
|
||||
admissionReviewLatencyDuration := int64(time.Since(time.Unix(admissionRequestTimestamp, 0)))
|
||||
admissionReviewLatencyDuration := int64(time.Since(admissionRequestTimestamp))
|
||||
*latencySender <- admissionReviewLatencyDuration
|
||||
*generateEngineResponsesSenderForAdmissionReviewDurationMetric <- engineResponses
|
||||
*generateEngineResponsesSenderForAdmissionRequestsCountMetric <- engineResponses
|
||||
|
|
|
@ -109,7 +109,7 @@ func (h *handlers) Validate(logger logr.Logger, request *admissionv1.AdmissionRe
|
|||
logger.V(4).Info("received an admission request in validating webhook", "kind", kind)
|
||||
|
||||
// timestamp at which this admission request got triggered
|
||||
requestTime := time.Now().Unix()
|
||||
requestTime := time.Now()
|
||||
policies := h.pCache.GetPolicies(policycache.ValidateEnforce, kind, request.Namespace)
|
||||
mutatePolicies := h.pCache.GetPolicies(policycache.Mutate, kind, request.Namespace)
|
||||
generatePolicies := h.pCache.GetPolicies(policycache.Generate, kind, request.Namespace)
|
||||
|
@ -212,7 +212,7 @@ func (h *handlers) Mutate(logger logr.Logger, request *admissionv1.AdmissionRequ
|
|||
}
|
||||
kind := request.Kind.Kind
|
||||
logger.V(4).Info("received an admission request in mutating webhook", "kind", kind)
|
||||
requestTime := time.Now().Unix()
|
||||
requestTime := time.Now()
|
||||
mutatePolicies := h.pCache.GetPolicies(policycache.Mutate, kind, request.Namespace)
|
||||
verifyImagesPolicies := h.pCache.GetPolicies(policycache.VerifyImagesMutate, kind, request.Namespace)
|
||||
if len(mutatePolicies) == 0 && len(verifyImagesPolicies) == 0 {
|
||||
|
@ -295,7 +295,7 @@ func (h *handlers) buildPolicyContext(request *admissionv1.AdmissionRequest, add
|
|||
return policyContext, nil
|
||||
}
|
||||
|
||||
func (h *handlers) applyMutatePolicies(logger logr.Logger, request *admissionv1.AdmissionRequest, policyContext *engine.PolicyContext, policies []kyvernov1.PolicyInterface, ts int64) ([]byte, []string, error) {
|
||||
func (h *handlers) applyMutatePolicies(logger logr.Logger, request *admissionv1.AdmissionRequest, policyContext *engine.PolicyContext, policies []kyvernov1.PolicyInterface, ts time.Time) ([]byte, []string, error) {
|
||||
mutatePatches, mutateEngineResponses, err := h.handleMutation(logger, request, policyContext, policies)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -303,7 +303,7 @@ func (h *handlers) applyMutatePolicies(logger logr.Logger, request *admissionv1.
|
|||
|
||||
logger.V(6).Info("", "generated patches", string(mutatePatches))
|
||||
|
||||
admissionReviewLatencyDuration := int64(time.Since(time.Unix(ts, 0)))
|
||||
admissionReviewLatencyDuration := int64(time.Since(ts))
|
||||
go h.registerAdmissionReviewDurationMetricMutate(logger, string(request.Operation), mutateEngineResponses, admissionReviewLatencyDuration)
|
||||
go h.registerAdmissionRequestsMetricMutate(logger, string(request.Operation), mutateEngineResponses)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
// createUpdateRequests applies generate and mutateExisting policies, and creates update requests for background reconcile
|
||||
func (h *handlers) createUpdateRequests(logger logr.Logger, request *admissionv1.AdmissionRequest, policyContext *engine.PolicyContext, generatePolicies, mutatePolicies []kyvernov1.PolicyInterface, ts int64) {
|
||||
func (h *handlers) createUpdateRequests(logger logr.Logger, request *admissionv1.AdmissionRequest, policyContext *engine.PolicyContext, generatePolicies, mutatePolicies []kyvernov1.PolicyInterface, ts time.Time) {
|
||||
admissionReviewCompletionLatencyChannel := make(chan int64, 1)
|
||||
generateEngineResponsesSenderForAdmissionReviewDurationMetric := make(chan []*response.EngineResponse, 1)
|
||||
generateEngineResponsesSenderForAdmissionRequestsCountMetric := make(chan []*response.EngineResponse, 1)
|
||||
|
@ -26,7 +26,7 @@ func (h *handlers) createUpdateRequests(logger logr.Logger, request *admissionv1
|
|||
go h.registerAdmissionRequestsMetricGenerate(logger, string(request.Operation), &generateEngineResponsesSenderForAdmissionRequestsCountMetric)
|
||||
}
|
||||
|
||||
func (h *handlers) handleMutateExisting(logger logr.Logger, request *admissionv1.AdmissionRequest, policies []kyvernov1.PolicyInterface, policyContext *engine.PolicyContext, admissionRequestTimestamp int64) {
|
||||
func (h *handlers) handleMutateExisting(logger logr.Logger, request *admissionv1.AdmissionRequest, policies []kyvernov1.PolicyInterface, policyContext *engine.PolicyContext, admissionRequestTimestamp time.Time) {
|
||||
logger.V(4).Info("update request")
|
||||
|
||||
if request.Operation == admissionv1.Delete {
|
||||
|
@ -73,7 +73,7 @@ func (h *handlers) handleMutateExisting(logger logr.Logger, request *admissionv1
|
|||
}
|
||||
}
|
||||
|
||||
admissionReviewLatencyDuration := int64(time.Since(time.Unix(admissionRequestTimestamp, 0)))
|
||||
admissionReviewLatencyDuration := int64(time.Since(admissionRequestTimestamp))
|
||||
go h.registerAdmissionReviewDurationMetricMutate(logger, string(request.Operation), engineResponses, admissionReviewLatencyDuration)
|
||||
go h.registerAdmissionRequestsMetricMutate(logger, string(request.Operation), engineResponses)
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ func (h *auditHandler) process(request *admissionv1.AdmissionRequest) error {
|
|||
var roles, clusterRoles []string
|
||||
var err error
|
||||
// time at which the corresponding the admission request's processing got initiated
|
||||
admissionRequestTimestamp := time.Now().Unix()
|
||||
admissionRequestTimestamp := time.Now()
|
||||
logger := h.log.WithName("process")
|
||||
|
||||
policies := h.pCache.GetPolicies(policycache.ValidateAudit, request.Kind.Kind, request.Namespace)
|
||||
|
|
|
@ -32,7 +32,7 @@ func (v *validationHandler) handleValidation(
|
|||
policies []kyvernov1.PolicyInterface,
|
||||
policyContext *engine.PolicyContext,
|
||||
namespaceLabels map[string]string,
|
||||
admissionRequestTimestamp int64,
|
||||
admissionRequestTimestamp time.Time,
|
||||
) (bool, string, []string) {
|
||||
if len(policies) == 0 {
|
||||
return true, "", nil
|
||||
|
@ -123,8 +123,8 @@ func (v *validationHandler) generateReportChangeRequests(request *admissionv1.Ad
|
|||
}
|
||||
}
|
||||
|
||||
func (v *validationHandler) generateMetrics(request *admissionv1.AdmissionRequest, admissionRequestTimestamp int64, engineResponses []*response.EngineResponse, metricsConfig *metrics.MetricsConfig, logger logr.Logger) {
|
||||
admissionReviewLatencyDuration := int64(time.Since(time.Unix(admissionRequestTimestamp, 0)))
|
||||
func (v *validationHandler) generateMetrics(request *admissionv1.AdmissionRequest, admissionRequestTimestamp time.Time, engineResponses []*response.EngineResponse, metricsConfig *metrics.MetricsConfig, logger logr.Logger) {
|
||||
admissionReviewLatencyDuration := int64(time.Since(admissionRequestTimestamp))
|
||||
go registerAdmissionReviewDurationMetricValidate(logger, metricsConfig, string(request.Operation), engineResponses, admissionReviewLatencyDuration)
|
||||
go registerAdmissionRequestsMetricValidate(logger, metricsConfig, string(request.Operation), engineResponses)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue