/
server.go
48 lines (40 loc) · 1.31 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package server
import (
"log"
"github.com/go-kratos/kratos/contrib/registry/nacos/v2"
"github.com/go-kratos/kratos/v2/registry"
"github.com/google/wire"
"github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
"github.com/prometheus/client_golang/prometheus"
)
// ProviderSet is server providers.
var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer, NewRegistrar)
var _metricSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "server",
Subsystem: "requests",
Name: "duration_ms",
Help: "server requests duration(ms).",
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
}, []string{"kind", "operation"})
var _metricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "client",
Subsystem: "requests",
Name: "code_total",
Help: "The total number of processed requests",
}, []string{"kind", "operation", "code", "reason"})
func NewRegistrar(sc []constant.ServerConfig, cc constant.ClientConfig) registry.Registrar {
client, err := clients.NewNamingClient(
vo.NacosClientParam{
ServerConfigs: sc,
ClientConfig: &cc,
},
)
if err != nil {
log.Panic(err)
}
prometheus.MustRegister(_metricSeconds, _metricRequests)
r := nacos.New(client)
return r
}