fix: ensure namespces to be filterred correctly in workspace metrics

Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
huanggze
2019-05-10 15:23:14 +08:00
parent 7bf044a766
commit 3d36b254b0
4 changed files with 67 additions and 42 deletions

View File

@@ -20,6 +20,7 @@ package prometheus
import (
"flag"
"io/ioutil"
"kubesphere.io/kubesphere/pkg/informers"
"net/http"
"net/url"
"strconv"
@@ -145,12 +146,28 @@ func ParseMonitoringRequestParams(request *restful.Request) *MonitoringRequestPa
u := url.Values{}
if start != "" && end != "" {
u.Set("start", convertTimeGranularity(start))
u.Set("end", convertTimeGranularity(end))
u.Set("step", step)
u.Set("timeout", timeout)
// range query start time must be greater than the namespace creation time
if nsName != "" {
nsLister := informers.SharedInformerFactory().Core().V1().Namespaces().Lister()
ns, err := nsLister.Get(nsName)
if err == nil {
queryStartTime := u.Get("start")
nsCreationTime := strconv.FormatInt(ns.CreationTimestamp.Unix(), 10)
if nsCreationTime > queryStartTime {
u.Set("start", nsCreationTime)
}
}
}
requestParams.QueryType = RangeQueryType
requestParams.Params = u
return &requestParams
}
if instantTime != "" {