You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2021/09/27 08:07:19 UTC
[servicecomb-service-center] branch v1.x updated: Fix: Etcd metrics
not correct (#1155)
This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch v1.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/v1.x by this push:
new c3bba37 Fix: Etcd metrics not correct (#1155)
c3bba37 is described below
commit c3bba374ea739a5fa94bad2a06923d12cf26839d
Author: little-cui <su...@qq.com>
AuthorDate: Mon Sep 27 16:07:15 2021 +0800
Fix: Etcd metrics not correct (#1155)
* Fix: Etcd metrics not correct
* Fix: remove counter
---
Dockerfile.build | 2 +-
go.mod | 3 +-
go.sum | 41 +---
pkg/registry/struct.go | 11 +
proxy.sh | 2 +-
scripts/build/local.sh | 2 +-
server/bootstrap/bootstrap.go | 2 +-
server/connection/metrics.go | 22 +-
server/core/backend/metrics.go | 14 +-
server/core/key_convertor.go | 5 +
server/handler/metric/metric.go | 2 +-
server/health/metrics.go | 6 +-
server/{metric => metrics}/calculator.go | 2 +-
server/{metric => metrics}/calculator_test.go | 2 +-
server/{metric => metrics}/common.go | 2 +-
server/{metric => metrics}/common_test.go | 2 +-
server/{metric => metrics}/gatherer.go | 16 +-
server/{metric => metrics}/gatherer_test.go | 2 +-
server/{metric => metrics}/metrics.go | 6 +-
server/{metric => metrics}/metrics_test.go | 2 +-
server/metrics/prometheus/meta_manager.go | 129 ++++++++++
.../prometheus/metrics_http.go} | 14 +-
.../prometheus/metrics_meta.go} | 68 ++----
server/{metric => metrics}/prometheus/reporter.go | 37 ++-
server/metrics/prometheus/reporter_meta.go | 95 ++++++++
server/{metric => metrics}/reporter.go | 2 +-
server/{metric => metrics}/reporter_test.go | 2 +-
server/plugin/discovery/etcd/metrics.go | 6 +-
server/plugin/discovery/etcd/metrics_test.go | 10 +-
server/plugin/discovery/metrics.go | 18 +-
server/plugin/quota/buildin/buildin.go | 2 -
server/plugin/quota/counter/counter.go | 49 ----
server/plugin/quota/counter/event.go | 111 ---------
server/plugin/quota/counter/event_test.go | 261 ---------------------
server/plugin/registry/metrics.go | 14 +-
server/plugin/tracing/pzipkin/common.go | 4 +-
server/service/event/domain_event_handler.go | 46 ----
server/service/event/event.go | 2 -
server/service/event/instance_event_handler.go | 34 +--
.../service/event/schema_summary_event_handler.go | 55 -----
server/service/event/service_event_handler.go | 18 --
41 files changed, 370 insertions(+), 753 deletions(-)
diff --git a/Dockerfile.build b/Dockerfile.build
index a21740c..83b9273 100644
--- a/Dockerfile.build
+++ b/Dockerfile.build
@@ -18,5 +18,5 @@ FROM golang:1.14
WORKDIR /go/src/github.com/apache/servicecomb-service-center
COPY . .
-RUN export GOPROXY=https://goproxy.io
+RUN export GOPROXY=https://goproxy.cn,direct
RUN bash -x scripts/build/local.sh linux 1.4.0 latest
diff --git a/go.mod b/go.mod
index c122e02..f5aed54 100644
--- a/go.mod
+++ b/go.mod
@@ -14,10 +14,9 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/elithrar/simple-scrypt v1.3.0
github.com/go-chassis/cari v0.3.0
- github.com/go-chassis/foundation v0.3.0
+ github.com/go-chassis/foundation v0.3.1-0.20210811025651-7f4d2b2b906c
github.com/go-chassis/go-archaius v1.3.2
github.com/go-chassis/go-chassis v0.0.0-20200826064053-d90be848aa10
- github.com/go-chassis/foundation v0.3.1-0.20210811025651-7f4d2b2b906c
github.com/go-chassis/paas-lager v1.1.1
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.4.3
diff --git a/go.sum b/go.sum
index 27c2de6..3f110dc 100644
--- a/go.sum
+++ b/go.sum
@@ -1,4 +1,3 @@
-cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
@@ -67,9 +66,6 @@ github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+Dx
github.com/apache/servicecomb-service-center v0.0.0-20200723031815-784c3533a8f2/go.mod h1:jiw0zTHphl1PVLX+LgftTSebaECo7XX6qwCNUONSMvE=
github.com/apache/thrift v0.0.0-20180125231006-3d556248a8b9 h1:ymi1nHra1RZXqjg5xvka4YVyK+3uKPk2B9HUlPRIiBc=
github.com/apache/thrift v0.0.0-20180125231006-3d556248a8b9/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
-github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
-github.com/apache/thrift v0.13.0 h1:5hryIiq9gtn+MiLVn0wP37kb/uTeRZgN08WoCsAhIhI=
-github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
@@ -112,8 +108,6 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
-github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
-github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
@@ -177,7 +171,6 @@ github.com/elithrar/simple-scrypt v1.3.0/go.mod h1:U2XQRI95XHY0St410VE3UjT7vuKb1
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.12.0+incompatible h1:SIvoTSbsMEwuM3dzFirLwKc4BH6VXP5CNf+G1FfJVr4=
github.com/emicklei/go-restful v2.12.0+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
-github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6vRfwrJatElLBEf0I=
@@ -205,12 +198,8 @@ github.com/go-chassis/cari v0.3.0 h1:ysEX1t9dBObshebFKca3zhrWFqyPvcIZo2r66IyJjuk
github.com/go-chassis/cari v0.3.0/go.mod h1:Ie2lW11Y5ZFClY9z7bhAwK6BoNxqGSf3fYGs4mPFs74=
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
-github.com/go-chassis/foundation v0.3.0 h1:jG4BIrK8fXD9jbTtJ5rOLGQZ1pQI/mLnDuVJzToCtos=
-github.com/go-chassis/foundation v0.3.0/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
github.com/go-chassis/foundation v0.3.1-0.20210811025651-7f4d2b2b906c h1:6ooUyysnayGgoJHV++NLEcnnnXzsw3ud4VydjISGBqI=
github.com/go-chassis/foundation v0.3.1-0.20210811025651-7f4d2b2b906c/go.mod h1:6NsIUaHghTFRGfCBcZN011zl196F6OR5QvD9N+P4oWU=
-github.com/go-chassis/glog v0.0.0-20180920075250-95a09b2413e9 h1:z6ezGZIJVMl2Yo0gOJlv8jOvCDFi9W3TLADQvJ6Z2t0=
-github.com/go-chassis/glog v0.0.0-20180920075250-95a09b2413e9/go.mod h1:tfdQUl8deEC8YmpbYjbSZJv7Y/7hC0ag9n3RVrjIoJs=
github.com/go-chassis/go-archaius v1.3.2 h1:b52voYtSL+fukmvg/rsn/quw/hgDWtV945adl0VV8Lg=
github.com/go-chassis/go-archaius v1.3.2/go.mod h1:nzRL1sSodtgeCZMzCNu0y2LPH5zz7chp8uaQ0GS0x6I=
github.com/go-chassis/go-chassis v0.0.0-20200716073336-4183d5dd1246/go.mod h1:S7RbnpeTWBqZ4+UxGAs05a6qdhDyWKpTNuil8FYNiME=
@@ -252,7 +241,6 @@ github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
-github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
@@ -261,12 +249,14 @@ github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
+github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 h1:5ZkaAPbicIKTF2I64qf5Fh8Aa83Q/dnOafMYV0OMwjA=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
@@ -287,8 +277,6 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
-github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
-github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@@ -302,7 +290,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -459,7 +446,6 @@ github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ic
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
-github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a h1:TpvdAwDAt1K4ANVOfcihouRdvP+MgAfDWwBuct4l6ZY=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
@@ -587,7 +573,6 @@ github.com/prometheus/client_golang v0.9.1 h1:K47Rk0v/fkEfwfQet2KWhscE0cJzjgCCDB
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
-github.com/prometheus/client_golang v0.9.4/go.mod h1:oCXIBxdI62A4cR6aTRJCgetEjecSIYzOEaeAn4iYEpM=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
github.com/prometheus/client_golang v1.7.0 h1:wCi7urQOGBsYcQROHqpUUX4ct84xp40t9R9JX0FuA/U=
@@ -777,7 +762,6 @@ golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm0
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
-golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
@@ -797,7 +781,6 @@ golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -845,7 +828,6 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -900,11 +882,9 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
@@ -943,7 +923,6 @@ google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
-google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c=
@@ -964,21 +943,8 @@ google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBr
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
-google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
-google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8=
-google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
-google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
-google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
-google.golang.org/grpc v1.21.0 h1:G+97AoqBnmZIT91cLG/EkCoK9NSelj64P8bOHHNmGn0=
-google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
-google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
-google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
-google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
-google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
-google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg=
-google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -990,8 +956,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA=
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
-google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
-google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -1033,7 +997,6 @@ gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a h1:/8zB6iBfHCl1qAnEAWwGPNrUvapuy6CPla1VM0k8hQw=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/pkg/registry/struct.go b/pkg/registry/struct.go
index 453ce57..b440287 100644
--- a/pkg/registry/struct.go
+++ b/pkg/registry/struct.go
@@ -415,3 +415,14 @@ type GetAppsResponse struct {
type MicroServiceDependency struct {
Dependency []*MicroServiceKey `json:"Dependency,omitempty"`
}
+
+func ToFrameworkLabel(ms *MicroService) (string, string) {
+ if ms.Framework != nil && len(ms.Framework.Name) > 0 {
+ version := ms.Framework.Version
+ if len(ms.Framework.Version) == 0 {
+ version = "UNKNOWN"
+ }
+ return ms.Framework.Name, version
+ }
+ return "UNKNOWN", "UNKNOWN"
+}
diff --git a/proxy.sh b/proxy.sh
index dd0c9af..be9f90c 100755
--- a/proxy.sh
+++ b/proxy.sh
@@ -13,4 +13,4 @@
# 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.
-export GOPROXY=https://goproxy.io,direct
+export GOPROXY=https://goproxy.cn,direct
diff --git a/scripts/build/local.sh b/scripts/build/local.sh
index 2dfb536..3d0bb3e 100644
--- a/scripts/build/local.sh
+++ b/scripts/build/local.sh
@@ -16,7 +16,7 @@
# limitations under the License.
set -e
-export GOPROXY=https://goproxy.io
+export GOPROXY=${GOPROXY:-"https://goproxy.cn,direct"}
export GOOS=${1:-"linux"}
export GOARCH=${4:-"amd64"}
export CGO_ENABLED=${CGO_ENABLED:-0} # prevent to compile cgo file
diff --git a/server/bootstrap/bootstrap.go b/server/bootstrap/bootstrap.go
index e1898d2..2ed5c0e 100644
--- a/server/bootstrap/bootstrap.go
+++ b/server/bootstrap/bootstrap.go
@@ -73,7 +73,7 @@ import (
_ "github.com/apache/servicecomb-service-center/server/rest/admin"
//metrics
- _ "github.com/apache/servicecomb-service-center/server/metric"
+ _ "github.com/apache/servicecomb-service-center/server/metrics/prometheus"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/server/handler/accesslog"
diff --git a/server/connection/metrics.go b/server/connection/metrics.go
index 26f34e0..27949cf 100644
--- a/server/connection/metrics.go
+++ b/server/connection/metrics.go
@@ -21,7 +21,7 @@ import (
"time"
"github.com/apache/servicecomb-service-center/pkg/event"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/prometheus/client_golang/prometheus"
)
@@ -33,7 +33,7 @@ const (
var (
notifyCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "notify",
Name: "publish_total",
Help: "Counter of publishing instance events",
@@ -41,16 +41,16 @@ var (
notifyLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "notify",
Name: "publish_durations_microseconds",
Help: "Latency of publishing instance events",
- Objectives: metric.Pxx,
+ Objectives: metrics.Pxx,
}, []string{"instance", "source", "status"})
pendingGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "notify",
Name: "pending_total",
Help: "Counter of pending instance events",
@@ -58,16 +58,16 @@ var (
pendingLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "notify",
Name: "pending_durations_microseconds",
Help: "Latency of pending instance events",
- Objectives: metric.Pxx,
+ Objectives: metrics.Pxx,
}, []string{"instance", "source"})
subscriberGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "notify",
Name: "subscriber_total",
Help: "Gauge of subscribers",
@@ -79,7 +79,7 @@ func init() {
}
func ReportPublishCompleted(evt event.Event, err error) {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
elapsed := float64(time.Since(evt.CreateAt()).Nanoseconds()) / float64(time.Microsecond)
status := success
if err != nil {
@@ -91,14 +91,14 @@ func ReportPublishCompleted(evt event.Event, err error) {
}
func ReportPendingCompleted(evt event.Event) {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
elapsed := float64(time.Since(evt.CreateAt()).Nanoseconds()) / float64(time.Microsecond)
pendingLatency.WithLabelValues(instance, evt.Type().String()).Observe(elapsed)
pendingGauge.WithLabelValues(instance, evt.Type().String()).Inc()
}
func ReportSubscriber(domain, scheme string, n float64) {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
subscriberGauge.WithLabelValues(instance, domain, scheme).Add(n)
}
diff --git a/server/core/backend/metrics.go b/server/core/backend/metrics.go
index 07170c5..ac1efb3 100644
--- a/server/core/backend/metrics.go
+++ b/server/core/backend/metrics.go
@@ -20,7 +20,7 @@ package backend
import (
"time"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/prometheus/client_golang/prometheus"
)
@@ -32,7 +32,7 @@ const (
var (
scCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "sc_total",
Help: "Counter of the Service Center instance",
@@ -40,7 +40,7 @@ var (
heartbeatCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "heartbeat_total",
Help: "Counter of heartbeat renew",
@@ -48,11 +48,11 @@ var (
heartbeatLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "heartbeat_durations_microseconds",
Help: "Latency of heartbeat renew",
- Objectives: metric.Pxx,
+ Objectives: metrics.Pxx,
}, []string{"instance", "status"})
)
@@ -61,12 +61,12 @@ func init() {
}
func ReportScInstance() {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
scCounter.WithLabelValues(instance).Add(1)
}
func ReportHeartbeatCompleted(err error, start time.Time) {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
elapsed := float64(time.Since(start).Nanoseconds()) / float64(time.Microsecond)
status := success
if err != nil {
diff --git a/server/core/key_convertor.go b/server/core/key_convertor.go
index ffbb87a..ddcf95a 100644
--- a/server/core/key_convertor.go
+++ b/server/core/key_convertor.go
@@ -21,6 +21,7 @@ import (
"github.com/apache/servicecomb-service-center/pkg/registry"
"github.com/apache/servicecomb-service-center/pkg/util"
+ "github.com/go-chassis/foundation/stringutil"
)
func KvToResponse(key []byte) (keys []string) {
@@ -167,3 +168,7 @@ func GetInfoFromDependencyRuleKV(key []byte) (t string, _ *registry.MicroService
Version: keys[l-1],
}
}
+
+func SplitDomainProject(domainProject string) (string, string) {
+ return stringutil.SplitToTwo(domainProject, SPLIT)
+}
diff --git a/server/handler/metric/metric.go b/server/handler/metric/metric.go
index 339a5ff..dedd63f 100644
--- a/server/handler/metric/metric.go
+++ b/server/handler/metric/metric.go
@@ -24,7 +24,7 @@ import (
"github.com/apache/servicecomb-service-center/pkg/chain"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/rest"
- "github.com/apache/servicecomb-service-center/server/metric/prometheus"
+ "github.com/apache/servicecomb-service-center/server/metrics/prometheus"
svr "github.com/apache/servicecomb-service-center/server/rest"
)
diff --git a/server/health/metrics.go b/server/health/metrics.go
index 2959aa0..2b313c1 100644
--- a/server/health/metrics.go
+++ b/server/health/metrics.go
@@ -22,7 +22,7 @@ import (
"github.com/apache/servicecomb-service-center/pkg/gopool"
"github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/prometheus/client_golang/prometheus"
)
@@ -31,7 +31,7 @@ const durationReportCPUUsage = 3 * time.Second
var (
cpuGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "process",
Name: "cpu_usage",
Help: "Process cpu usage",
@@ -55,7 +55,7 @@ func AutoReportCPUUsage(ctx context.Context) {
return
case <-time.After(durationReportCPUUsage):
pt, ct := util.GetProcCPUUsage()
- cpuGauge.WithLabelValues(metric.InstanceName()).Set(
+ cpuGauge.WithLabelValues(metrics.InstanceName()).Set(
(pt - cpuProc) * float64(cpus) / (ct - cpuTotal))
cpuTotal, cpuProc = ct, pt
}
diff --git a/server/metric/calculator.go b/server/metrics/calculator.go
similarity index 99%
rename from server/metric/calculator.go
rename to server/metrics/calculator.go
index f1c4ee7..6574e6d 100644
--- a/server/metric/calculator.go
+++ b/server/metrics/calculator.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package metric
+package metrics
import (
dto "github.com/prometheus/client_model/go"
diff --git a/server/metric/calculator_test.go b/server/metrics/calculator_test.go
similarity index 99%
rename from server/metric/calculator_test.go
rename to server/metrics/calculator_test.go
index e4a356a..4dcf76d 100644
--- a/server/metric/calculator_test.go
+++ b/server/metrics/calculator_test.go
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package metric
+package metrics
import (
"testing"
diff --git a/server/metric/common.go b/server/metrics/common.go
similarity index 99%
rename from server/metric/common.go
rename to server/metrics/common.go
index 9358283..b2aee7e 100644
--- a/server/metric/common.go
+++ b/server/metrics/common.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package metric
+package metrics
import (
"net"
diff --git a/server/metric/common_test.go b/server/metrics/common_test.go
similarity index 99%
rename from server/metric/common_test.go
rename to server/metrics/common_test.go
index 6de7968..7c68186 100644
--- a/server/metric/common_test.go
+++ b/server/metrics/common_test.go
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package metric
+package metrics
import (
"os"
diff --git a/server/metric/gatherer.go b/server/metrics/gatherer.go
similarity index 87%
rename from server/metric/gatherer.go
rename to server/metrics/gatherer.go
index 37b58bf..b2c8451 100644
--- a/server/metric/gatherer.go
+++ b/server/metrics/gatherer.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package metric
+package metrics
import (
"context"
@@ -29,28 +29,28 @@ import (
)
// Gatherer is the reader of sc metrics
-var Gatherer *MetricsGatherer
+var Gatherer *Gather
func init() {
Gatherer = NewGatherer()
Gatherer.Start()
}
-func NewGatherer() *MetricsGatherer {
- return &MetricsGatherer{
+func NewGatherer() *Gather {
+ return &Gather{
Records: NewMetrics(),
closed: true,
}
}
-type MetricsGatherer struct {
+type Gather struct {
Records *Metrics
lock sync.Mutex
closed bool
}
-func (mm *MetricsGatherer) Start() {
+func (mm *Gather) Start() {
mm.lock.Lock()
if !mm.closed {
mm.lock.Unlock()
@@ -63,7 +63,7 @@ func (mm *MetricsGatherer) Start() {
mm.lock.Unlock()
}
-func (mm *MetricsGatherer) loop(ctx context.Context) {
+func (mm *Gather) loop(ctx context.Context) {
ticker := time.NewTicker(Period)
for {
select {
@@ -80,7 +80,7 @@ func (mm *MetricsGatherer) loop(ctx context.Context) {
}
}
-func (mm *MetricsGatherer) Collect() error {
+func (mm *Gather) Collect() error {
mfs, err := prometheus.DefaultGatherer.Gather()
if err != nil {
return err
diff --git a/server/metric/gatherer_test.go b/server/metrics/gatherer_test.go
similarity index 98%
rename from server/metric/gatherer_test.go
rename to server/metrics/gatherer_test.go
index 4867aca..d3581eb 100644
--- a/server/metric/gatherer_test.go
+++ b/server/metrics/gatherer_test.go
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package metric
+package metrics
import "testing"
diff --git a/server/metric/metrics.go b/server/metrics/metrics.go
similarity index 98%
rename from server/metric/metrics.go
rename to server/metrics/metrics.go
index 45bb294..83a4314 100644
--- a/server/metric/metrics.go
+++ b/server/metrics/metrics.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package metric
+package metrics
import (
"reflect"
@@ -41,7 +41,7 @@ func NewDetails() *Details {
}
}
-// Details is the struct to hold the calculated result and index by metric label
+// Details is the struct to hold the calculated result and index by metrics label
type Details struct {
// Summary is the calculation results of the details
Summary float64
@@ -94,7 +94,7 @@ func (cm *Details) ForEach(f func(labels []*dto.LabelPair, v float64) (next bool
}
}
-// Metrics is the struct to hold the Details objects store and index by metric name
+// Metrics is the struct to hold the Details objects store and index by metrics name
type Metrics struct {
mapper map[string]*Details
}
diff --git a/server/metric/metrics_test.go b/server/metrics/metrics_test.go
similarity index 99%
rename from server/metric/metrics_test.go
rename to server/metrics/metrics_test.go
index 2a7c463..64760e9 100644
--- a/server/metric/metrics_test.go
+++ b/server/metrics/metrics_test.go
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package metric
+package metrics
import (
"reflect"
diff --git a/server/metrics/prometheus/meta_manager.go b/server/metrics/prometheus/meta_manager.go
new file mode 100644
index 0000000..8ff9fae
--- /dev/null
+++ b/server/metrics/prometheus/meta_manager.go
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) 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 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 prometheus
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/apache/servicecomb-service-center/pkg/log"
+ pb "github.com/apache/servicecomb-service-center/pkg/registry"
+ "github.com/apache/servicecomb-service-center/server/core"
+ "github.com/apache/servicecomb-service-center/server/core/backend"
+ "github.com/apache/servicecomb-service-center/server/core/proto"
+ "github.com/apache/servicecomb-service-center/server/plugin/registry"
+)
+
+type MetricsManager struct {
+}
+
+func (m *MetricsManager) Report(ctx context.Context, r *MetaReporter) error {
+ reportDomains(ctx, r)
+ reportServices(ctx, r)
+ reportSchemas(ctx, r)
+ return nil
+}
+
+func reportDomains(ctx context.Context, r *MetaReporter) {
+ key := core.GenerateDomainKey("")
+ domainsResp, err := backend.Store().Domain().Search(ctx,
+ registry.WithCacheOnly(), registry.WithCountOnly(),
+ registry.WithStrKey(key),
+ registry.WithPrefix())
+ if err != nil {
+ log.Error("query all domains failed", err)
+ return
+ }
+ r.DomainAdd(float64(domainsResp.Count))
+}
+
+func reportSchemas(ctx context.Context, r *MetaReporter) {
+ key := core.GetServiceSchemaSummaryRootKey("")
+ schemaKeysResp, err := backend.Store().SchemaSummary().Search(ctx,
+ registry.WithCacheOnly(), registry.WithKeyOnly(),
+ registry.WithStrKey(key),
+ registry.WithPrefix())
+ if err != nil {
+ log.Error("query all schemas failed", err)
+ return
+ }
+ for _, keyValue := range schemaKeysResp.Kvs {
+ domainProject, _, _ := core.GetInfoFromSchemaSummaryKV(keyValue.Key)
+ domain, project := core.SplitDomainProject(domainProject)
+ labels := MetricsLabels{
+ Domain: domain,
+ Project: project,
+ }
+ r.SchemaAdd(1, labels)
+ }
+}
+
+func reportServices(ctx context.Context, r *MetaReporter) {
+ key := core.GetServiceRootKey("")
+ servicesResp, err := backend.Store().Service().Search(ctx,
+ registry.WithCacheOnly(),
+ registry.WithStrKey(key),
+ registry.WithPrefix())
+ if err != nil {
+ log.Error("query all microservices failed", err)
+ return
+ }
+ for _, keyValue := range servicesResp.Kvs {
+ service := keyValue.Value.(*pb.MicroService)
+ _, domainProject := core.GetInfoFromSvcKV(keyValue.Key)
+ if core.IsShared(proto.MicroServiceToKey(domainProject, service)) {
+ continue
+ }
+ domain, project := core.SplitDomainProject(domainProject)
+ frameworkName, frameworkVersion := pb.ToFrameworkLabel(service)
+ labels := MetricsLabels{
+ Domain: domain,
+ Project: project,
+ Framework: frameworkName,
+ FrameworkVersion: frameworkVersion,
+ }
+ r.ServiceAdd(1, labels)
+
+ reportInstances(ctx, r, domainProject, service)
+ }
+}
+
+func reportInstances(ctx context.Context, r *MetaReporter, domainProject string, service *pb.MicroService) {
+ instancesResp, err := backend.Store().Instance().Search(ctx,
+ registry.WithCacheOnly(), registry.WithCountOnly(),
+ registry.WithStrKey(core.GenerateInstanceKey(domainProject, service.ServiceId, "")),
+ registry.WithPrefix())
+ if err != nil {
+ log.Error(fmt.Sprintf("query microservice %s isntances failed", service.ServiceId), err)
+ return
+ }
+ if instancesResp.Count == 0 {
+ return
+ }
+ count := float64(instancesResp.Count)
+ domain, project := core.SplitDomainProject(domainProject)
+ frameworkName, frameworkVersion := pb.ToFrameworkLabel(service)
+ labels := MetricsLabels{
+ Domain: domain,
+ Project: project,
+ Framework: frameworkName,
+ FrameworkVersion: frameworkVersion,
+ }
+ r.FrameworkSet(labels)
+ r.InstanceAdd(count, labels)
+}
diff --git a/server/metric/prometheus/metrics.go b/server/metrics/prometheus/metrics_http.go
similarity index 92%
rename from server/metric/prometheus/metrics.go
rename to server/metrics/prometheus/metrics_http.go
index 2dff27f..4b5615f 100644
--- a/server/metric/prometheus/metrics.go
+++ b/server/metrics/prometheus/metrics_http.go
@@ -26,7 +26,7 @@ import (
"github.com/apache/servicecomb-service-center/pkg/rest"
"github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
api "github.com/apache/servicecomb-service-center/server/rest"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -35,7 +35,7 @@ import (
var (
incomingRequests = prometheus.NewCounterVec(
prometheus.CounterOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "http",
Name: "request_total",
Help: "Counter of requests received into ROA handler",
@@ -43,7 +43,7 @@ var (
successfulRequests = prometheus.NewCounterVec(
prometheus.CounterOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "http",
Name: "success_total",
Help: "Counter of successful requests processed by ROA handler",
@@ -51,16 +51,16 @@ var (
reqDurations = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "http",
Name: "request_durations_microseconds",
Help: "HTTP request latency summary of ROA handler",
- Objectives: metric.Pxx,
+ Objectives: metrics.Pxx,
}, []string{"method", "instance", "api", "domain"})
queryPerSeconds = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "http",
Name: "query_per_seconds",
Help: "HTTP requests per seconds of ROA handler",
@@ -75,7 +75,7 @@ func init() {
}
func ReportRequestCompleted(w http.ResponseWriter, r *http.Request, start time.Time) {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
elapsed := float64(time.Since(start).Nanoseconds()) / float64(time.Microsecond)
route, _ := r.Context().Value(rest.CtxMatchFunc).(string)
domain := util.ParseDomain(r.Context())
diff --git a/server/service/metrics/metrics.go b/server/metrics/prometheus/metrics_meta.go
similarity index 56%
rename from server/service/metrics/metrics.go
rename to server/metrics/prometheus/metrics_meta.go
index 389abc8..0ebd272 100644
--- a/server/service/metrics/metrics.go
+++ b/server/metrics/prometheus/metrics_meta.go
@@ -15,11 +15,10 @@
* limitations under the License.
*/
-package metrics
+package prometheus
import (
- "github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/prometheus/client_golang/prometheus"
)
@@ -32,87 +31,56 @@ const (
KeyFrameworkTotal = "framework_total"
SubSystem = "db"
-)
-// Key return metrics key
-func Key(name string) string {
- return util.StringJoin([]string{SubSystem, name}, "_")
-}
+ LabelInstance = "instance"
+ LabelFramework = "framework"
+ LabelFrameworkVersion = "frameworkVersion"
+ LabelDomain = "domain"
+ LabelProject = "project"
+)
var (
domainCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: SubSystem,
Name: KeyDomainTotal,
Help: "Gauge of domain created in Service Center",
- }, []string{"instance"})
+ }, []string{LabelInstance})
serviceCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: KeyServiceTotal,
Help: "Gauge of microservice created in Service Center",
- }, []string{"instance", "framework", "frameworkVersion", "domain"})
+ }, []string{LabelInstance, LabelFramework, LabelFrameworkVersion, LabelDomain, LabelProject})
instanceCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: SubSystem,
Name: KeyInstanceTotal,
Help: "Gauge of microservice created in Service Center",
- }, []string{"instance", "domain"})
+ }, []string{LabelInstance, LabelFramework, LabelFrameworkVersion, LabelDomain, LabelProject})
schemaCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: SubSystem,
Name: KeySchemaTotal,
Help: "Gauge of schema created in Service Center",
- }, []string{"instance", "domain"})
+ }, []string{LabelInstance, LabelDomain, LabelProject})
frameworkCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: SubSystem,
Name: KeyFrameworkTotal,
Help: "Gauge of client framework info in Service Center",
- }, metric.ToLabelNames(Framework{}))
+ }, []string{LabelInstance, LabelFramework, LabelFrameworkVersion, LabelDomain, LabelProject})
)
-// Framework return framework info.
-type Framework struct {
- DomainName string `json:"domainName"`
- ProjectName string `json:"projectName"`
- FrameWork string `json:"framework"`
- FrameworkVersion string `json:"frameworkVersion"`
-}
-
func init() {
prometheus.MustRegister(domainCounter, serviceCounter, instanceCounter, schemaCounter, frameworkCounter)
}
-
-func ReportDomains(c float64) {
- instance := metric.InstanceName()
- domainCounter.WithLabelValues(instance).Add(c)
-}
-
-func ReportServices(domain, framework, frameworkVersion string, c float64) {
- instance := metric.InstanceName()
- serviceCounter.WithLabelValues(instance, framework, frameworkVersion, domain).Add(c)
-}
-
-func ReportInstances(domain string, c float64) {
- instance := metric.InstanceName()
- instanceCounter.WithLabelValues(instance, domain).Add(c)
-}
-
-func ReportSchemas(domain string, c float64) {
- instance := metric.InstanceName()
- schemaCounter.WithLabelValues(instance, domain).Add(c)
-}
-
-func ReportFramework(domainName, projectName string, framework, frameworkVersion string, c float64) {
- frameworkCounter.WithLabelValues(domainName, projectName, framework, frameworkVersion).Add(c)
-}
diff --git a/server/metric/prometheus/reporter.go b/server/metrics/prometheus/reporter.go
similarity index 65%
rename from server/metric/prometheus/reporter.go
rename to server/metrics/prometheus/reporter.go
index 32cc6df..ae99e8f 100644
--- a/server/metric/prometheus/reporter.go
+++ b/server/metrics/prometheus/reporter.go
@@ -16,7 +16,10 @@
package prometheus
import (
- "github.com/apache/servicecomb-service-center/server/metric"
+ "context"
+
+ "github.com/apache/servicecomb-service-center/pkg/log"
+ "github.com/apache/servicecomb-service-center/server/metrics"
dto "github.com/prometheus/client_model/go"
)
@@ -31,12 +34,17 @@ var qpsLabelMap = map[string]int{
"domain": 3,
}
-type APIReporter struct {
- cache *metric.Details
+type Reporter struct {
+ cache *metrics.Details
+}
+
+func (r *Reporter) Report() {
+ r.reportMetaMetrics()
+ r.reportHTTPMetrics()
}
-func (r *APIReporter) Report() {
- details := metric.Gatherer.Records.Get(httpRequestTotal)
+func (r *Reporter) reportHTTPMetrics() {
+ details := metrics.Gatherer.Records.Get(httpRequestTotal)
if details == nil {
return
}
@@ -48,12 +56,12 @@ func (r *APIReporter) Report() {
}
details.ForEach(func(labels []*dto.LabelPair, v float64) (next bool) {
old := r.cache.Get(labels)
- queryPerSeconds.WithLabelValues(r.toLabels(labels)...).Set((v - old) / metric.Period.Seconds())
+ queryPerSeconds.WithLabelValues(r.toLabels(labels)...).Set((v - old) / metrics.Period.Seconds())
return true
})
}
-func (r *APIReporter) toLabels(pairs []*dto.LabelPair) (labels []string) {
+func (r *Reporter) toLabels(pairs []*dto.LabelPair) (labels []string) {
labels = make([]string, len(qpsLabelMap))
for _, pair := range pairs {
if i, ok := qpsLabelMap[pair.GetName()]; ok {
@@ -63,10 +71,19 @@ func (r *APIReporter) toLabels(pairs []*dto.LabelPair) (labels []string) {
return
}
+func (r *Reporter) reportMetaMetrics() {
+ ResetMetaMetrics()
+ mgr := MetricsManager{}
+ err := mgr.Report(context.Background(), GetMetaReporter())
+ if err != nil {
+ log.Error("report meta metrics failed", err)
+ }
+}
+
func init() {
- metric.RegisterReporter("rest", NewAPIReporter())
+ metrics.RegisterReporter("job", NewReporter())
}
-func NewAPIReporter() *APIReporter {
- return &APIReporter{}
+func NewReporter() *Reporter {
+ return &Reporter{}
}
diff --git a/server/metrics/prometheus/reporter_meta.go b/server/metrics/prometheus/reporter_meta.go
new file mode 100644
index 0000000..75b55c6
--- /dev/null
+++ b/server/metrics/prometheus/reporter_meta.go
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) 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 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 prometheus
+
+import (
+ "github.com/apache/servicecomb-service-center/server/metrics"
+)
+
+var metaReporter = &MetaReporter{}
+
+type MetricsLabels struct {
+ Domain string `json:"domain"`
+ Project string `json:"project"`
+ Framework string `json:"framework"`
+ FrameworkVersion string `json:"frameworkVersion"`
+}
+
+type MetaReporter struct {
+}
+
+func (m *MetaReporter) DomainAdd(delta float64) {
+ instance := metrics.InstanceName()
+ labels := map[string]string{
+ LabelInstance: instance,
+ }
+ domainCounter.With(labels).Add(delta)
+}
+func (m *MetaReporter) ServiceAdd(delta float64, ml MetricsLabels) {
+ instance := metrics.InstanceName()
+ labels := map[string]string{
+ LabelInstance: instance,
+ LabelFramework: ml.Framework,
+ LabelFrameworkVersion: ml.FrameworkVersion,
+ LabelDomain: ml.Domain,
+ LabelProject: ml.Project,
+ }
+ serviceCounter.With(labels).Add(delta)
+}
+func (m *MetaReporter) InstanceAdd(delta float64, ml MetricsLabels) {
+ instance := metrics.InstanceName()
+ labels := map[string]string{
+ LabelInstance: instance,
+ LabelFramework: ml.Framework,
+ LabelFrameworkVersion: ml.FrameworkVersion,
+ LabelDomain: ml.Domain,
+ LabelProject: ml.Project,
+ }
+ instanceCounter.With(labels).Add(delta)
+}
+func (m *MetaReporter) SchemaAdd(delta float64, ml MetricsLabels) {
+ instance := metrics.InstanceName()
+ labels := map[string]string{
+ LabelInstance: instance,
+ LabelDomain: ml.Domain,
+ LabelProject: ml.Project,
+ }
+ schemaCounter.With(labels).Add(delta)
+}
+func (m *MetaReporter) FrameworkSet(ml MetricsLabels) {
+ instance := metrics.InstanceName()
+ labels := map[string]string{
+ LabelInstance: instance,
+ LabelFramework: ml.Framework,
+ LabelFrameworkVersion: ml.FrameworkVersion,
+ LabelDomain: ml.Domain,
+ LabelProject: ml.Project,
+ }
+ frameworkCounter.With(labels).Set(1)
+}
+
+func GetMetaReporter() *MetaReporter {
+ return metaReporter
+}
+
+func ResetMetaMetrics() {
+ domainCounter.Reset()
+ serviceCounter.Reset()
+ instanceCounter.Reset()
+ schemaCounter.Reset()
+}
diff --git a/server/metric/reporter.go b/server/metrics/reporter.go
similarity index 98%
rename from server/metric/reporter.go
rename to server/metrics/reporter.go
index decfba4..072acc2 100644
--- a/server/metric/reporter.go
+++ b/server/metrics/reporter.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package metric
+package metrics
import "github.com/apache/servicecomb-service-center/pkg/log"
diff --git a/server/metric/reporter_test.go b/server/metrics/reporter_test.go
similarity index 98%
rename from server/metric/reporter_test.go
rename to server/metrics/reporter_test.go
index 3962540..0b76074 100644
--- a/server/metric/reporter_test.go
+++ b/server/metrics/reporter_test.go
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package metric
+package metrics
import "testing"
diff --git a/server/plugin/discovery/etcd/metrics.go b/server/plugin/discovery/etcd/metrics.go
index c104ec4..f900e30 100644
--- a/server/plugin/discovery/etcd/metrics.go
+++ b/server/plugin/discovery/etcd/metrics.go
@@ -17,14 +17,14 @@
package etcd
import (
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
cacheSizeGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "local",
Name: "cache_size_bytes",
Help: "Local cache size summary of backend store",
@@ -36,7 +36,7 @@ func init() {
}
func ReportCacheSize(resource, t string, s int) {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
if len(instance) == 0 || len(resource) == 0 {
// endpoints list will be empty when initializing
// resource may be empty when report SCHEMA
diff --git a/server/plugin/discovery/etcd/metrics_test.go b/server/plugin/discovery/etcd/metrics_test.go
index 9265f15..1e56a0d 100644
--- a/server/plugin/discovery/etcd/metrics_test.go
+++ b/server/plugin/discovery/etcd/metrics_test.go
@@ -19,7 +19,7 @@ package etcd
import (
"testing"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/astaxie/beego"
)
@@ -29,17 +29,17 @@ func init() {
func TestReportCacheSize(t *testing.T) {
ReportCacheSize("a", "b", 100)
- err := metric.Gatherer.Collect()
+ err := metrics.Gatherer.Collect()
if err != nil {
t.Fatalf("TestReportCacheSize failed")
}
- if metric.Gatherer.Records.Summary("local_cache_size_bytes") != 100 {
+ if metrics.Gatherer.Records.Summary("local_cache_size_bytes") != 100 {
t.Fatalf("TestReportCacheSize failed")
}
ReportCacheSize("", "b", 200)
- err = metric.Gatherer.Collect()
- if metric.Gatherer.Records.Summary("local_cache_size_bytes") != 100 {
+ err = metrics.Gatherer.Collect()
+ if metrics.Gatherer.Records.Summary("local_cache_size_bytes") != 100 {
t.Fatalf("TestReportCacheSize failed")
}
}
diff --git a/server/plugin/discovery/metrics.go b/server/plugin/discovery/metrics.go
index 2dfec76..2b47e89 100644
--- a/server/plugin/discovery/metrics.go
+++ b/server/plugin/discovery/metrics.go
@@ -19,14 +19,14 @@ package discovery
import (
"time"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
eventsCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "backend_event_total",
Help: "Counter of backend events",
@@ -34,16 +34,16 @@ var (
eventsLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "backend_event_durations_microseconds",
Help: "Latency of backend events processing",
- Objectives: metric.Pxx,
+ Objectives: metrics.Pxx,
}, []string{"instance", "prefix"})
dispatchCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "dispatch_event_total",
Help: "Counter of backend events dispatch",
@@ -51,11 +51,11 @@ var (
dispatchLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "dispatch_event_durations_microseconds",
Help: "Latency of backend events dispatch",
- Objectives: metric.Pxx,
+ Objectives: metrics.Pxx,
}, []string{"instance", "prefix"})
)
@@ -68,7 +68,7 @@ func ReportProcessEventCompleted(prefix string, evts []KvEvent) {
if l == 0 {
return
}
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
now := time.Now()
for _, evt := range evts {
elapsed := float64(now.Sub(evt.CreateAt.Local()).Nanoseconds()) / float64(time.Microsecond)
@@ -83,7 +83,7 @@ func ReportDispatchEventCompleted(prefix string, evts []KvEvent) {
if l == 0 {
return
}
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
now := time.Now()
for _, evt := range evts {
elapsed := float64(now.Sub(evt.CreateAt.Local()).Nanoseconds()) / float64(time.Microsecond)
diff --git a/server/plugin/quota/buildin/buildin.go b/server/plugin/quota/buildin/buildin.go
index 3c5e10d..40cee0c 100644
--- a/server/plugin/quota/buildin/buildin.go
+++ b/server/plugin/quota/buildin/buildin.go
@@ -23,12 +23,10 @@ import (
"github.com/apache/servicecomb-service-center/pkg/log"
mgr "github.com/apache/servicecomb-service-center/server/plugin"
"github.com/apache/servicecomb-service-center/server/plugin/quota"
- "github.com/apache/servicecomb-service-center/server/plugin/quota/counter"
)
func init() {
mgr.RegisterPlugin(mgr.Plugin{PName: mgr.QUOTA, Name: "buildin", New: New})
- counter.RegisterCounterListener("buildin")
}
func New() mgr.Instance {
diff --git a/server/plugin/quota/counter/counter.go b/server/plugin/quota/counter/counter.go
deleted file mode 100644
index 768fde2..0000000
--- a/server/plugin/quota/counter/counter.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) 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 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 counter
-
-import (
- "github.com/apache/servicecomb-service-center/server/plugin/discovery"
-)
-
-var counters = Counters{}
-
-type Counter interface {
- OnCreate(t discovery.Type, domainProject string)
- OnDelete(t discovery.Type, domainProject string)
-}
-
-type Counters []Counter
-
-func (cs Counters) OnCreate(t discovery.Type, domainProject string) {
- for _, c := range cs {
- c.OnCreate(t, domainProject)
- }
-}
-
-func (cs Counters) OnDelete(t discovery.Type, domainProject string) {
- for _, c := range cs {
- c.OnDelete(t, domainProject)
- }
-}
-
-func RegisterCounter(c Counter) {
- counters = append(counters, c)
-}
-
-func GetCounters() Counters {
- return counters
-}
diff --git a/server/plugin/quota/counter/event.go b/server/plugin/quota/counter/event.go
deleted file mode 100644
index 898478e..0000000
--- a/server/plugin/quota/counter/event.go
+++ /dev/null
@@ -1,111 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) 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 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 counter
-
-import (
- "context"
-
- "github.com/apache/servicecomb-service-center/pkg/log"
- "github.com/apache/servicecomb-service-center/pkg/registry"
- "github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/apache/servicecomb-service-center/server/core"
- "github.com/apache/servicecomb-service-center/server/core/backend"
- "github.com/apache/servicecomb-service-center/server/core/proto"
- "github.com/apache/servicecomb-service-center/server/plugin/discovery"
- serviceUtil "github.com/apache/servicecomb-service-center/server/service/util"
- "github.com/astaxie/beego"
-)
-
-var (
- SharedServiceIds util.ConcurrentMap
-)
-
-// ServiceIndexEventHandler counting the number of services
-// Deprecated: Use metrics instead.
-type ServiceIndexEventHandler struct {
-}
-
-func (h *ServiceIndexEventHandler) Type() discovery.Type {
- return backend.ServiceIndex
-}
-
-func (h *ServiceIndexEventHandler) OnEvent(evt discovery.KvEvent) {
- key := core.GetInfoFromSvcIndexKV(evt.KV.Key)
- if core.IsShared(key) {
- SharedServiceIds.Put(key.Tenant+core.SPLIT+evt.KV.Value.(string), struct{}{})
- return
- }
-
- switch evt.Type {
- case registry.EVT_INIT, registry.EVT_CREATE:
- GetCounters().OnCreate(h.Type(), key.Tenant)
- case registry.EVT_DELETE:
- GetCounters().OnDelete(h.Type(), key.Tenant)
- default:
- }
-}
-
-func NewServiceIndexEventHandler() *ServiceIndexEventHandler {
- return &ServiceIndexEventHandler{}
-}
-
-// InstanceEventHandler counting the number of instances
-// Deprecated: Use metrics instead.
-type InstanceEventHandler struct {
- SharedServiceIds map[string]struct{}
-}
-
-func (h *InstanceEventHandler) Type() discovery.Type {
- return backend.INSTANCE
-}
-
-func (h *InstanceEventHandler) OnEvent(evt discovery.KvEvent) {
- serviceID, _, domainProject := core.GetInfoFromInstKV(evt.KV.Key)
- key := domainProject + core.SPLIT + serviceID
- if _, ok := SharedServiceIds.Get(key); ok {
- return
- }
-
- switch evt.Type {
- case registry.EVT_INIT, registry.EVT_CREATE:
- if domainProject == core.RegistryDomainProject {
- service, err := serviceUtil.GetService(context.Background(), domainProject, serviceID)
- if service == nil || err != nil {
- log.Errorf(err, "GetService[%s] failed", key)
- return
- }
- if core.IsShared(proto.MicroServiceToKey(domainProject, service)) {
- SharedServiceIds.Put(key, struct{}{})
- return
- }
- }
- GetCounters().OnCreate(h.Type(), domainProject)
- case registry.EVT_DELETE:
- GetCounters().OnDelete(h.Type(), domainProject)
- }
-}
-
-func NewInstanceEventHandler() *InstanceEventHandler {
- return &InstanceEventHandler{SharedServiceIds: make(map[string]struct{})}
-}
-
-func RegisterCounterListener(pluginName string) {
- if pluginName != beego.AppConfig.DefaultString("quota_plugin", "buildin") {
- return
- }
- discovery.AddEventHandler(NewServiceIndexEventHandler())
- discovery.AddEventHandler(NewInstanceEventHandler())
-}
diff --git a/server/plugin/quota/counter/event_test.go b/server/plugin/quota/counter/event_test.go
deleted file mode 100644
index 7ad6699..0000000
--- a/server/plugin/quota/counter/event_test.go
+++ /dev/null
@@ -1,261 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) 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 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 counter
-
-import (
- "testing"
-
- registry2 "github.com/apache/servicecomb-service-center/pkg/registry"
- "github.com/apache/servicecomb-service-center/server/core"
- "github.com/apache/servicecomb-service-center/server/core/backend"
- "github.com/apache/servicecomb-service-center/server/plugin/discovery"
-)
-
-type mockCounter struct {
- ServiceCount int64
- InstanceCount int64
-}
-
-func (c *mockCounter) OnCreate(t discovery.Type, domainProject string) {
- switch t {
- case backend.ServiceIndex:
- c.ServiceCount++
- case backend.INSTANCE:
- c.InstanceCount++
- default:
- panic("error")
- }
-}
-
-func (c *mockCounter) OnDelete(t discovery.Type, domainProject string) {
- switch t {
- case backend.ServiceIndex:
- c.ServiceCount--
- case backend.INSTANCE:
- c.InstanceCount--
- default:
- panic("error")
- }
-}
-
-func TestNewServiceIndexEventHandler(t *testing.T) {
-
- var counter = mockCounter{}
- RegisterCounter(&counter)
- h := NewServiceIndexEventHandler()
-
- cases := []discovery.KvEvent{
- {
- Type: registry2.EVT_INIT,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateServiceIndexKey(®istry2.MicroServiceKey{
- Tenant: core.RegistryDomainProject,
- Project: "",
- AppId: core.RegistryAppID,
- ServiceName: core.RegistryServiceName,
- Version: "e",
- Environment: "f",
- Alias: "g",
- })),
- Value: "1",
- },
- },
- {
- Type: registry2.EVT_UPDATE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateServiceIndexKey(®istry2.MicroServiceKey{
- Tenant: core.RegistryDomainProject,
- Project: "",
- AppId: core.RegistryAppID,
- ServiceName: core.RegistryServiceName,
- Version: "e",
- Environment: "f",
- Alias: "g",
- })),
- Value: "1",
- },
- },
- {
- Type: registry2.EVT_DELETE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateServiceIndexKey(®istry2.MicroServiceKey{
- Tenant: core.RegistryDomainProject,
- Project: "",
- AppId: core.RegistryAppID,
- ServiceName: core.RegistryServiceName,
- Version: "e",
- Environment: "f",
- Alias: "g",
- })),
- Value: "1",
- },
- },
- {
- Type: registry2.EVT_CREATE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateServiceIndexKey(®istry2.MicroServiceKey{
- Tenant: core.RegistryDomainProject,
- Project: "",
- AppId: core.RegistryAppID,
- ServiceName: core.RegistryServiceName,
- Version: "e",
- Environment: "f",
- Alias: "g",
- })),
- Value: "1",
- },
- },
- {
- Type: registry2.EVT_INIT,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateServiceIndexKey(®istry2.MicroServiceKey{
- Tenant: "a/b",
- Project: "",
- AppId: "c",
- ServiceName: "d",
- Version: "e",
- Environment: "f",
- Alias: "g",
- })),
- Value: "1",
- },
- },
- {
- Type: registry2.EVT_DELETE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateServiceIndexKey(®istry2.MicroServiceKey{
- Tenant: "a/b",
- Project: "",
- AppId: "c",
- ServiceName: "d",
- Version: "e",
- Environment: "f",
- Alias: "g",
- })),
- Value: "1",
- },
- },
- {
- Type: registry2.EVT_UPDATE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateServiceIndexKey(®istry2.MicroServiceKey{
- Tenant: "a/b",
- Project: "",
- AppId: "c",
- ServiceName: "d",
- Version: "e",
- Environment: "f",
- Alias: "g",
- })),
- Value: "1",
- },
- },
- {
- Type: registry2.EVT_CREATE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateServiceIndexKey(®istry2.MicroServiceKey{
- Tenant: "a/b",
- Project: "",
- AppId: "c",
- ServiceName: "d",
- Version: "e",
- Environment: "f",
- Alias: "g",
- })),
- Value: "1",
- },
- },
- }
-
- for _, evt := range cases {
- h.OnEvent(evt)
- }
- if counter.ServiceCount != 1 || counter.InstanceCount != 0 {
- t.Fatal("TestNewServiceIndexEventHandler failed", counter)
- }
-}
-
-func TestNewInstanceEventHandler(t *testing.T) {
- var counter = mockCounter{}
- RegisterCounter(&counter)
- h := NewInstanceEventHandler()
- SharedServiceIds.Put(core.RegistryDomainProject+core.SPLIT+"2", struct{}{})
- cases := []discovery.KvEvent{
- {
- Type: registry2.EVT_INIT,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateInstanceKey(core.RegistryDomainProject, "2", "1")),
- Value: nil,
- },
- },
- {
- Type: registry2.EVT_UPDATE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateInstanceKey(core.RegistryDomainProject, "2", "1")),
- Value: nil,
- },
- },
- {
- Type: registry2.EVT_CREATE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateInstanceKey(core.RegistryDomainProject, "2", "1")),
- Value: nil,
- },
- },
- {
- Type: registry2.EVT_DELETE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateInstanceKey(core.RegistryDomainProject, "2", "1")),
- Value: nil,
- },
- },
- {
- Type: registry2.EVT_INIT,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateInstanceKey("a/b", "1", "1")),
- Value: nil,
- },
- },
- {
- Type: registry2.EVT_DELETE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateInstanceKey("a/b", "1", "1")),
- Value: nil,
- },
- },
- {
- Type: registry2.EVT_UPDATE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateInstanceKey("a/b", "1", "1")),
- Value: nil,
- },
- },
- {
- Type: registry2.EVT_CREATE,
- KV: &discovery.KeyValue{
- Key: []byte(core.GenerateInstanceKey("a/b", "1", "1")),
- Value: nil,
- },
- },
- }
-
- for _, evt := range cases {
- h.OnEvent(evt)
- }
- if counter.InstanceCount != 1 || counter.ServiceCount != 0 {
- t.Fatal("TestNewServiceIndexEventHandler failed", counter)
- }
-}
diff --git a/server/plugin/registry/metrics.go b/server/plugin/registry/metrics.go
index 565e837..edda004 100644
--- a/server/plugin/registry/metrics.go
+++ b/server/plugin/registry/metrics.go
@@ -20,7 +20,7 @@ package registry
import (
"time"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/prometheus/client_golang/prometheus"
)
@@ -32,7 +32,7 @@ const (
var (
backendCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "backend_total",
Help: "Gauge of the backend instance",
@@ -40,7 +40,7 @@ var (
operationCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "backend_operation_total",
Help: "Counter of backend operation",
@@ -48,11 +48,11 @@ var (
operationLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
- Namespace: metric.FamilyName,
+ Namespace: metrics.FamilyName,
Subsystem: "db",
Name: "backend_operation_durations_microseconds",
Help: "Latency of backend operation",
- Objectives: metric.Pxx,
+ Objectives: metrics.Pxx,
}, []string{"instance", "operation", "status"})
)
@@ -61,12 +61,12 @@ func init() {
}
func ReportBackendInstance(c int) {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
backendCounter.WithLabelValues(instance).Set(float64(c))
}
func ReportBackendOperationCompleted(operation string, err error, start time.Time) {
- instance := metric.InstanceName()
+ instance := metrics.InstanceName()
elapsed := float64(time.Since(start).Nanoseconds()) / float64(time.Microsecond)
status := success
if err != nil {
diff --git a/server/plugin/tracing/pzipkin/common.go b/server/plugin/tracing/pzipkin/common.go
index 7ac0548..d427196 100644
--- a/server/plugin/tracing/pzipkin/common.go
+++ b/server/plugin/tracing/pzipkin/common.go
@@ -26,7 +26,7 @@ import (
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/server/core"
- "github.com/apache/servicecomb-service-center/server/metric"
+ "github.com/apache/servicecomb-service-center/server/metrics"
"github.com/opentracing/opentracing-go"
zipkin "github.com/openzipkin/zipkin-go-opentracing"
)
@@ -45,7 +45,7 @@ func initTracer() {
log.Errorf(err, "new tracing collector failed, use the noop tracer")
return
}
- ipPort := metric.InstanceName()
+ ipPort := metrics.InstanceName()
recorder := zipkin.NewRecorder(collector, false, ipPort, strings.ToLower(core.Service.ServiceName))
tracer, err := zipkin.NewTracer(recorder,
zipkin.TraceID128Bit(true),
diff --git a/server/service/event/domain_event_handler.go b/server/service/event/domain_event_handler.go
deleted file mode 100644
index 60fcf9b..0000000
--- a/server/service/event/domain_event_handler.go
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) 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 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 event
-
-import (
- "github.com/apache/servicecomb-service-center/pkg/registry"
- "github.com/apache/servicecomb-service-center/server/core/backend"
- "github.com/apache/servicecomb-service-center/server/plugin/discovery"
- "github.com/apache/servicecomb-service-center/server/service/metrics"
-)
-
-// DomainEventHandler report domain & project total number
-type DomainEventHandler struct {
-}
-
-func (h *DomainEventHandler) Type() discovery.Type {
- return backend.DOMAIN
-}
-
-func (h *DomainEventHandler) OnEvent(evt discovery.KvEvent) {
- action := evt.Type
- switch action {
- case registry.EVT_INIT, registry.EVT_CREATE:
- metrics.ReportDomains(1)
- case registry.EVT_DELETE:
- metrics.ReportDomains(-1)
- }
-}
-
-func NewDomainEventHandler() *DomainEventHandler {
- return &DomainEventHandler{}
-}
diff --git a/server/service/event/event.go b/server/service/event/event.go
index 8fe602f..bde1091 100644
--- a/server/service/event/event.go
+++ b/server/service/event/event.go
@@ -21,12 +21,10 @@ import (
)
func init() {
- discovery.AddEventHandler(NewDomainEventHandler())
discovery.AddEventHandler(NewServiceEventHandler())
discovery.AddEventHandler(NewInstanceEventHandler())
discovery.AddEventHandler(NewRuleEventHandler())
discovery.AddEventHandler(NewTagEventHandler())
discovery.AddEventHandler(NewDependencyEventHandler())
discovery.AddEventHandler(NewDependencyRuleEventHandler())
- discovery.AddEventHandler(NewSchemaSummaryEventHandler())
}
diff --git a/server/service/event/instance_event_handler.go b/server/service/event/instance_event_handler.go
index 46f9b3a..b30871b 100644
--- a/server/service/event/instance_event_handler.go
+++ b/server/service/event/instance_event_handler.go
@@ -30,15 +30,9 @@ import (
"github.com/apache/servicecomb-service-center/server/event"
"github.com/apache/servicecomb-service-center/server/plugin/discovery"
"github.com/apache/servicecomb-service-center/server/service/cache"
- "github.com/apache/servicecomb-service-center/server/service/metrics"
serviceUtil "github.com/apache/servicecomb-service-center/server/service/util"
)
-const (
- increaseOne = 1
- decreaseOne = -1
-)
-
// InstanceEventHandler is the handler to handle:
// 1. report instance metrics
// 2. recover the instance quota
@@ -57,33 +51,19 @@ func (h *InstanceEventHandler) OnEvent(evt discovery.KvEvent) {
providerID, providerInstanceID, domainProject := apt.GetInfoFromInstKV(evt.KV.Key)
idx := strings.Index(domainProject, "/")
domainName := domainProject[:idx]
- projectName := domainProject[idx+1:]
ctx := context.WithValue(context.WithValue(context.Background(),
util.CtxCacheOnly, "1"),
util.CtxGlobal, "1")
- var count float64 = increaseOne
if action == pb.EVT_INIT {
- metrics.ReportInstances(domainName, count)
- ms, err := serviceUtil.GetService(ctx, domainProject, providerID)
- if err != nil {
- log.Warnf("caught [%s] instance[%s/%s] event, endpoints %v, get cached provider's file failed",
- action, providerID, providerInstanceID, instance.Endpoints)
- return
- }
- frameworkName, frameworkVersion := getFramework(ms)
- metrics.ReportFramework(domainName, projectName, frameworkName, frameworkVersion, count)
return
}
- if action == pb.EVT_DELETE {
- count = decreaseOne
- if !apt.IsDefaultDomainProject(domainProject) {
- projectName := domainProject[idx+1:]
- serviceUtil.RemandInstanceQuota(
- util.SetDomainProject(context.Background(), domainName, projectName))
- }
+ if action == pb.EVT_DELETE && !apt.IsDefaultDomainProject(domainProject) {
+ projectName := domainProject[idx+1:]
+ serviceUtil.RemandInstanceQuota(
+ util.SetDomainProject(context.Background(), domainName, projectName))
}
// 查询服务版本信息
@@ -100,12 +80,6 @@ func (h *InstanceEventHandler) OnEvent(evt discovery.KvEvent) {
return
}
- if action != pb.EVT_UPDATE {
- frameworkName, frameworkVersion := getFramework(ms)
- metrics.ReportInstances(domainName, count)
- metrics.ReportFramework(domainName, projectName, frameworkName, frameworkVersion, count)
- }
-
log.Infof("caught [%s] service[%s][%s/%s/%s/%s] instance[%s] event, endpoints %v",
action, providerID, ms.Environment, ms.AppId, ms.ServiceName, ms.Version,
providerInstanceID, instance.Endpoints)
diff --git a/server/service/event/schema_summary_event_handler.go b/server/service/event/schema_summary_event_handler.go
deleted file mode 100644
index 4aba1c0..0000000
--- a/server/service/event/schema_summary_event_handler.go
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) 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 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 event
-
-import (
- "strings"
-
- pb "github.com/apache/servicecomb-service-center/pkg/registry"
- "github.com/apache/servicecomb-service-center/server/core"
- "github.com/apache/servicecomb-service-center/server/core/backend"
- "github.com/apache/servicecomb-service-center/server/plugin/discovery"
- "github.com/apache/servicecomb-service-center/server/service/metrics"
-)
-
-// SchemaSummaryEventHandler report schema metrics
-type SchemaSummaryEventHandler struct {
-}
-
-func (h *SchemaSummaryEventHandler) Type() discovery.Type {
- return backend.SchemaSummary
-}
-
-func (h *SchemaSummaryEventHandler) OnEvent(evt discovery.KvEvent) {
- action := evt.Type
- switch action {
- case pb.EVT_INIT, pb.EVT_CREATE, pb.EVT_DELETE:
- domainProject, _, _ := core.GetInfoFromSchemaSummaryKV(evt.KV.Key)
- idx := strings.Index(domainProject, "/")
- newDomain := domainProject[:idx]
- if pb.EVT_DELETE == action {
- metrics.ReportSchemas(newDomain, -1)
- } else {
- metrics.ReportSchemas(newDomain, 1)
- }
- default:
- }
-}
-
-func NewSchemaSummaryEventHandler() *SchemaSummaryEventHandler {
- return &SchemaSummaryEventHandler{}
-}
diff --git a/server/service/event/service_event_handler.go b/server/service/event/service_event_handler.go
index e45fab0..7cdbd7f 100644
--- a/server/service/event/service_event_handler.go
+++ b/server/service/event/service_event_handler.go
@@ -27,7 +27,6 @@ import (
"github.com/apache/servicecomb-service-center/server/core/proto"
"github.com/apache/servicecomb-service-center/server/plugin/discovery"
"github.com/apache/servicecomb-service-center/server/service/cache"
- "github.com/apache/servicecomb-service-center/server/service/metrics"
serviceUtil "github.com/apache/servicecomb-service-center/server/service/util"
)
@@ -45,7 +44,6 @@ func (h *ServiceEventHandler) Type() discovery.Type {
func (h *ServiceEventHandler) OnEvent(evt discovery.KvEvent) {
ms := evt.KV.Value.(*pb.MicroService)
_, domainProject := core.GetInfoFromSvcKV(evt.KV.Key)
- fn, fv := getFramework(ms)
switch evt.Type {
case pb.EVT_INIT, pb.EVT_CREATE:
@@ -56,11 +54,6 @@ func (h *ServiceEventHandler) OnEvent(evt discovery.KvEvent) {
if err != nil {
log.Errorf(err, "new domain[%s] or project[%s] failed", newDomain, newProject)
}
- metrics.ReportServices(newDomain, fn, fv, 1)
- case pb.EVT_DELETE:
- domainName := domainProject[:strings.Index(domainProject, "/")]
- metrics.ReportServices(domainName, fn, fv, -1)
- default:
}
if evt.Type == pb.EVT_INIT {
@@ -75,17 +68,6 @@ func (h *ServiceEventHandler) OnEvent(evt discovery.KvEvent) {
cache.FindInstances.Remove(providerKey)
}
-func getFramework(ms *pb.MicroService) (string, string) {
- if ms.Framework != nil && len(ms.Framework.Name) > 0 {
- version := ms.Framework.Version
- if len(ms.Framework.Version) == 0 {
- version = "UNKNOWN"
- }
- return ms.Framework.Name, version
- }
- return "UNKNOWN", "UNKNOWN"
-}
-
func NewServiceEventHandler() *ServiceEventHandler {
return &ServiceEventHandler{}
}