From 4b4c6e0f79d17feadd6f902b052473c9225ea68d Mon Sep 17 00:00:00 2001 From: "Roland.Ma" Date: Wed, 15 Sep 2021 06:54:05 +0000 Subject: [PATCH] add duration parameter Signed-off-by: Roland.Ma --- pkg/kapis/monitoring/v1alpha3/helper.go | 12 +++++++----- pkg/kapis/monitoring/v1alpha3/register.go | 2 ++ pkg/simple/client/monitoring/prometheus/promql.go | 4 ++-- pkg/simple/client/monitoring/query_options.go | 9 +++------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pkg/kapis/monitoring/v1alpha3/helper.go b/pkg/kapis/monitoring/v1alpha3/helper.go index a2802de57..84d3f706f 100644 --- a/pkg/kapis/monitoring/v1alpha3/helper.go +++ b/pkg/kapis/monitoring/v1alpha3/helper.go @@ -91,6 +91,7 @@ type reqParams struct { ingress string job string services string + duration string pvcFilter string queryType string } @@ -152,6 +153,7 @@ func parseRequestParams(req *restful.Request) reqParams { r.componentType = req.PathParameter("component") r.ingress = req.PathParameter("ingress") r.job = req.QueryParameter("job") + r.duration = req.QueryParameter("duration") r.expression = req.QueryParameter("expr") r.metric = req.QueryParameter("metric") r.queryType = req.QueryParameter("type") @@ -345,12 +347,12 @@ func (h handler) makeQueryOptions(r reqParams, lvl monitoring.Level) (q queryOpt case monitoring.LevelIngress: q.identifier = model.IdentifierIngress - var step *time.Duration - // step param is reused in none Range Query to pass vector's time duration. + var du *time.Duration + // duration param is used in none Range Query to pass vector's time duration. if r.time != "" { - s, err := time.ParseDuration(r.step) + s, err := time.ParseDuration(r.duration) if err == nil { - step = &s + du = &s } } q.option = monitoring.IngressOption{ @@ -359,7 +361,7 @@ func (h handler) makeQueryOptions(r reqParams, lvl monitoring.Level) (q queryOpt Ingress: r.ingress, Job: r.job, Pod: r.podName, - Step: step, + Duration: du, } q.namedMetrics = model.IngressMetrics diff --git a/pkg/kapis/monitoring/v1alpha3/register.go b/pkg/kapis/monitoring/v1alpha3/register.go index 4369a4443..45253899f 100644 --- a/pkg/kapis/monitoring/v1alpha3/register.go +++ b/pkg/kapis/monitoring/v1alpha3/register.go @@ -431,6 +431,7 @@ func AddToContainer(c *restful.Container, k8sClient kubernetes.Interface, monito Param(ws.PathParameter("namespace", "The name of the namespace.").DataType("string").Required(true)). Param(ws.QueryParameter("job", "The job name filter. Ingress could be served by multi Ingress controllers, The job filters metric from a specific controller.").DataType("string").Required(true)). Param(ws.QueryParameter("pod", "The pod name filter.").DataType("string")). + Param(ws.QueryParameter("duration", "The duration is the time window of Range Vector. The format is [0-9]+[smhdwy]. Defaults to 5m (i.e. 5 min).").DataType("string").Required(false)). Param(ws.QueryParameter("metrics_filter", "The metric name filter consists of a regexp pattern. It specifies which metric data to return. For example, the following filter matches both PVC available and used inodes: `pvc_inodes_available|pvc_inodes_used`. View available metrics at [kubesphere.io](https://docs.kubesphere.io/advanced-v2.0/zh-CN/api-reference/monitoring-metrics/).").DataType("string").Required(false)). Param(ws.QueryParameter("resources_filter", "The PVC filter consists of a regexp pattern. It specifies which PVC data to return. For example, the following filter matches any pod whose name begins with redis: `redis.*`.").DataType("string").Required(false)). Param(ws.QueryParameter("start", "Start time of query. Use **start** and **end** to retrieve metric data over a time span. It is a string with Unix time format, eg. 1559347200. ").DataType("string").Required(false)). @@ -453,6 +454,7 @@ func AddToContainer(c *restful.Container, k8sClient kubernetes.Interface, monito Param(ws.PathParameter("ingress", "ingress name.").DataType("string").Required(true)). Param(ws.QueryParameter("job", "The job name filter. Ingress could be served by multi Ingress controllers, The job filters metric from a specific controller.").DataType("string").Required(true)). Param(ws.QueryParameter("pod", "The pod filter.").DataType("string")). + Param(ws.QueryParameter("duration", "The duration is the time window of Range Vector. The format is [0-9]+[smhdwy]. Defaults to 5m (i.e. 5 min).").DataType("string").Required(false)). Param(ws.QueryParameter("metrics_filter", "The metric name filter consists of a regexp pattern. It specifies which metric data to return. For example, the following filter matches both PVC available and used inodes: `pvc_inodes_available|pvc_inodes_used`. View available metrics at [kubesphere.io](https://docs.kubesphere.io/advanced-v2.0/zh-CN/api-reference/monitoring-metrics/).").DataType("string").Required(false)). Param(ws.QueryParameter("start", "Start time of query. Use **start** and **end** to retrieve metric data over a time span. It is a string with Unix time format, eg. 1559347200. ").DataType("string").Required(false)). Param(ws.QueryParameter("end", "End time of query. Use **start** and **end** to retrieve metric data over a time span. It is a string with Unix time format, eg. 1561939200. ").DataType("string").Required(false)). diff --git a/pkg/simple/client/monitoring/prometheus/promql.go b/pkg/simple/client/monitoring/prometheus/promql.go index 9dd236a4a..fe89f9252 100644 --- a/pkg/simple/client/monitoring/prometheus/promql.go +++ b/pkg/simple/client/monitoring/prometheus/promql.go @@ -472,8 +472,8 @@ func makeIngressMetricExpr(tmpl string, o monitoring.QueryOptions) string { duration := "5m" // parse Range Vector Selectors metric{key=value}[duration] - if o.MeterOptions != nil { - duration = o.MeterOptions.Step.String() + if o.Duration != nil { + duration = o.Duration.String() } // For monitoring ingress in the specific namespace diff --git a/pkg/simple/client/monitoring/query_options.go b/pkg/simple/client/monitoring/query_options.go index dc3178765..71e225202 100644 --- a/pkg/simple/client/monitoring/query_options.go +++ b/pkg/simple/client/monitoring/query_options.go @@ -84,6 +84,7 @@ type QueryOptions struct { ServiceName string Ingress string Job string + Duration *time.Duration MeterOptions *Meteroptions } @@ -296,7 +297,7 @@ type IngressOption struct { Ingress string Job string Pod string - Step *time.Duration + Duration *time.Duration } func (no IngressOption) Apply(o *QueryOptions) { @@ -306,11 +307,7 @@ func (no IngressOption) Apply(o *QueryOptions) { o.Ingress = no.Ingress o.Job = no.Job o.PodName = no.Pod - if no.Step != nil { - o.MeterOptions = &Meteroptions{ - Step: *no.Step, - } - } + o.Duration = no.Duration } type ComponentOption struct{}