Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metric kind for prometheus builder #724

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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