2021-12-13 19:45:33 +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-04-19 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-13 19:45:33 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-12-13 19:45:33 +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-04-19 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-09-16 15:21:10 +08:00
|
|
|
|
2020-11-16 17:01:10 +08:00
|
|
|
import (
|
2021-11-12 18:27:10 +08:00
|
|
|
"context"
|
2020-11-16 17:01:10 +08:00
|
|
|
"testing"
|
|
|
|
|
2022-03-03 21:57:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream"
|
2021-02-04 14:37:12 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-11-16 17:01:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// NOTE: start pulsar before test
|
|
|
|
func TestStatsService_start(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2021-02-08 14:30:54 +08:00
|
|
|
|
2021-04-02 13:48:25 +08:00
|
|
|
msFactory := msgstream.NewPmsFactory()
|
2021-02-08 14:30:54 +08:00
|
|
|
m := map[string]interface{}{
|
2022-01-09 23:45:33 +08:00
|
|
|
"PulsarAddress": Params.PulsarCfg.Address,
|
2021-02-08 14:30:54 +08:00
|
|
|
"ReceiveBufSize": 1024,
|
|
|
|
"PulsarBufSize": 1024}
|
|
|
|
msFactory.SetParams(m)
|
2022-02-08 21:57:46 +08:00
|
|
|
node.statsService = newStatsService(node.queryNodeLoopCtx, node.historical.replica, msFactory)
|
2021-11-12 18:27:10 +08:00
|
|
|
node.statsService.start()
|
2021-01-21 15:20:23 +08:00
|
|
|
node.Stop()
|
2020-11-16 17:01:10 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
//NOTE: start pulsar before test
|
2020-12-10 16:31:09 +08:00
|
|
|
func TestSegmentManagement_sendSegmentStatistic(t *testing.T) {
|
2021-11-12 18:27:10 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
2020-11-16 17:01:10 +08:00
|
|
|
|
|
|
|
const receiveBufSize = 1024
|
|
|
|
// start pulsar
|
2022-02-02 00:35:43 +08:00
|
|
|
producerChannels := []string{Params.MsgChannelCfg.QueryNodeStats}
|
2020-11-16 17:01:10 +08:00
|
|
|
|
2021-04-02 13:48:25 +08:00
|
|
|
msFactory := msgstream.NewPmsFactory()
|
2021-02-08 14:30:54 +08:00
|
|
|
m := map[string]interface{}{
|
|
|
|
"receiveBufSize": receiveBufSize,
|
2022-01-09 23:45:33 +08:00
|
|
|
"pulsarAddress": Params.PulsarCfg.Address,
|
2021-02-08 14:30:54 +08:00
|
|
|
"pulsarBufSize": 1024}
|
2021-11-12 18:27:10 +08:00
|
|
|
err = msFactory.SetParams(m)
|
2021-02-08 14:30:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
statsStream, err := msFactory.NewMsgStream(node.queryNodeLoopCtx)
|
2021-02-04 14:37:12 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
statsStream.AsProducer(producerChannels)
|
2020-11-16 17:01:10 +08:00
|
|
|
|
|
|
|
var statsMsgStream msgstream.MsgStream = statsStream
|
|
|
|
|
2022-02-08 21:57:46 +08:00
|
|
|
node.statsService = newStatsService(node.queryNodeLoopCtx, node.historical.replica, msFactory)
|
2021-11-12 18:27:10 +08:00
|
|
|
node.statsService.statsStream = statsMsgStream
|
|
|
|
node.statsService.statsStream.Start()
|
2020-11-16 17:01:10 +08:00
|
|
|
|
|
|
|
// send stats
|
2021-11-12 18:27:10 +08:00
|
|
|
node.statsService.publicStatistic(nil)
|
2021-01-21 15:20:23 +08:00
|
|
|
node.Stop()
|
2020-11-16 17:01:10 +08:00
|
|
|
}
|