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

Cherry-pick https://github.com/opendatahub-io/odh-model-controller/pull/256 #261

Merged
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
1 change: 1 addition & 0 deletions controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
KserveMetricsConfigMapNameSuffix = "-metrics-dashboard"
DefaultStorageConfig = "storage-config"
IntervalValue = "1m"
RequestRateInterval = "5m"
OvmsImageName = "openvino_model_server"
TgisImageName = "text-generation-inference"
VllmImageName = "vllm"
Expand Down
22 changes: 11 additions & 11 deletions controllers/constants/runtime-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ const (
CaikitMetricsData = `{
"config": [
{
"title": "Number of requests",
"title": "Requests per 5 minutes",
"type": "REQUEST_COUNT",
"queries": [
{
"title": "Number of successful incoming requests",
"query": "round(sum(increase(predict_rpc_count_total{namespace='${NAMESPACE}',code='OK',model_id='${MODEL_NAME}'}[${RATE_INTERVAL}])))"
"query": "round(sum(increase(predict_rpc_count_total{namespace='${NAMESPACE}',code='OK',model_id='${MODEL_NAME}'}[${REQUEST_RATE_INTERVAL}])))"
},
{
"title": "Number of failed incoming requests",
"query": "round(sum(increase(predict_rpc_count_total{namespace='${NAMESPACE}',code!='OK',model_id='${MODEL_NAME}'}[${RATE_INTERVAL}])))"
"query": "round(sum(increase(predict_rpc_count_total{namespace='${NAMESPACE}',code!='OK',model_id='${MODEL_NAME}'}[${REQUEST_RATE_INTERVAL}])))"
}
]
},
Expand Down Expand Up @@ -74,16 +74,16 @@ const (
OvmsMetricsData = `{
"config": [
{
"title": "Number of requests",
"title": "Requests per 5 minutes",
"type": "REQUEST_COUNT",
"queries": [
{
"title": "Number of successful incoming requests",
"query": "round(sum(increase(ovms_requests_success{namespace='${NAMESPACE}',name='${MODEL_NAME}'}[${RATE_INTERVAL}])))"
"query": "round(sum(increase(ovms_requests_success{namespace='${NAMESPACE}',name='${MODEL_NAME}'}[${REQUEST_RATE_INTERVAL}])))"
},
{
"title": "Number of failed incoming requests",
"query": "round(sum(increase(ovms_requests_fail{namespace='${NAMESPACE}',name='${MODEL_NAME}'}[${RATE_INTERVAL}])))"
"query": "round(sum(increase(ovms_requests_fail{namespace='${NAMESPACE}',name='${MODEL_NAME}'}[${REQUEST_RATE_INTERVAL}])))"
}
]
},
Expand Down Expand Up @@ -128,16 +128,16 @@ const (
TgisMetricsData = `{
"config": [
{
"title": "Number of requests",
"title": "Requests per 5 minutes",
"type": "REQUEST_COUNT",
"queries": [
{
"title": "Number of successful incoming requests",
"query": "round(sum(increase(tgi_request_success{namespace='${NAMESPACE}', pod=~'${MODEL_NAME}-predictor-.*'}[${RATE_INTERVAL}])))"
"query": "round(sum(increase(tgi_request_success{namespace='${NAMESPACE}', pod=~'${MODEL_NAME}-predictor-.*'}[${REQUEST_RATE_INTERVAL}])))"
},
{
"title": "Number of failed incoming requests",
"query": "round(sum(increase(tgi_request_failure{namespace='${NAMESPACE}', pod=~'${MODEL_NAME}-predictor-.*'}[${RATE_INTERVAL}])))"
"query": "round(sum(increase(tgi_request_failure{namespace='${NAMESPACE}', pod=~'${MODEL_NAME}-predictor-.*'}[${REQUEST_RATE_INTERVAL}])))"
}
]
},
Expand Down Expand Up @@ -182,12 +182,12 @@ const (
VllmMetricsData = `{
"config": [
{
"title": "Number of requests",
"title": "Requests per 5 minutes",
"type": "REQUEST_COUNT",
"queries": [
{
"title": "Number of successful incoming requests",
"query": "round(sum(increase(vllm:request_success_total{namespace='${NAMESPACE}',model_name='${model_name}'}[${RATE_INTERVAL}])))"
"query": "round(sum(increase(vllm:request_success_total{namespace='${NAMESPACE}',model_name='${model_name}'}[${REQUEST_RATE_INTERVAL}])))"
}
]
},
Expand Down
18 changes: 7 additions & 11 deletions controllers/kserve_inferenceservice_controller_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package controllers

import (
"github.com/opendatahub-io/odh-model-controller/controllers/constants"
"github.com/opendatahub-io/odh-model-controller/controllers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"strings"
"time"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -73,8 +73,8 @@ var _ = Describe("The KServe Dashboard reconciler", func() {
Expect(err).NotTo(HaveOccurred())
Expect(metricsConfigMap).NotTo(BeNil())

finaldata := substituteVariablesInQueries(constants.OvmsMetricsData, testNs, KserveOvmsInferenceServiceName, constants.IntervalValue)
expectedmetricsConfigMap := &corev1.ConfigMap{
finaldata := utils.SubstituteVariablesInQueries(constants.OvmsMetricsData, testNs, KserveOvmsInferenceServiceName)
expectedMetricsConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: KserveOvmsInferenceServiceName + constants.KserveMetricsConfigMapNameSuffix,
Namespace: testNs,
Expand All @@ -84,7 +84,8 @@ var _ = Describe("The KServe Dashboard reconciler", func() {
"metrics": finaldata,
},
}
Expect(compareConfigMap(metricsConfigMap, expectedmetricsConfigMap)).Should(BeTrue())
Expect(compareConfigMap(metricsConfigMap, expectedMetricsConfigMap)).Should(BeTrue())
Expect(expectedMetricsConfigMap.Data).NotTo(HaveKeyWithValue("metrics", ContainSubstring("${REQUEST_RATE_INTERVAL}")))
})

It("if the runtime is not supported for metrics, it should create a configmap with the unsupported config", func() {
Expand All @@ -95,7 +96,7 @@ var _ = Describe("The KServe Dashboard reconciler", func() {
Expect(err).NotTo(HaveOccurred())
Expect(metricsConfigMap).NotTo(BeNil())

expectedmetricsConfigMap := &corev1.ConfigMap{
expectedMetricsConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: UnsupportedMetricsInferenceServiceName + constants.KserveMetricsConfigMapNameSuffix,
Namespace: testNs,
Expand All @@ -104,7 +105,7 @@ var _ = Describe("The KServe Dashboard reconciler", func() {
"supported": "false",
},
}
Expect(compareConfigMap(metricsConfigMap, expectedmetricsConfigMap)).Should(BeTrue())
Expect(compareConfigMap(metricsConfigMap, expectedMetricsConfigMap)).Should(BeTrue())
})

It("if the isvc does not have a runtime specified, an unsupported metrics configmap should be created", func() {
Expand Down Expand Up @@ -153,8 +154,3 @@ var _ = Describe("The KServe Dashboard reconciler", func() {
})
})
})

func substituteVariablesInQueries(data string, namespace string, name string, IntervalValue string) string {
replacer := strings.NewReplacer("${NAMESPACE}", namespace, "${MODEL_NAME}", name, "${RATE_INTERVAL}", IntervalValue)
return replacer.Replace(data)
}
19 changes: 6 additions & 13 deletions controllers/reconcilers/kserve_metrics_dashboard_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ package reconcilers

import (
"context"
"github.com/hashicorp/errwrap"
"github.com/opendatahub-io/odh-model-controller/controllers/utils"
"regexp"
ctrl "sigs.k8s.io/controller-runtime"
"strconv"
"strings"

"github.com/go-logr/logr"
"github.com/hashicorp/errwrap"
kservev1alpha1 "github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
kservev1beta1 "github.com/kserve/kserve/pkg/apis/serving/v1beta1"
"github.com/opendatahub-io/odh-model-controller/controllers/comparators"
"github.com/opendatahub-io/odh-model-controller/controllers/constants"
"github.com/opendatahub-io/odh-model-controller/controllers/processors"
"github.com/opendatahub-io/odh-model-controller/controllers/resources"
"github.com/opendatahub-io/odh-model-controller/controllers/utils"
"regexp"
ctrl "sigs.k8s.io/controller-runtime"
"strconv"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -146,19 +144,14 @@ func (r *KserveMetricsDashboardReconciler) createDesiredResource(ctx context.Con
return nil, err
}
if supported {
finaldata := substituteVariablesInQueries(data, isvc.Namespace, isvc.Name, constants.IntervalValue)
finaldata := utils.SubstituteVariablesInQueries(data, isvc.Namespace, isvc.Name)
configMap.Data["metrics"] = finaldata
}

return configMap, nil

}

func substituteVariablesInQueries(data string, namespace string, name string, IntervalValue string) string {
replacer := strings.NewReplacer("${NAMESPACE}", namespace, "${MODEL_NAME}", name, "${RATE_INTERVAL}", IntervalValue)
return replacer.Replace(data)
}

func (r *KserveMetricsDashboardReconciler) createConfigMap(isvc *kservev1beta1.InferenceService, supported bool, log logr.Logger) (*corev1.ConfigMap, error) {
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down
10 changes: 10 additions & 0 deletions controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"reflect"
"sort"
"strings"

kservev1beta1 "github.com/kserve/kserve/pkg/apis/serving/v1beta1"
"github.com/kuadrant/authorino/pkg/log"
Expand Down Expand Up @@ -399,3 +400,12 @@ func FindSupportingRuntimeForISvc(ctx context.Context, cli client.Client, log lo
return desiredServingRuntime, errors.New(constants.NoSuitableRuntimeError)
}
}

func SubstituteVariablesInQueries(data string, namespace string, name string) string {
replacer := strings.NewReplacer(
"${NAMESPACE}", namespace,
"${MODEL_NAME}", name,
"${RATE_INTERVAL}", constants.IntervalValue,
"${REQUEST_RATE_INTERVAL}", constants.RequestRateInterval)
return replacer.Replace(data)
}