Skip to content

Commit aa11ac2

Browse files
authored
[ISSUE polarismesh#990] 新增服务端相关指标的上报&调整statis插件的相关逻辑 (polarismesh#939)
1 parent 90943c6 commit aa11ac2

File tree

160 files changed

+2603
-1425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+2603
-1425
lines changed

.github/workflows/integration-testing-mysql.yml

+2-11
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
work_dir=$(ls | grep polaris-server-release | sed -n '1p')
123123
echo "work_dir is $work_dir"
124124
125-
cp -rf ./testdata/polaris-server.yaml $work_dir/
125+
cp -rf ./test/data/polaris-server.yaml $work_dir/
126126
127127
cd $work_dir
128128
@@ -148,7 +148,7 @@ jobs:
148148
cd ..
149149
ls -lstrh
150150
# 先测试普通的集成测试
151-
pushd ./test
151+
pushd ./test/integrate
152152
echo "[INTEGRATION TEST] begin"
153153
curl http://127.0.0.1:8090
154154
go test -count=1 -v -tags integration -timeout 60m
@@ -157,12 +157,3 @@ jobs:
157157
cd $work_dir
158158
./tool/stop.sh
159159
cd ..
160-
161-
162-
163-
# - name: run config-center interface tests
164-
# run: |
165-
# # 进行配置中心的集成测试
166-
# pushd ./test/config_center
167-
# go test -count=1 -v
168-
# popd

.github/workflows/integration-testing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
cd ..
106106
ls -lstrh
107107
# 先测试普通的集成测试
108-
pushd ./test
108+
pushd ./test/integrate
109109
echo "[INTEGRATION TEST] begin"
110110
curl http://127.0.0.1:8090
111111
go test -count=1 -v -tags integration

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Checkout code
3636
uses: actions/checkout@v2
3737

38-
- name: Set up Go
38+
- name: Setup Go
3939
uses: actions/setup-go@v2
4040
with:
4141
go-version: 1.19

.github/workflows/standalone.yml

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ jobs:
4848
with:
4949
ref: ${{ github.event.inputs.server_version }}
5050

51+
- name: Setup Go
52+
uses: actions/setup-go@v2
53+
with:
54+
go-version: 1.19
55+
5156
- name: Build
5257
id: build
5358
env:

.licenserc.yaml

+12-8
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,27 @@ header: # `header` section is configurations for source codes license header.
5353
- "**"
5454

5555
paths-ignore: # `paths-ignore` are the path list that will be ignored by license-eye.
56-
- "**/*.md"
56+
# folder
57+
- "common/api/protoc"
58+
- "deploy"
59+
- "release"
5760
- "**/testdata/**"
58-
- "**/go.mod"
59-
- "**/go.sum"
61+
62+
# single file
6063
- "LICENSE"
6164
- ".gitignore"
6265
- "Makefile"
6366
- "Dockerfile"
64-
- "**/*.pb.go"
6567
- "version"
6668
- ".golangci.yml"
6769
- ".github"
68-
- "deploy"
69-
- "**/*.proto"
7070
- "logo.svg"
71-
- "release"
72-
- "common/api/protoc"
71+
- "**/*.pb.go"
72+
- "**/*_mock.go"
73+
- "**/*.proto"
74+
- "**/*.md"
75+
- "**/go.mod"
76+
- "**/go.sum"
7377
comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.
7478

7579
# license-location-threshold specifies the index threshold where the license header can be located,

apiserver/eurekaserver/eureka_suit_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ import (
4242
_ "github.com/polarismesh/polaris/plugin/password"
4343
_ "github.com/polarismesh/polaris/plugin/ratelimit/lrurate"
4444
_ "github.com/polarismesh/polaris/plugin/ratelimit/token"
45-
_ "github.com/polarismesh/polaris/plugin/statis/local"
45+
_ "github.com/polarismesh/polaris/plugin/statis/logger"
46+
_ "github.com/polarismesh/polaris/plugin/statis/prometheus"
4647
"github.com/polarismesh/polaris/service"
4748
"github.com/polarismesh/polaris/service/batch"
4849
"github.com/polarismesh/polaris/service/healthcheck"
4950
"github.com/polarismesh/polaris/store"
5051
storemock "github.com/polarismesh/polaris/store/mock"
51-
"github.com/polarismesh/polaris/testdata"
52+
testdata "github.com/polarismesh/polaris/test/data"
5253
)
5354

5455
type Bootstrap struct {

apiserver/eurekaserver/server.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/polarismesh/polaris/apiserver"
3434
connlimit "github.com/polarismesh/polaris/common/conn/limit"
3535
"github.com/polarismesh/polaris/common/eventhub"
36+
"github.com/polarismesh/polaris/common/metrics"
3637
"github.com/polarismesh/polaris/common/secure"
3738
"github.com/polarismesh/polaris/common/utils"
3839
"github.com/polarismesh/polaris/plugin"
@@ -461,7 +462,12 @@ func (h *EurekaServer) postproccess(req *restful.Request, rsp *restful.Response)
461462
method := getEurekaApi(req.Request.Method, path)
462463

463464
if recordApiCall {
464-
_ = h.statis.AddAPICall(method, "HTTP", int(code), diff.Nanoseconds())
465+
h.statis.ReportCallMetrics(metrics.CallMetric{
466+
API: method,
467+
Protocol: "HTTP",
468+
Code: int(code),
469+
Duration: diff,
470+
})
465471
}
466472
}
467473

apiserver/eurekaserver/write_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestEurekaServer_renew(t *testing.T) {
113113
}, nil)
114114

115115
s.EXPECT().GetInstancesCount().AnyTimes().Return(uint32(1), nil)
116-
s.EXPECT().GetUnixSecond().AnyTimes().Return(time.Now().Unix(), nil)
116+
s.EXPECT().GetUnixSecond(gomock.Any()).AnyTimes().Return(time.Now().Unix(), nil)
117117
s.EXPECT().GetServicesCount().Return(uint32(1), nil).AnyTimes()
118118
s.EXPECT().Destroy().Return(nil)
119119
return nil

apiserver/grpcserver/base.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,13 @@ func (b *BaseGrpcServer) streamInterceptor(srv interface{}, ss grpc.ServerStream
271271
)
272272
}
273273

274-
_ = b.statis.AddAPICall(stream.Method, "gRPC", stream.Code, 0)
274+
b.statis.ReportCallMetrics(metrics.CallMetric{
275+
Type: metrics.ServerCallMetric,
276+
API: stream.Method,
277+
Protocol: "gRPC",
278+
Code: int(stream.Code),
279+
Duration: 0,
280+
})
275281
}
276282
return
277283
}
@@ -334,8 +340,7 @@ func (b *BaseGrpcServer) postprocess(stream *VirtualStream, m interface{}) {
334340
}
335341

336342
// 接口调用统计
337-
now := time.Now()
338-
diff := now.Sub(stream.StartTime)
343+
diff := time.Since(stream.StartTime)
339344

340345
// 打印耗时超过1s的请求
341346
if diff > time.Second {
@@ -347,7 +352,14 @@ func (b *BaseGrpcServer) postprocess(stream *VirtualStream, m interface{}) {
347352
zap.Duration("handling-time", diff),
348353
)
349354
}
350-
_ = b.statis.AddAPICall(stream.Method, "gRPC", code, diff.Nanoseconds())
355+
356+
b.statis.ReportCallMetrics(metrics.CallMetric{
357+
Type: metrics.ServerCallMetric,
358+
API: stream.Method,
359+
Protocol: "gRPC",
360+
Code: int(stream.Code),
361+
Duration: diff,
362+
})
351363
}
352364

353365
// Restart restart gRPC server

apiserver/grpcserver/cache.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
lru "github.com/hashicorp/golang-lru"
2525
"google.golang.org/grpc"
2626

27+
"github.com/polarismesh/polaris/common/metrics"
2728
"github.com/polarismesh/polaris/plugin"
2829
)
2930

@@ -110,8 +111,12 @@ func (pc *protobufCache) Get(cacheType string, key string) *CacheObject {
110111
}
111112

112113
val, exist := c.Get(key)
113-
114-
_ = plugin.GetStatis().AddCacheCall(plugin.ComponentProtobufCache, cacheType, exist, 1)
114+
plugin.GetStatis().ReportCallMetrics(metrics.CallMetric{
115+
Type: metrics.ProtobufCacheCallMetric,
116+
Protocol: cacheType,
117+
Success: exist,
118+
Times: 1,
119+
})
115120

116121
if val == nil {
117122
return nil

apiserver/httpserver/core_console_apidoc.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929

3030
func enrichGetNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
3131
return r.
32-
Doc("查询命名空间列表").
32+
Doc("查询命名空间列表(New)").
3333
Metadata(restfulspec.KeyOpenAPITags, namespaceApiTags).
3434
Param(restful.QueryParameter("name", "命名空间唯一名称").DataType("string").Required(true)).
3535
Param(restful.QueryParameter("offset", "查询偏移量").DataType("integer").Required(false).DefaultValue("0")).
@@ -39,36 +39,36 @@ func enrichGetNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
3939

4040
func enrichCreateNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
4141
return r.
42-
Doc("创建命名空间").
42+
Doc("创建命名空间(New)").
4343
Metadata(restfulspec.KeyOpenAPITags, namespaceApiTags).
4444
Reads([]apimodel.Namespace{}, "create namespaces").
4545
Notes(enrichCreateNamespacesApiNotes)
4646
}
4747

4848
func enrichDeleteNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
4949
return r.
50-
Doc("删除命名空间").
50+
Doc("删除命名空间(New)").
5151
Metadata(restfulspec.KeyOpenAPITags, namespaceApiTags).
5252
Reads([]apimodel.Namespace{}, "delete namespaces").
5353
Notes(enrichDeleteNamespacesApiNotes)
5454
}
5555

5656
func enrichUpdateNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
5757
return r.
58-
Doc("更新命名空间").
58+
Doc("更新命名空间(New)").
5959
Metadata(restfulspec.KeyOpenAPITags, namespaceApiTags).
6060
Reads([]apimodel.Namespace{}, "update namespaces").
6161
Notes(enrichUpdateNamespacesApiNotes)
6262
}
6363

6464
func enrichGetNamespaceTokenApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
6565
return r.
66-
Doc("查询命名空间Token").
66+
Doc("查询命名空间Token(New)").
6767
Metadata(restfulspec.KeyOpenAPITags, namespaceApiTags).Deprecate()
6868
}
6969

7070
func enrichUpdateNamespaceTokenApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
7171
return r.
72-
Doc("更新命名空间Token").
72+
Doc("更新命名空间Token(New)").
7373
Metadata(restfulspec.KeyOpenAPITags, namespaceApiTags).Deprecate()
7474
}

apiserver/httpserver/server.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
"github.com/polarismesh/polaris/maintain"
4646
"github.com/polarismesh/polaris/namespace"
4747
"github.com/polarismesh/polaris/plugin"
48-
"github.com/polarismesh/polaris/plugin/statis/local"
4948
"github.com/polarismesh/polaris/service"
5049
"github.com/polarismesh/polaris/service/healthcheck"
5150
)
@@ -347,7 +346,9 @@ func (h *HTTPServer) createRestfulContainer() (*restful.Container, error) {
347346

348347
ws := new(restful.WebService)
349348
ws.Path("/core/v1").Consumes(restful.MIME_JSON).Produces(restful.MIME_JSON)
350-
349+
if err := h.GetClientServer(ws); err != nil {
350+
return nil, err
351+
}
351352
if err := h.GetCoreV1ConsoleAccessServer(ws, apiConfig.Include); err != nil {
352353
return nil, err
353354
}
@@ -393,11 +394,7 @@ func (h *HTTPServer) createRestfulContainer() (*restful.Container, error) {
393394
h.enableSwaggerAPI(wsContainer)
394395
}
395396

396-
statis := plugin.GetStatis()
397-
if _, ok := statis.(*local.StatisWorker); ok {
398-
h.enablePrometheusAccess(wsContainer)
399-
}
400-
397+
h.enablePrometheusAccess(wsContainer)
401398
return wsContainer, nil
402399
}
403400

@@ -518,7 +515,13 @@ func (h *HTTPServer) postProcess(req *restful.Request, rsp *restful.Response) {
518515
}
519516

520517
if recordApiCall {
521-
_ = h.statis.AddAPICall(method, "HTTP", int(code), diff.Nanoseconds())
518+
h.statis.ReportCallMetrics(metrics.CallMetric{
519+
Type: metrics.ServerCallMetric,
520+
API: method,
521+
Protocol: "HTTP",
522+
Code: int(code),
523+
Duration: diff,
524+
})
522525
}
523526
}
524527

apiserver/httpserver/v1/naming_console_access_apidoc.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var (
3838
)
3939

4040
func enrichGetNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
41-
return r.Doc("获取命名空间列表").
41+
return r.Doc("获取命名空间列表(Old)").
4242
Metadata(restfulspec.KeyOpenAPITags, namespacesApiTags).
4343
Param(restful.QueryParameter("name", "命名空间唯一名称").
4444
DataType("string").Required(true)).
@@ -51,37 +51,37 @@ func enrichGetNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
5151

5252
func enrichCreateNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
5353
return r.
54-
Doc("创建命名空间").
54+
Doc("创建命名空间(Old)").
5555
Metadata(restfulspec.KeyOpenAPITags, namespacesApiTags).
5656
Reads([]apimodel.Namespace{}, "create namespaces").
5757
Notes(enrichCreateNamespacesApiNotes)
5858
}
5959

6060
func enrichDeleteNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
6161
return r.
62-
Doc("删除命名空间").
62+
Doc("删除命名空间(Old)").
6363
Metadata(restfulspec.KeyOpenAPITags, namespacesApiTags).
6464
Reads([]apimodel.Namespace{}, "delete namespaces").
6565
Notes(enrichDeleteNamespacesApiNotes)
6666
}
6767

6868
func enrichUpdateNamespacesApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
6969
return r.
70-
Doc("更新命名空间").
70+
Doc("更新命名空间(Old)").
7171
Metadata(restfulspec.KeyOpenAPITags, namespacesApiTags).
7272
Reads([]apimodel.Namespace{}, "update namespaces").
7373
Notes(enrichUpdateNamespacesApiNotes)
7474
}
7575

7676
func enrichGetNamespaceTokenApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
7777
return r.
78-
Doc("查询命名空间Token").
78+
Doc("查询命名空间Token(Old)").
7979
Metadata(restfulspec.KeyOpenAPITags, namespacesApiTags).Deprecate()
8080
}
8181

8282
func enrichUpdateNamespaceTokenApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
8383
return r.
84-
Doc("更新命名空间Token").
84+
Doc("更新命名空间Token(Old)").
8585
Metadata(restfulspec.KeyOpenAPITags, namespacesApiTags).Deprecate()
8686
}
8787

@@ -284,28 +284,28 @@ func enrichGetInstanceLabelsApiDocs(r *restful.RouteBuilder) *restful.RouteBuild
284284
}
285285

286286
func enrichCreateRoutingsApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
287-
return r.Doc("创建路由规则").
287+
return r.Doc("创建路由规则(V1)").
288288
Metadata(restfulspec.KeyOpenAPITags, routingRulesApiTags).
289289
Reads([]apitraffic.Routing{}, "create routing rules").
290290
Notes(enrichCreateRoutingsApiNotes)
291291
}
292292

293293
func enrichDeleteRoutingsApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
294-
return r.Doc("删除路由规则").
294+
return r.Doc("删除路由规则(V1)").
295295
Metadata(restfulspec.KeyOpenAPITags, routingRulesApiTags).
296296
Reads([]apitraffic.Routing{}, "delete routing rules").
297297
Notes(enrichDeleteRoutingsApiNotes)
298298
}
299299

300300
func enrichUpdateRoutingsApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
301-
return r.Doc("更新路由规则").
301+
return r.Doc("更新路由规则(V1)").
302302
Metadata(restfulspec.KeyOpenAPITags, routingRulesApiTags).
303303
Reads([]apitraffic.Routing{}, "update routing rules").
304304
Notes(enrichUpdateRoutingsApiNotes)
305305
}
306306

307307
func enrichGetRoutingsApiDocs(r *restful.RouteBuilder) *restful.RouteBuilder {
308-
return r.Doc("查询路由规则").
308+
return r.Doc("查询路由规则(V1)").
309309
Metadata(restfulspec.KeyOpenAPITags, routingRulesApiTags).
310310
Param(restful.PathParameter("service", "服务名称").DataType("string").
311311
Required(false)).

0 commit comments

Comments
 (0)