Merge pull request #2076 from huanggze/custom-monitoring

api: list metric labels and values
This commit is contained in:
KubeSphere CI Bot
2020-05-15 19:52:32 +08:00
committed by GitHub
12 changed files with 362 additions and 1 deletions

View File

@@ -19,6 +19,7 @@
package monitoring
import (
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/models/monitoring/expressions"
"kubesphere.io/kubesphere/pkg/simple/client/monitoring"
"time"
@@ -30,6 +31,7 @@ type MonitoringOperator interface {
GetNamedMetrics(metrics []string, time time.Time, opt monitoring.QueryOption) Metrics
GetNamedMetricsOverTime(metrics []string, start, end time.Time, step time.Duration, opt monitoring.QueryOption) Metrics
GetMetadata(namespace string) Metadata
GetMetricLabelSet(metric, namespace string, start, end time.Time) MetricLabelSet
}
type monitoringOperator struct {
@@ -78,3 +80,17 @@ func (mo monitoringOperator) GetMetadata(namespace string) Metadata {
data := mo.c.GetMetadata(namespace)
return Metadata{Data: data}
}
func (mo monitoringOperator) GetMetricLabelSet(metric, namespace string, start, end time.Time) MetricLabelSet {
// Different monitoring backend implementations have different ways to enforce namespace isolation.
// Each implementation should register itself to `ReplaceNamespaceFns` during init().
// We hard code "prometheus" here because we only support this datasource so far.
// In the future, maybe the value should be returned from a method like `mo.c.GetMonitoringServiceName()`.
expr, err := expressions.ReplaceNamespaceFns["prometheus"](metric, namespace)
if err != nil {
klog.Error(err)
return MetricLabelSet{}
}
data := mo.c.GetMetricLabelSet(expr, start, end)
return MetricLabelSet{Data: data}
}

View File

@@ -12,3 +12,7 @@ type Metrics struct {
type Metadata struct {
Data []monitoring.Metadata `json:"data" description:"actual array of results"`
}
type MetricLabelSet struct {
Data []map[string]string `json:"data" description:"actual array of results"`
}