mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
feat: add openim images config path
Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
parent
d28df4cbbb
commit
a029bdc0ca
@ -17,13 +17,14 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginPrometheus"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
|
||||||
"net"
|
"net"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
|
ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/kdisc"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/constant"
|
"github.com/OpenIMSDK/protocol/constant"
|
||||||
"github.com/OpenIMSDK/tools/discoveryregistry"
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
||||||
@ -65,7 +66,7 @@ func run(port int, proPort int) error {
|
|||||||
var client discoveryregistry.SvcDiscoveryRegistry
|
var client discoveryregistry.SvcDiscoveryRegistry
|
||||||
|
|
||||||
// Determine whether zk is passed according to whether it is a clustered deployment
|
// Determine whether zk is passed according to whether it is a clustered deployment
|
||||||
client, err = discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
client, err = kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(context.Background(), "Failed to initialize discovery register", err)
|
log.ZError(context.Background(), "Failed to initialize discovery register", err)
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ func run(port int, proPort int) error {
|
|||||||
router := api.NewGinRouter(client, rdb)
|
router := api.NewGinRouter(client, rdb)
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
if config.Config.Prometheus.Enable {
|
if config.Config.Prometheus.Enable {
|
||||||
p := ginProm.NewPrometheus("app", prom_metrics.GetGinCusMetrics("Api"))
|
p := ginProm.NewPrometheus("app", metrics.GetGinCusMetrics("Api"))
|
||||||
p.SetListenAddress(fmt.Sprintf(":%d", proPort))
|
p.SetListenAddress(fmt.Sprintf(":%d", proPort))
|
||||||
p.Use(router)
|
p.Use(router)
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,14 @@ package msggateway
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/msggateway"
|
"github.com/OpenIMSDK/protocol/msggateway"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||||
@ -221,7 +222,7 @@ func (ws *WsServer) registerClient(client *Client) {
|
|||||||
if !userOK {
|
if !userOK {
|
||||||
ws.clients.Set(client.UserID, client)
|
ws.clients.Set(client.UserID, client)
|
||||||
log.ZDebug(client.ctx, "user not exist", "userID", client.UserID, "platformID", client.PlatformID)
|
log.ZDebug(client.ctx, "user not exist", "userID", client.UserID, "platformID", client.PlatformID)
|
||||||
prom_metrics.OnlineUserGauge.Add(1)
|
metrics.OnlineUserGauge.Add(1)
|
||||||
ws.onlineUserNum.Add(1)
|
ws.onlineUserNum.Add(1)
|
||||||
ws.onlineUserConnNum.Add(1)
|
ws.onlineUserConnNum.Add(1)
|
||||||
} else {
|
} else {
|
||||||
@ -361,7 +362,7 @@ func (ws *WsServer) unregisterClient(client *Client) {
|
|||||||
isDeleteUser := ws.clients.delete(client.UserID, client.ctx.GetRemoteAddr())
|
isDeleteUser := ws.clients.delete(client.UserID, client.ctx.GetRemoteAddr())
|
||||||
if isDeleteUser {
|
if isDeleteUser {
|
||||||
ws.onlineUserNum.Add(-1)
|
ws.onlineUserNum.Add(-1)
|
||||||
prom_metrics.OnlineUserGauge.Dec()
|
metrics.OnlineUserGauge.Dec()
|
||||||
}
|
}
|
||||||
ws.onlineUserConnNum.Add(-1)
|
ws.onlineUserConnNum.Add(-1)
|
||||||
ws.SetUserOnlineStatus(client.ctx, client, constant.Offline)
|
ws.SetUserOnlineStatus(client.ctx, client, constant.Offline)
|
||||||
|
@ -17,16 +17,17 @@ package msgtransfer
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
|
"log"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/kdisc"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/mw"
|
"github.com/OpenIMSDK/tools/mw"
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ func StartTransfer(prometheusPort int) error {
|
|||||||
if err := mongo.CreateMsgIndex(); err != nil {
|
if err := mongo.CreateMsgIndex(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
client, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
client, err := kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
||||||
/*
|
/*
|
||||||
client, err := openkeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
|
client, err := openkeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
|
||||||
openkeeper.WithFreq(time.Hour), openkeeper.WithRoundRobin(), openkeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
|
openkeeper.WithFreq(time.Hour), openkeeper.WithRoundRobin(), openkeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
|
||||||
@ -123,7 +124,7 @@ func (m *MsgTransfer) Start(prometheusPort int) error {
|
|||||||
reg.MustRegister(
|
reg.MustRegister(
|
||||||
collectors.NewGoCollector(),
|
collectors.NewGoCollector(),
|
||||||
)
|
)
|
||||||
reg.MustRegister(prom_metrics.GetGrpcCusMetrics("Transfer")...)
|
reg.MustRegister(metrics.GetGrpcCusMetrics("Transfer")...)
|
||||||
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
|
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
|
||||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", prometheusPort), nil))
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", prometheusPort), nil))
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@ package msgtransfer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
|
|
||||||
"github.com/IBM/sarama"
|
"github.com/IBM/sarama"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
@ -75,9 +76,9 @@ func (mc *OnlineHistoryMongoConsumerHandler) handleChatWs2Mongo(
|
|||||||
"conversationID",
|
"conversationID",
|
||||||
msgFromMQ.ConversationID,
|
msgFromMQ.ConversationID,
|
||||||
)
|
)
|
||||||
prom_metrics.MsgInsertMongoFailedCounter.Inc()
|
metrics.MsgInsertMongoFailedCounter.Inc()
|
||||||
} else {
|
} else {
|
||||||
prom_metrics.MsgInsertMongoSuccessCounter.Inc()
|
metrics.MsgInsertMongoSuccessCounter.Inc()
|
||||||
}
|
}
|
||||||
var seqs []int64
|
var seqs []int64
|
||||||
for _, msg := range msgFromMQ.MsgData {
|
for _, msg := range msgFromMQ.MsgData {
|
||||||
|
@ -18,8 +18,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/dummy"
|
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/dummy"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/conversation"
|
"github.com/OpenIMSDK/protocol/conversation"
|
||||||
|
|
||||||
@ -288,7 +289,7 @@ func (p *Pusher) offlinePushMsg(ctx context.Context, conversationID string, msg
|
|||||||
}
|
}
|
||||||
err = p.offlinePusher.Push(ctx, offlinePushUserIDs, title, content, opts)
|
err = p.offlinePusher.Push(ctx, offlinePushUserIDs, title, content, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
prom_metrics.MsgOfflinePushFailedCounter.Inc()
|
metrics.MsgOfflinePushFailedCounter.Inc()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -16,7 +16,8 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ func (s *authServer) UserToken(ctx context.Context, req *pbauth.UserTokenReq) (*
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
prom_metrics.UserLoginCounter.Inc()
|
metrics.UserLoginCounter.Inc()
|
||||||
resp.Token = token
|
resp.Token = token
|
||||||
resp.ExpireTimeSeconds = config.Config.TokenPolicy.Expire * 24 * 60 * 60
|
resp.ExpireTimeSeconds = config.Config.TokenPolicy.Expire * 24 * 60 * 60
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
|
@ -16,7 +16,8 @@ package msg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ func (m *msgServer) sendMsgSuperGroupChat(
|
|||||||
req *pbmsg.SendMsgReq,
|
req *pbmsg.SendMsgReq,
|
||||||
) (resp *pbmsg.SendMsgResp, err error) {
|
) (resp *pbmsg.SendMsgResp, err error) {
|
||||||
if err = m.messageVerification(ctx, req); err != nil {
|
if err = m.messageVerification(ctx, req); err != nil {
|
||||||
prom_metrics.GroupChatMsgProcessFailedCounter.Inc()
|
metrics.GroupChatMsgProcessFailedCounter.Inc()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = callbackBeforeSendGroupMsg(ctx, req); err != nil {
|
if err = callbackBeforeSendGroupMsg(ctx, req); err != nil {
|
||||||
@ -78,7 +79,7 @@ func (m *msgServer) sendMsgSuperGroupChat(
|
|||||||
if err = callbackAfterSendGroupMsg(ctx, req); err != nil {
|
if err = callbackAfterSendGroupMsg(ctx, req); err != nil {
|
||||||
log.ZWarn(ctx, "CallbackAfterSendGroupMsg", err)
|
log.ZWarn(ctx, "CallbackAfterSendGroupMsg", err)
|
||||||
}
|
}
|
||||||
prom_metrics.GroupChatMsgProcessSuccessCounter.Inc()
|
metrics.GroupChatMsgProcessSuccessCounter.Inc()
|
||||||
resp = &pbmsg.SendMsgResp{}
|
resp = &pbmsg.SendMsgResp{}
|
||||||
resp.SendTime = req.MsgData.SendTime
|
resp.SendTime = req.MsgData.SendTime
|
||||||
resp.ServerMsgID = req.MsgData.ServerMsgID
|
resp.ServerMsgID = req.MsgData.ServerMsgID
|
||||||
@ -161,7 +162,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbmsg.SendMsgReq
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !isSend {
|
if !isSend {
|
||||||
prom_metrics.SingleChatMsgProcessFailedCounter.Inc()
|
metrics.SingleChatMsgProcessFailedCounter.Inc()
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else {
|
} else {
|
||||||
if err = callbackBeforeSendSingleMsg(ctx, req); err != nil {
|
if err = callbackBeforeSendSingleMsg(ctx, req); err != nil {
|
||||||
@ -171,7 +172,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbmsg.SendMsgReq
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := m.MsgDatabase.MsgToMQ(ctx, utils.GenConversationUniqueKeyForSingle(req.MsgData.SendID, req.MsgData.RecvID), req.MsgData); err != nil {
|
if err := m.MsgDatabase.MsgToMQ(ctx, utils.GenConversationUniqueKeyForSingle(req.MsgData.SendID, req.MsgData.RecvID), req.MsgData); err != nil {
|
||||||
prom_metrics.SingleChatMsgProcessFailedCounter.Inc()
|
metrics.SingleChatMsgProcessFailedCounter.Inc()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = callbackAfterSendSingleMsg(ctx, req)
|
err = callbackAfterSendSingleMsg(ctx, req)
|
||||||
@ -183,7 +184,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbmsg.SendMsgReq
|
|||||||
ClientMsgID: req.MsgData.ClientMsgID,
|
ClientMsgID: req.MsgData.ClientMsgID,
|
||||||
SendTime: req.MsgData.SendTime,
|
SendTime: req.MsgData.SendTime,
|
||||||
}
|
}
|
||||||
prom_metrics.SingleChatMsgProcessSuccessCounter.Inc()
|
metrics.SingleChatMsgProcessSuccessCounter.Inc()
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/kdisc"
|
||||||
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ func InitMsgTool() (*MsgTool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
discov, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
discov, err := kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
||||||
/*
|
/*
|
||||||
discov, err := zookeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
|
discov, err := zookeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
|
||||||
zookeeper.WithFreq(time.Hour), zookeeper.WithRoundRobin(), zookeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
|
zookeeper.WithFreq(time.Hour), zookeeper.WithRoundRobin(), zookeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
|
||||||
|
128
pkg/common/convert/friend_test.go
Normal file
128
pkg/common/convert/friend_test.go
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
// Copyright © 2023 OpenIM. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed 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.
|
||||||
|
|
||||||
|
package convert
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/OpenIMSDK/protocol/sdkws"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFriendPb2DB(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
friend *sdkws.FriendInfo
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want *relation.FriendModel
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := FriendPb2DB(tt.args.friend); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("FriendPb2DB() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFriendDB2Pb(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
friendDB *relation.FriendModel
|
||||||
|
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error)
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want *sdkws.FriendInfo
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := FriendDB2Pb(tt.args.ctx, tt.args.friendDB, tt.args.getUsers)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("FriendDB2Pb() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("FriendDB2Pb() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFriendsDB2Pb(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
friendsDB []*relation.FriendModel
|
||||||
|
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error)
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
wantFriendsPb []*sdkws.FriendInfo
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
gotFriendsPb, err := FriendsDB2Pb(tt.args.ctx, tt.args.friendsDB, tt.args.getUsers)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("FriendsDB2Pb() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(gotFriendsPb, tt.wantFriendsPb) {
|
||||||
|
t.Errorf("FriendsDB2Pb() = %v, want %v", gotFriendsPb, tt.wantFriendsPb)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFriendRequestDB2Pb(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
friendRequests []*relation.FriendRequestModel
|
||||||
|
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error)
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want []*sdkws.FriendRequest
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := FriendRequestDB2Pb(tt.args.ctx, tt.args.friendRequests, tt.args.getUsers)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("FriendRequestDB2Pb() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("FriendRequestDB2Pb() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,6 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
@ -31,6 +30,7 @@ import (
|
|||||||
unrelationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/unrelation"
|
unrelationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/unrelation"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/unrelation"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/unrelation"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/kafka"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/kafka"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
|
||||||
pbmsg "github.com/OpenIMSDK/protocol/msg"
|
pbmsg "github.com/OpenIMSDK/protocol/msg"
|
||||||
@ -376,20 +376,20 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
|
|||||||
}
|
}
|
||||||
failedNum, err := db.cache.SetMessageToCache(ctx, conversationID, msgs)
|
failedNum, err := db.cache.SetMessageToCache(ctx, conversationID, msgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
prom_metrics.MsgInsertRedisFailedCounter.Add(float64(failedNum))
|
metrics.MsgInsertRedisFailedCounter.Add(float64(failedNum))
|
||||||
log.ZError(ctx, "setMessageToCache error", err, "len", len(msgs), "conversationID", conversationID)
|
log.ZError(ctx, "setMessageToCache error", err, "len", len(msgs), "conversationID", conversationID)
|
||||||
} else {
|
} else {
|
||||||
prom_metrics.MsgInsertRedisSuccessCounter.Inc()
|
metrics.MsgInsertRedisSuccessCounter.Inc()
|
||||||
}
|
}
|
||||||
err = db.cache.SetMaxSeq(ctx, conversationID, currentMaxSeq)
|
err = db.cache.SetMaxSeq(ctx, conversationID, currentMaxSeq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, "db.cache.SetMaxSeq error", err, "conversationID", conversationID)
|
log.ZError(ctx, "db.cache.SetMaxSeq error", err, "conversationID", conversationID)
|
||||||
prom_metrics.SeqSetFailedCounter.Inc()
|
metrics.SeqSetFailedCounter.Inc()
|
||||||
}
|
}
|
||||||
err2 := db.cache.SetHasReadSeqs(ctx, conversationID, userSeqMap)
|
err2 := db.cache.SetHasReadSeqs(ctx, conversationID, userSeqMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, "SetHasReadSeqs error", err2, "userSeqMap", userSeqMap, "conversationID", conversationID)
|
log.ZError(ctx, "SetHasReadSeqs error", err2, "userSeqMap", userSeqMap, "conversationID", conversationID)
|
||||||
prom_metrics.SeqSetFailedCounter.Inc()
|
metrics.SeqSetFailedCounter.Inc()
|
||||||
}
|
}
|
||||||
return lastMaxSeq, isNew, utils.Wrap(err, "")
|
return lastMaxSeq, isNew, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
154
pkg/common/http/http_client_test.go
Normal file
154
pkg/common/http/http_client_test.go
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
// Copyright © 2023 OpenIM. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed 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.
|
||||||
|
|
||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGet(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
url string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
wantResponse []byte
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
gotResponse, err := Get(tt.args.url)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(gotResponse, tt.wantResponse) {
|
||||||
|
t.Errorf("Get() = %v, want %v", gotResponse, tt.wantResponse)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPost(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
url string
|
||||||
|
header map[string]string
|
||||||
|
data interface{}
|
||||||
|
timeout int
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
wantContent []byte
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
gotContent, err := Post(tt.args.ctx, tt.args.url, tt.args.header, tt.args.data, tt.args.timeout)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("Post() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(gotContent, tt.wantContent) {
|
||||||
|
t.Errorf("Post() = %v, want %v", gotContent, tt.wantContent)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostReturn(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
url string
|
||||||
|
header map[string]string
|
||||||
|
input interface{}
|
||||||
|
output interface{}
|
||||||
|
timeOutSecond int
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if err := PostReturn(tt.args.ctx, tt.args.url, tt.args.header, tt.args.input, tt.args.output, tt.args.timeOutSecond); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("PostReturn() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_callBackPostReturn(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
url string
|
||||||
|
command string
|
||||||
|
input interface{}
|
||||||
|
output callbackstruct.CallbackResp
|
||||||
|
callbackConfig config.CallBackConfig
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if err := callBackPostReturn(tt.args.ctx, tt.args.url, tt.args.command, tt.args.input, tt.args.output, tt.args.callbackConfig); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("callBackPostReturn() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCallBackPostReturn(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
url string
|
||||||
|
req callbackstruct.CallbackReq
|
||||||
|
resp callbackstruct.CallbackResp
|
||||||
|
callbackConfig config.CallBackConfig
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if err := CallBackPostReturn(tt.args.ctx, tt.args.url, tt.args.req, tt.args.resp, tt.args.callbackConfig); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("CallBackPostReturn() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package discovery_register
|
package kdisc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
157
pkg/common/locker/message_locker_test.go
Normal file
157
pkg/common/locker/message_locker_test.go
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
// Copyright © 2023 OpenIM. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed 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.
|
||||||
|
|
||||||
|
package locker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewLockerMessage(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
cache cache.MsgModel
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want *LockerMessage
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := NewLockerMessage(tt.args.cache); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("NewLockerMessage() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLockerMessage_LockMessageTypeKey(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
cache cache.MsgModel
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
clientMsgID string
|
||||||
|
typeKey string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
l := &LockerMessage{
|
||||||
|
cache: tt.fields.cache,
|
||||||
|
}
|
||||||
|
if err := l.LockMessageTypeKey(tt.args.ctx, tt.args.clientMsgID, tt.args.typeKey); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("LockerMessage.LockMessageTypeKey() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLockerMessage_LockGlobalMessage(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
cache cache.MsgModel
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
clientMsgID string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
l := &LockerMessage{
|
||||||
|
cache: tt.fields.cache,
|
||||||
|
}
|
||||||
|
if err := l.LockGlobalMessage(tt.args.ctx, tt.args.clientMsgID); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("LockerMessage.LockGlobalMessage() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLockerMessage_UnLockMessageTypeKey(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
cache cache.MsgModel
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
clientMsgID string
|
||||||
|
typeKey string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
l := &LockerMessage{
|
||||||
|
cache: tt.fields.cache,
|
||||||
|
}
|
||||||
|
if err := l.UnLockMessageTypeKey(tt.args.ctx, tt.args.clientMsgID, tt.args.typeKey); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("LockerMessage.UnLockMessageTypeKey() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLockerMessage_UnLockGlobalMessage(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
cache cache.MsgModel
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
ctx context.Context
|
||||||
|
clientMsgID string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
l := &LockerMessage{
|
||||||
|
cache: tt.fields.cache,
|
||||||
|
}
|
||||||
|
if err := l.UnLockGlobalMessage(tt.args.ctx, tt.args.clientMsgID); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("LockerMessage.UnLockGlobalMessage() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package prom_metrics
|
package prom_metrics
|
||||||
|
|
||||||
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginPrometheus"
|
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
labels := prometheus.Labels{"label_one": "any", "label_two": "value"}
|
labels := prometheus.Labels{"label_one": "any", "label_two": "value"}
|
@ -3,7 +3,7 @@ package prom_metrics
|
|||||||
import (
|
import (
|
||||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/ginPrometheus"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
)
|
)
|
||||||
@ -35,11 +35,11 @@ func GetGrpcCusMetrics(registerName string) []prometheus.Collector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGinCusMetrics(name string) []*ginPrometheus.Metric {
|
func GetGinCusMetrics(name string) []*ginprom.Metric {
|
||||||
switch name {
|
switch name {
|
||||||
case "Api":
|
case "Api":
|
||||||
return []*ginPrometheus.Metric{ApiCustomCnt}
|
return []*ginprom.Metric{ApiCustomCnt}
|
||||||
default:
|
default:
|
||||||
return []*ginPrometheus.Metric{ApiCustomCnt}
|
return []*ginprom.Metric{ApiCustomCnt}
|
||||||
}
|
}
|
||||||
}
|
}
|
80
pkg/common/metrics/metrics_test.go
Normal file
80
pkg/common/metrics/metrics_test.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package prom_metrics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewGrpcPromObj(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
cusMetrics []prometheus.Collector
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want *prometheus.Registry
|
||||||
|
want1 *grpc_prometheus.ServerMetrics
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, got1, err := NewGrpcPromObj(tt.args.cusMetrics)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("NewGrpcPromObj() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("NewGrpcPromObj() got = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got1, tt.want1) {
|
||||||
|
t.Errorf("NewGrpcPromObj() got1 = %v, want %v", got1, tt.want1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetGrpcCusMetrics(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
registerName string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want []prometheus.Collector
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := GetGrpcCusMetrics(tt.args.registerName); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("GetGrpcCusMetrics() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetGinCusMetrics(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want []*ginprom.Metric
|
||||||
|
}{
|
||||||
|
// TODO: Add test cases.
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := GetGinCusMetrics(tt.args.name); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("GetGinCusMetrics() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -16,16 +16,17 @@ package startrpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/metrics"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/kdisc"
|
||||||
|
|
||||||
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -55,7 +56,7 @@ func Start(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
client, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
client, err := kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return utils.Wrap1(err)
|
return utils.Wrap1(err)
|
||||||
}
|
}
|
||||||
@ -70,8 +71,8 @@ func Start(
|
|||||||
// ctx 中间件
|
// ctx 中间件
|
||||||
if config.Config.Prometheus.Enable {
|
if config.Config.Prometheus.Enable {
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
cusMetrics := prom_metrics.GetGrpcCusMetrics(rpcRegisterName)
|
cusMetrics := metrics.GetGrpcCusMetrics(rpcRegisterName)
|
||||||
reg, metric, err = prom_metrics.NewGrpcPromObj(cusMetrics)
|
reg, metric, err = metrics.NewGrpcPromObj(cusMetrics)
|
||||||
options = append(options, mw.GrpcServer(), grpc.StreamInterceptor(metric.StreamServerInterceptor()),
|
options = append(options, mw.GrpcServer(), grpc.StreamInterceptor(metric.StreamServerInterceptor()),
|
||||||
grpc.UnaryInterceptor(metric.UnaryServerInterceptor()))
|
grpc.UnaryInterceptor(metric.UnaryServerInterceptor()))
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user