Skip to content

Commit

Permalink
Fix displaying model and transformer logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arief Rahmansyah committed Oct 23, 2023
1 parent 7a32f96 commit e737ada
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 47 deletions.
4 changes: 2 additions & 2 deletions api/models/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

const (
revisionPrefix = "r"
RevisionPrefix = "r"
)

type Service struct {
Expand Down Expand Up @@ -113,7 +113,7 @@ func CreateInferenceServiceName(modelName, versionID, revisionID string) string
// This is for backward compatibility, when the endpoint / isvc name didn't include the revision number
return fmt.Sprintf("%s-%s", modelName, versionID)
}
return fmt.Sprintf("%s-%s-%s%s", modelName, versionID, revisionPrefix, revisionID)
return fmt.Sprintf("%s-%s-%s%s", modelName, versionID, RevisionPrefix, revisionID)
}

func GetInferenceURL(url *apis.URL, inferenceServiceName string, protocolValue protocol.Protocol) string {
Expand Down
25 changes: 21 additions & 4 deletions api/service/log_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/fatih/color"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"

"github.com/caraml-dev/merlin/cluster"
"github.com/caraml-dev/merlin/log"
Expand Down Expand Up @@ -197,17 +199,31 @@ func (l logService) getPodsLogs(ctx context.Context, clusterController cluster.C
}

func (l logService) getLabelSelector(query LogQuery) string {
modelVersionName := query.ModelName + "-" + query.VersionID

onlineServingLabelVals := []string{modelVersionName}
for i := 1; i <= query.RevisionID; i++ {
onlineServingLabelVals = append(onlineServingLabelVals, fmt.Sprintf("%s-%s%d", modelVersionName, models.RevisionPrefix, i))
}
onlineServingReq, _ := labels.NewRequirement(KserveIsvcLabelKey, selection.In, onlineServingLabelVals)

switch query.ComponentType {
case models.ImageBuilderComponentType:
if query.PredictionJobID == "" {
return ImageBuilderLabelKey + "=" + query.ProjectName + "-" + query.ModelName + "-" + query.VersionID
return ImageBuilderLabelKey + "=" + query.ProjectName + "-" + modelVersionName
} else {
return ImageBuilderLabelKey + "=batch-" + query.ProjectName + "-" + query.ModelName + "-" + query.VersionID
return ImageBuilderLabelKey + "=batch-" + query.ProjectName + "-" + modelVersionName
}
case models.ModelComponentType:
return "component=predictor," + KserveIsvcLabelKey + "=" + query.ModelName + "-" + query.VersionID
predictorReq, _ := labels.NewRequirement("component", selection.Equals, []string{"predictor"})
predictor := labels.NewSelector()
predictor = predictor.Add(*predictorReq, *onlineServingReq)
return predictor.String()
case models.TransformerComponentType:
return "component=transformer," + KserveIsvcLabelKey + "=" + query.ModelName + "-" + query.VersionID
transformerReq, _ := labels.NewRequirement("component", selection.Equals, []string{"transformer"})
transformer := labels.NewSelector()
transformer = transformer.Add(*transformerReq, *onlineServingReq)
return transformer.String()
case models.BatchJobDriverComponentType:
return "spark-role=driver," + BatchPredictionJobLabelKey + "=" + query.PredictionJobID
case models.BatchJobExecutorComponentType:
Expand Down Expand Up @@ -298,6 +314,7 @@ type LogQuery struct {
ModelID string `schema:"model_id"`
ModelName string `schema:"model_name"`
VersionID string `schema:"version_id"`
RevisionID int `schema:"revision_id"`
PredictionJobID string `schema:"prediction_job_id"`

Cluster string `schema:"cluster,required"`
Expand Down
140 changes: 131 additions & 9 deletions api/service/log_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import (
"testing"
"time"

"github.com/caraml-dev/merlin/cluster"
"github.com/caraml-dev/merlin/cluster/mocks"
"github.com/fatih/color"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/caraml-dev/merlin/cluster"
"github.com/caraml-dev/merlin/cluster/mocks"
)

func TestLogLine_generateText(t *testing.T) {
Expand Down Expand Up @@ -137,6 +136,7 @@ func Test_logService_StreamLogs(t *testing.T) {
ModelID: "1",
ModelName: "test-model",
VersionID: "1",
RevisionID: 2,

Cluster: "test-cluster",
Namespace: "test-namespace",
Expand All @@ -150,15 +150,15 @@ func Test_logService_StreamLogs(t *testing.T) {
"test-cluster": mockController,
}

mockController.On("ListPods", context.Background(), "test-namespace", "component=predictor,serving.kserve.io/inferenceservice=test-model-1").
mockController.On("ListPods", context.Background(), "test-namespace", "component=predictor,serving.kserve.io/inferenceservice in (test-model-1,test-model-1-r1,test-model-1-r2)").
Return(&v1.PodList{
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
Name: "test-model-1-predictor-a",
Name: "test-model-1-r2-predictor-a",
Labels: map[string]string{
"component": "predictor",
"serving.kserve.io/inferenceservice": "test-model-1",
"serving.kserve.io/inferenceservice": "test-model-1-r2",
},
},
Spec: v1.PodSpec{
Expand All @@ -174,10 +174,10 @@ func Test_logService_StreamLogs(t *testing.T) {
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "test-model-1-predictor-b",
Name: "test-model-1-r2-predictor-b",
Labels: map[string]string{
"component": "predictor",
"serving.kserve.io/inferenceservice": "test-model-1",
"serving.kserve.io/inferenceservice": "test-model-1-r2",
},
},
Spec: v1.PodSpec{
Expand All @@ -194,7 +194,7 @@ func Test_logService_StreamLogs(t *testing.T) {
},
}, nil)

pods := []string{"test-model-1-predictor-a", "test-model-1-predictor-b"}
pods := []string{"test-model-1-r2-predictor-a", "test-model-1-r2-predictor-b"}
containers := []string{"storage-initializer", "kfserving-container", "inferenceservice-logger"}

for _, pod := range pods {
Expand Down Expand Up @@ -226,3 +226,125 @@ func Test_logService_StreamLogs(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 6, len(got))
}

func Test_logService_getLabelSelector(t *testing.T) {
type fields struct {
clusterControllers map[string]cluster.Controller
}
type args struct {
query LogQuery
}
tests := []struct {
name string
fields fields
args args
want string
}{
{
name: "model without revision",
fields: fields{},
args: args{query: LogQuery{
ComponentType: "model",
ProjectName: "test-project",
ModelName: "test-model",
VersionID: "1",
RevisionID: 0,
}},
want: "component=predictor,serving.kserve.io/inferenceservice in (test-model-1)",
},
{
name: "model name with number without revision",
fields: fields{},
args: args{query: LogQuery{
ComponentType: "model",
ProjectName: "test-project",
ModelName: "test-model-0-1-2",
VersionID: "10",
RevisionID: 0,
}},
want: "component=predictor,serving.kserve.io/inferenceservice in (test-model-0-1-2-10)",
},
{
name: "model with revision",
fields: fields{},
args: args{query: LogQuery{
ComponentType: "model",
ProjectName: "test-project",
ModelName: "test-model",
VersionID: "1",
RevisionID: 3,
}},
want: "component=predictor,serving.kserve.io/inferenceservice in (test-model-1,test-model-1-r1,test-model-1-r2,test-model-1-r3)",
},
{
name: "model name with number with revision",
fields: fields{},
args: args{query: LogQuery{
ComponentType: "model",
ProjectName: "test-project",
ModelName: "test-model-0-1-2",
VersionID: "10",
RevisionID: 2,
}},
want: "component=predictor,serving.kserve.io/inferenceservice in (test-model-0-1-2-10,test-model-0-1-2-10-r1,test-model-0-1-2-10-r2)",
},
{
name: "transformer without revision",
fields: fields{},
args: args{query: LogQuery{
ComponentType: "transformer",
ProjectName: "test-project",
ModelName: "test-model",
VersionID: "1",
RevisionID: 0,
}},
want: "component=transformer,serving.kserve.io/inferenceservice in (test-model-1)",
},
{
name: "transformer name with number without revision",
fields: fields{},
args: args{query: LogQuery{
ComponentType: "transformer",
ProjectName: "test-project",
ModelName: "test-model-0-1-2",
VersionID: "10",
RevisionID: 0,
}},
want: "component=transformer,serving.kserve.io/inferenceservice in (test-model-0-1-2-10)",
},
{
name: "transformer with revision",
fields: fields{},
args: args{query: LogQuery{
ComponentType: "transformer",
ProjectName: "test-project",
ModelName: "test-model",
VersionID: "1",
RevisionID: 3,
}},
want: "component=transformer,serving.kserve.io/inferenceservice in (test-model-1,test-model-1-r1,test-model-1-r2,test-model-1-r3)",
},
{
name: "transformer name with number with revision",
fields: fields{},
args: args{query: LogQuery{
ComponentType: "transformer",
ProjectName: "test-project",
ModelName: "test-model-0-1-2",
VersionID: "10",
RevisionID: 2,
}},
want: "component=transformer,serving.kserve.io/inferenceservice in (test-model-0-1-2-10,test-model-0-1-2-10-r1,test-model-0-1-2-10-r2)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
l := logService{
clusterControllers: tt.fields.clusterControllers,
}
if got := l.getLabelSelector(tt.args.query); got != tt.want {
t.Errorf("logService.getLabelSelector() = %v, want %v", got, tt.want)
}
})
}
}
6 changes: 3 additions & 3 deletions api/service/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
Cluster: "cluster1",
IsDefault: &isDefault,
}
labels = mlp.Labels{
mlpLabels = mlp.Labels{
{
Key: "sample",
Value: "true",
Expand All @@ -29,7 +29,7 @@ var (
Name: "project-1",
Team: "dsp",
Stream: "dsp",
Labels: labels,
Labels: mlpLabels,
},
ExperimentID: 1,

Expand Down Expand Up @@ -100,7 +100,7 @@ var (
Name: "project-1",
Team: "dsp",
Stream: "dsp",
Labels: labels,
Labels: mlpLabels,
},
ExperimentID: 1,

Expand Down
Loading

0 comments on commit e737ada

Please sign in to comment.