add duration parameter
Signed-off-by: Roland.Ma <rolandma@kubesphere.io>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)).
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user