add duration parameter

Signed-off-by: Roland.Ma <rolandma@kubesphere.io>
This commit is contained in:
Roland.Ma
2021-09-15 06:54:05 +00:00
parent 1ee5e49ac0
commit 4b4c6e0f79
4 changed files with 14 additions and 13 deletions

View File

@@ -91,6 +91,7 @@ type reqParams struct {
ingress string ingress string
job string job string
services string services string
duration string
pvcFilter string pvcFilter string
queryType string queryType string
} }
@@ -152,6 +153,7 @@ func parseRequestParams(req *restful.Request) reqParams {
r.componentType = req.PathParameter("component") r.componentType = req.PathParameter("component")
r.ingress = req.PathParameter("ingress") r.ingress = req.PathParameter("ingress")
r.job = req.QueryParameter("job") r.job = req.QueryParameter("job")
r.duration = req.QueryParameter("duration")
r.expression = req.QueryParameter("expr") r.expression = req.QueryParameter("expr")
r.metric = req.QueryParameter("metric") r.metric = req.QueryParameter("metric")
r.queryType = req.QueryParameter("type") r.queryType = req.QueryParameter("type")
@@ -345,12 +347,12 @@ func (h handler) makeQueryOptions(r reqParams, lvl monitoring.Level) (q queryOpt
case monitoring.LevelIngress: case monitoring.LevelIngress:
q.identifier = model.IdentifierIngress q.identifier = model.IdentifierIngress
var step *time.Duration var du *time.Duration
// step param is reused in none Range Query to pass vector's time duration. // duration param is used in none Range Query to pass vector's time duration.
if r.time != "" { if r.time != "" {
s, err := time.ParseDuration(r.step) s, err := time.ParseDuration(r.duration)
if err == nil { if err == nil {
step = &s du = &s
} }
} }
q.option = monitoring.IngressOption{ q.option = monitoring.IngressOption{
@@ -359,7 +361,7 @@ func (h handler) makeQueryOptions(r reqParams, lvl monitoring.Level) (q queryOpt
Ingress: r.ingress, Ingress: r.ingress,
Job: r.job, Job: r.job,
Pod: r.podName, Pod: r.podName,
Step: step, Duration: du,
} }
q.namedMetrics = model.IngressMetrics q.namedMetrics = model.IngressMetrics

View File

@@ -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.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("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("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("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("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)). 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.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("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("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("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("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)). 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)).

View File

@@ -472,8 +472,8 @@ func makeIngressMetricExpr(tmpl string, o monitoring.QueryOptions) string {
duration := "5m" duration := "5m"
// parse Range Vector Selectors metric{key=value}[duration] // parse Range Vector Selectors metric{key=value}[duration]
if o.MeterOptions != nil { if o.Duration != nil {
duration = o.MeterOptions.Step.String() duration = o.Duration.String()
} }
// For monitoring ingress in the specific namespace // For monitoring ingress in the specific namespace

View File

@@ -84,6 +84,7 @@ type QueryOptions struct {
ServiceName string ServiceName string
Ingress string Ingress string
Job string Job string
Duration *time.Duration
MeterOptions *Meteroptions MeterOptions *Meteroptions
} }
@@ -296,7 +297,7 @@ type IngressOption struct {
Ingress string Ingress string
Job string Job string
Pod string Pod string
Step *time.Duration Duration *time.Duration
} }
func (no IngressOption) Apply(o *QueryOptions) { func (no IngressOption) Apply(o *QueryOptions) {
@@ -306,11 +307,7 @@ func (no IngressOption) Apply(o *QueryOptions) {
o.Ingress = no.Ingress o.Ingress = no.Ingress
o.Job = no.Job o.Job = no.Job
o.PodName = no.Pod o.PodName = no.Pod
if no.Step != nil { o.Duration = no.Duration
o.MeterOptions = &Meteroptions{
Step: *no.Step,
}
}
} }
type ComponentOption struct{} type ComponentOption struct{}