2023-01-04 19:37:36 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
package indexnode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2023-06-25 14:38:44 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-08-25 15:48:54 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
2022-08-25 15:48:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
2022-12-16 10:03:27 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2023-09-15 10:09:21 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
|
2022-08-25 15:48:54 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAbnormalIndexNode(t *testing.T) {
|
|
|
|
in, err := NewMockIndexNodeComponent(context.TODO())
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-08-25 15:48:54 +08:00
|
|
|
assert.Nil(t, in.Stop())
|
|
|
|
ctx := context.TODO()
|
|
|
|
status, err := in.CreateJob(ctx, &indexpb.CreateJobRequest{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-18 14:05:28 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(status), merr.ErrServiceNotReady)
|
2022-08-25 15:48:54 +08:00
|
|
|
|
|
|
|
qresp, err := in.QueryJobs(ctx, &indexpb.QueryJobsRequest{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-18 14:05:28 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(qresp.GetStatus()), merr.ErrServiceNotReady)
|
2022-08-25 15:48:54 +08:00
|
|
|
|
|
|
|
status, err = in.DropJobs(ctx, &indexpb.DropJobsRequest{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-18 14:05:28 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(status), merr.ErrServiceNotReady)
|
2022-08-25 15:48:54 +08:00
|
|
|
|
|
|
|
jobNumRsp, err := in.GetJobStats(ctx, &indexpb.GetJobStatsRequest{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-18 14:05:28 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(jobNumRsp.GetStatus()), merr.ErrServiceNotReady)
|
2022-08-25 15:48:54 +08:00
|
|
|
|
|
|
|
metricsResp, err := in.GetMetrics(ctx, &milvuspb.GetMetricsRequest{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.Equal(t, metricsResp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
2022-12-16 10:03:27 +08:00
|
|
|
|
|
|
|
configurationResp, err := in.ShowConfigurations(ctx, &internalpb.ShowConfigurationsRequest{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.Equal(t, configurationResp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
2022-08-25 15:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMetrics(t *testing.T) {
|
|
|
|
var (
|
|
|
|
ctx = context.TODO()
|
|
|
|
metricReq, _ = metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
|
|
|
)
|
|
|
|
in, err := NewMockIndexNodeComponent(ctx)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-01-19 14:53:44 +08:00
|
|
|
defer in.Stop()
|
2022-08-25 15:48:54 +08:00
|
|
|
resp, err := in.GetMetrics(ctx, metricReq)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.True(t, merr.Ok(resp.GetStatus()))
|
2022-08-25 15:48:54 +08:00
|
|
|
t.Logf("Component: %s, Metrics: %s", resp.ComponentName, resp.Response)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMetricsError(t *testing.T) {
|
2023-09-21 09:45:27 +08:00
|
|
|
ctx := context.TODO()
|
2022-08-25 15:48:54 +08:00
|
|
|
|
|
|
|
in, err := NewMockIndexNodeComponent(ctx)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-01-19 14:53:44 +08:00
|
|
|
defer in.Stop()
|
2022-08-25 15:48:54 +08:00
|
|
|
errReq := &milvuspb.GetMetricsRequest{
|
|
|
|
Request: `{"metric_typ": "system_info"}`,
|
|
|
|
}
|
|
|
|
resp, err := in.GetMetrics(ctx, errReq)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
2022-08-25 15:48:54 +08:00
|
|
|
|
|
|
|
unsupportedReq := &milvuspb.GetMetricsRequest{
|
|
|
|
Request: `{"metric_type": "application_info"}`,
|
|
|
|
}
|
|
|
|
resp, err = in.GetMetrics(ctx, unsupportedReq)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-30 10:31:28 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp.GetStatus()), merr.ErrMetricNotFound)
|
2022-08-25 15:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMockFieldData(t *testing.T) {
|
|
|
|
chunkMgr := NewMockChunkManager()
|
|
|
|
|
|
|
|
chunkMgr.mockFieldData(100000, 8, 0, 0, 1)
|
|
|
|
}
|