2021-10-27 18:04:47 +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
|
2021-08-19 10:28:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-27 18:04:47 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-08-19 10:28:10 +08:00
|
|
|
//
|
2021-10-27 18:04:47 +08:00
|
|
|
// 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.
|
2021-08-19 10:28:10 +08:00
|
|
|
|
|
|
|
package indexcoord
|
|
|
|
|
|
|
|
import (
|
2021-09-08 14:23:59 +08:00
|
|
|
"context"
|
2021-08-19 10:28:10 +08:00
|
|
|
"testing"
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2021-09-08 14:23:59 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/indexnode"
|
2022-04-07 22:05:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2021-12-29 14:35:21 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/etcd"
|
2021-09-08 14:23:59 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2021-08-19 10:28:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetSystemInfoMetrics(t *testing.T) {
|
2021-09-08 14:23:59 +08:00
|
|
|
ctx := context.Background()
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ic, err := NewIndexCoord(ctx, factory)
|
2021-09-08 14:23:59 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
Params.Init()
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
2021-12-29 14:35:21 +08:00
|
|
|
defer etcdCli.Close()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
ic.SetEtcdClient(etcdCli)
|
2021-09-08 14:23:59 +08:00
|
|
|
err = ic.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = ic.Start()
|
|
|
|
assert.Nil(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
err = ic.Register()
|
|
|
|
assert.Nil(t, err)
|
2021-09-08 14:23:59 +08:00
|
|
|
|
|
|
|
t.Run("getSystemInfoMetrics", func(t *testing.T) {
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
resp, err := getSystemInfoMetrics(ctx, req, ic)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, resp)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("getSystemInfoMetrics error", func(t *testing.T) {
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
inm1 := &indexnode.Mock{
|
|
|
|
Failure: true,
|
|
|
|
Err: true,
|
|
|
|
}
|
|
|
|
inm2 := &indexnode.Mock{
|
|
|
|
Failure: true,
|
|
|
|
Err: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
ic.nodeManager.setClient(1, inm1)
|
|
|
|
ic.nodeManager.setClient(2, inm2)
|
|
|
|
|
|
|
|
resp, err := getSystemInfoMetrics(ctx, req, ic)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, resp)
|
|
|
|
})
|
|
|
|
|
|
|
|
err = ic.Stop()
|
|
|
|
assert.Nil(t, err)
|
2021-08-19 10:28:10 +08:00
|
|
|
}
|