Skip to content

Commit

Permalink
Merge pull request #724 from whitebear009/add-kind
Browse files Browse the repository at this point in the history
add metric kind for prometheus builder
  • Loading branch information
qmhu authored Mar 28, 2023
2 parents 046e6f7 + b023ebc commit 61f0df4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/querybuilder-providers/prometheus/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func (b *builder) workloadQuery(metric *metricquery.Metric) (query *metricquery.
case v1.ResourceCPU.String():
metricRule = prometheus_adapter.MatchMetricRule(mrs.MetricRulesExternal, prometheus_adapter.WorkloadCpuUsageExpression)
if metricRule == nil {
queryExpr = utils.GetWorkloadCpuUsageExpression(metric.Workload.Namespace, metric.Workload.Name, "")
queryExpr = utils.GetWorkloadCpuUsageExpression(metric.Workload.Namespace, metric.Workload.Name, metric.Workload.Kind)
}
case v1.ResourceMemory.String():
metricRule = prometheus_adapter.MatchMetricRule(mrs.MetricRulesExternal, prometheus_adapter.WorkloadMemUsageExpression)
if metricRule == nil {
queryExpr = utils.GetWorkloadMemUsageExpression(metric.Workload.Namespace, metric.Workload.Name, "")
queryExpr = utils.GetWorkloadMemUsageExpression(metric.Workload.Namespace, metric.Workload.Name, metric.Workload.Kind)
}
default:
return nil, fmt.Errorf("metric type %v do not support resource metric %v. only support %v now", metric.Type, metric.MetricName, supportedResources.List())
Expand Down Expand Up @@ -118,12 +118,12 @@ func (b *builder) containerQuery(metric *metricquery.Metric) (query *metricquery
case v1.ResourceCPU.String():
metricRule = prometheus_adapter.MatchMetricRule(mrs.MetricRulesExternal, prometheus_adapter.ContainerCpuUsageExpression)
if metricRule == nil {
queryExpr = utils.GetContainerCpuUsageExpression(metric.Container.Namespace, metric.Container.WorkloadName, "", metric.Container.Name)
queryExpr = utils.GetContainerCpuUsageExpression(metric.Container.Namespace, metric.Container.WorkloadName, metric.Container.WorkloadKind, metric.Container.Name)
}
case v1.ResourceMemory.String():
metricRule = prometheus_adapter.MatchMetricRule(mrs.MetricRulesExternal, prometheus_adapter.ContainerMemUsageExpression)
if metricRule == nil {
queryExpr = utils.GetContainerMemUsageExpression(metric.Container.Namespace, metric.Container.WorkloadName, "", metric.Container.Name)
queryExpr = utils.GetContainerMemUsageExpression(metric.Container.Namespace, metric.Container.WorkloadName, metric.Container.WorkloadKind, metric.Container.Name)
}
default:
return nil, fmt.Errorf("metric type %v do not support resource metric %v. only support %v now", metric.Type, metric.MetricName, supportedResources.List())
Expand Down
10 changes: 6 additions & 4 deletions pkg/querybuilder-providers/prometheus/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestBuildQuery(t *testing.T) {
APIVersion: "v1",
},
},
want: utils.GetWorkloadCpuUsageExpression("default", "test", ""),
want: utils.GetWorkloadCpuUsageExpression("default", "test", "Deployment"),
},
{
desc: "tc2-workload-mem",
Expand All @@ -60,7 +60,7 @@ func TestBuildQuery(t *testing.T) {
APIVersion: "v1",
},
},
want: utils.GetWorkloadMemUsageExpression("default", "test", ""),
want: utils.GetWorkloadMemUsageExpression("default", "test", "Deployment"),
},
{
desc: "tc3-container-cpu",
Expand All @@ -70,10 +70,11 @@ func TestBuildQuery(t *testing.T) {
Container: &metricquery.ContainerNamerInfo{
Namespace: "default",
WorkloadName: "workload",
WorkloadKind: "Deployment",
Name: "container",
},
},
want: utils.GetContainerCpuUsageExpression("default", "workload", "", "container"),
want: utils.GetContainerCpuUsageExpression("default", "workload", "Deployment", "container"),
},
{
desc: "tc4-container-mem",
Expand All @@ -83,10 +84,11 @@ func TestBuildQuery(t *testing.T) {
Container: &metricquery.ContainerNamerInfo{
Namespace: "default",
WorkloadName: "workload",
WorkloadKind: "Deployment",
Name: "container",
},
},
want: utils.GetContainerMemUsageExpression("default", "workload", "", "container"),
want: utils.GetContainerMemUsageExpression("default", "workload", "Deployment", "container"),
},
{
desc: "tc5-node-cpu",
Expand Down

0 comments on commit 61f0df4

Please sign in to comment.