SCB-1518 upgrade go chassis, new image for out of box edge service (#76)
* upgrade go chassis
* add license header
diff --git a/README.md b/README.md
index 9da0058..8f69195 100644
--- a/README.md
+++ b/README.md
@@ -58,6 +58,19 @@
- tar file: release/mesher-latest-linux-amd64.tar
- docker image name: servicecomb/mesher-sidecar:latest
+#### Build mesher edge service
+```shell script
+sudo docker build -t servicecomb/mesher-edge -f docker/edge/Dockerfile .
+```
+
+### How to run
+#### edge service
+```shell script
+sudo docker run -e PAAS_CSE_SC_ENDPOINT="" \
+-e PAAS_CSE_CC_ENDPOINT="" \
+-p 80:30101 \
+--name mesher-edge servicecomb/mesher-edge
+```
# Documentations
You can see more documentations in [here](https://mesher.readthedocs.io/en/latest/),
this online doc is for latest version of mesher, if you want to see your version's doc,
diff --git a/cmd/mesher/mesher.go b/cmd/mesher/mesher.go
index 007ff20..e450ce7 100644
--- a/cmd/mesher/mesher.go
+++ b/cmd/mesher/mesher.go
@@ -27,7 +27,7 @@
_ "github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/server"
_ "github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/simpleRegistry"
// config server
- _ "github.com/go-chassis/go-chassis-config/servicecombkie"
+ _ "github.com/go-chassis/go-chassis-config/servicecomb"
//protocols
_ "github.com/apache/servicecomb-mesher/proxy/protocol/grpc"
_ "github.com/apache/servicecomb-mesher/proxy/protocol/http"
diff --git a/deployments/docker/db.js b/deployments/docker/db.js
new file mode 100644
index 0000000..2f1ff7a
--- /dev/null
+++ b/deployments/docker/db.js
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+db.createUser(
+ {
+ user: "kie",
+ pwd: "123",
+ roles:[
+ {
+ role: "readWrite",
+ db: "kie"
+ }
+ ]
+ }
+);
\ No newline at end of file
diff --git a/deployments/docker/docker-compose.yaml b/deployments/docker/docker-compose.yaml
new file mode 100644
index 0000000..2018e2e
--- /dev/null
+++ b/deployments/docker/docker-compose.yaml
@@ -0,0 +1,83 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+version: '3.1'
+services:
+ mongo:
+ image: mongo:3.4
+ restart: always
+ ports:
+ - 27017:27017
+ environment:
+ MONGO_INITDB_DATABASE: kie
+ MONGO_INITDB_ROOT_USERNAME: kie
+ MONGO_INITDB_ROOT_PASSWORD: 123
+ volumes:
+ - ./db.js:/docker-entrypoint-initdb.d/db.js:ro
+ mongo-express:
+ image: mongo-express
+ restart: always
+ ports:
+ - 8081:8081
+ environment:
+ ME_CONFIG_MONGODB_ADMINUSERNAME: kie
+ ME_CONFIG_MONGODB_ADMINPASSWORD: 123
+ kie:
+ image: servicecomb/kie:latest
+ restart: always
+ ports:
+ - 30110:30110
+ environment:
+ MONGODB_USER: kie
+ MONGODB_PWD: 123
+ MONGODB_ADDR: mongo
+ etcd:
+ image: 'quay.io/coreos/etcd:latest'
+ # restart: always
+ environment:
+ ETCD_ADVERTISE_CLIENT_URLS: http://etcd:2379
+ ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
+ ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd:2380
+ ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
+ ETCD_INITIAL_CLUSTER: default=http://etcd:2380
+
+ service-center:
+ depends_on:
+ - etcd
+ image: 'servicecomb/service-center:latest'
+ ports:
+ - "30100:30100"
+ environment:
+ BACKEND_ADDRESS: etcd:2379
+
+ scfrontend:
+ depends_on:
+ - service-center
+ image: 'servicecomb/scfrontend:latest'
+ ports:
+ - "30103:30103"
+ environment:
+ SC_ADDRESS: http://service-center:30100
+ mesher-edge:
+ depends_on:
+ - service-center
+ - kie
+ image: 'servicecomb/mesher-edge:latest'
+ ports:
+ - "80:30101"
+ environment:
+ PAAS_CSE_SC_ENDPOINT: service-center:30100
+ PAAS_CSE_CC_ENDPOINT: kie:30110
\ No newline at end of file
diff --git a/docker/edge/Dockerfile b/docker/edge/Dockerfile
new file mode 100644
index 0000000..45aba70
--- /dev/null
+++ b/docker/edge/Dockerfile
@@ -0,0 +1,38 @@
+# 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.
+
+FROM golang:1.12.10 as builder
+
+COPY . /servicecomb-mesher/
+WORKDIR /servicecomb-mesher/
+ENV GOPROXY=https://goproxy.io
+RUN go build -a github.com/apache/servicecomb-mesher/cmd/mesher
+
+
+FROM frolvlad/alpine-glibc:latest
+RUN mkdir -p /opt/mesher && \
+ mkdir -p /etc/mesher/conf && \
+ mkdir -p /etc/ssl/mesher/
+# To upload schemas using env enable SCHEMA_ROOT as environment variable using dockerfile or pass while running container
+#ENV SCHEMA_ROOT=/etc/chassis-go/schemas umcomment in future
+
+ENV CHASSIS_HOME=/opt/mesher/
+
+COPY --from=builder /servicecomb-mesher/mesher $CHASSIS_HOME
+COPY docker/edge/microservice.yaml docker/edge/chassis.yaml docker/edge/lager.yaml $CHASSIS_HOME/conf/
+COPY docker/edge/mesher.yaml /etc/mesher/conf/
+COPY docker/edge/start.sh $CHASSIS_HOME
+WORKDIR $CHASSIS_HOME
+ENTRYPOINT ["sh", "/opt/mesher/start.sh"]
diff --git a/docker/edge/chassis.yaml b/docker/edge/chassis.yaml
new file mode 100644
index 0000000..974dbd4
--- /dev/null
+++ b/docker/edge/chassis.yaml
@@ -0,0 +1,55 @@
+# 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.
+
+---
+cse:
+ protocols:
+ http:
+ listenAddress: 127.0.0.1:30101
+ rest-admin:
+ listenAddress: 127.0.0.1:30102 # listen addr use to adminAPI
+ service:
+ registry:
+ address: http://127.0.0.1:30100 # uri of service center
+ scope: full #set full to be able to discover other app's service
+ config:
+ client:
+ serverUri: https://127.0.0.1:30110 #uri of config center
+ type: servicecomb-kie
+ refreshMode: 1 # 1: only pull config.
+ refreshInterval: 30 # unit is second
+ handler:
+ chain:
+ Consumer:
+ outgoing: router,bizkeeper-consumer,loadbalance,tracing-consumer,transport #consumer handlers
+ Provider:
+ incoming: tracing-provider #provider handlers
+
+## Mesher TLS is base on Go Chassis TLS config, https://docs.go-chassis.com/user-guides/tls.html
+ssl:
+# mesher-edge.rest.Provider.cipherPlugin: default
+# mesher-edge.rest.Provider.verifyPeer: false
+# mesher-edge.rest.Provider.cipherSuits: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
+# mesher-edge.rest.Provider.protocol: TLSv1.2
+# mesher-edge.rest.Provider.caFile:
+# mesher-edge.rest.Provider.certFile: server.crt
+# mesher-edge.rest.Provider.keyFile: server.key
+# mesher-edge.rest.Provider.certPwdFile:
+
+#tracing:
+# enabled: true #enable distribution tracing
+# collectorType: zipkin #zipkin: Send tracing info to zipkin server
+# #namedPipe: Write tracing info to linux named pipe.
+# collectorTarget: http://localhost:9411/api/v1/spans #If the collectorType is "zipkin", the target is a zipkin server url, if the collecterType is "file" or "namedPipe", the target is a file path.
diff --git a/docker/edge/lager.yaml b/docker/edge/lager.yaml
new file mode 100755
index 0000000..b5c962c
--- /dev/null
+++ b/docker/edge/lager.yaml
@@ -0,0 +1,37 @@
+# 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.
+
+---
+# LoggerLevel: |DEBUG|INFO|WARN|ERROR|FATAL
+logger_level: DEBUG
+
+# LoggerFile: used to output the name of log.可配置绝对路径,也可以配置用于拼接CHASSIS_HOME的相对路径。
+logger_file: log/mesher.log
+
+# LogFormatText:设定日志的输出格式是 json 还是 plaintext (类似于log4j),默认为 false,不建议修改,如果开发过程中想本地查看日志的话,
+# 可以设定 LoggerFile 和 LogFormatText 为 true,这样会输出类似于 log4j 格式的本地日志。
+log_format_text: false
+
+#rollingPolicy daily/size;用于配置根据时间,还是根据大小进行日志rotate操作。
+rollingPolicy: size
+
+# MaxDaily of a log file before rotate. By D Days.;日志rotate时间配置,单位"day"。
+log_rotate_date: 1
+
+# MaxSize of a log file before rotate. By M Bytes.;日志rotate文件大小配置,单位"MB"。
+log_rotate_size: 10
+
+# Max counts to keep of a log's backup files.日志最大存储数量,单位“个”。
+log_backup_count: 7
\ No newline at end of file
diff --git a/docker/edge/mesher.yaml b/docker/edge/mesher.yaml
new file mode 100644
index 0000000..3b62adf
--- /dev/null
+++ b/docker/edge/mesher.yaml
@@ -0,0 +1,55 @@
+# 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.
+
+## Router rules and fault injection rules are moved to router.yaml
+#plugin:
+# destinationResolver:
+# http: host # how to turn host to destination name. default to service name,
+
+admin: #admin API
+ goRuntimeMetrics : true # enable metrics
+ enable: true
+
+## enable pprof to profile mesher runtime
+#pprof:
+# enable: false
+
+#mesher:
+# ingress:
+# type: servicecomb
+# rule:
+# http: |
+# - host: example.com
+# limit: 30
+# apiPath: /some/api
+# service:
+# name: example
+# redirectPath: /another/api
+# port:
+# name: http-legacy
+# value: 8080
+# - apiPath: /sayerror/api
+# service:
+# name: Server
+# redirectPath: /sayerror
+# port:
+# name: http
+# value: 8080
+# - apiPath: /some/api
+# service:
+# name: Server
+# port:
+# name: http
+# value: 8080
\ No newline at end of file
diff --git a/docker/edge/microservice.yaml b/docker/edge/microservice.yaml
new file mode 100644
index 0000000..7b49d0c
--- /dev/null
+++ b/docker/edge/microservice.yaml
@@ -0,0 +1,18 @@
+# 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.
+
+service_description:
+ name: mesher-edge
+ version: 1.7.0
diff --git a/docker/edge/start.sh b/docker/edge/start.sh
new file mode 100644
index 0000000..13f255f
--- /dev/null
+++ b/docker/edge/start.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# 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.
+
+set -e
+
+MESHER_DIR=$(cd $(dirname $0); pwd)
+MESHER_CONF_DIR="$MESHER_DIR/conf"
+
+MESHER_YAML="mesher.yaml"
+ETC_CONF_DIR="/etc/mesher/conf"
+
+CHASSIS_YAML="chassis.yaml"
+MICROSERVICE_YAML="microservice.yaml"
+MONITORING_YAML="monitoring.yaml"
+LAGER_YAML="lager.yaml"
+TLS_YAML="tls.yaml"
+AUTH_YAML="auth.yaml"
+TRACING_YAML="tracing.yaml"
+
+TMP_DIR="/tmp"
+
+check_config_files(){
+ # configs can be mounted, maybe config map
+ if [ -f "$TMP_DIR/$MESHER_YAML" ]; then
+ echo "$MESHER_YAML is customed"
+ cp -f $TMP_DIR/$MESHER_YAML $ETC_CONF_DIR/$MESHER_YAML
+ fi
+ copy_tmp2mesher $CHASSIS_YAML
+ copy_tmp2mesher $MONITORING_YAML
+ copy_tmp2mesher $LAGER_YAML
+ copy_tmp2mesher $TLS_YAML
+ copy_tmp2mesher $AUTH_YAML
+ copy_tmp2mesher $TRACING_YAML
+}
+copy_tmp2mesher(){
+ if [ -f $TMP_DIR/$1 ]; then
+ echo "$1 is customed"
+ cp -f $TMP_DIR/$1 $MESHER_CONF_DIR/$1
+ fi
+}
+
+check_config_files
+
+net_name=$(ip -o -4 route show to default | awk '{print $5}')
+listen_addr=$(ifconfig $net_name | grep -E 'inet\W' | grep -o -E [0-9]+.[0-9]+.[0-9]+.[0-9]+ | head -n 1)
+
+# replace ip addr
+sed -i s/"listenAddress:\s\{1,\}[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}"/"listenAddress: $listen_addr"/g $MESHER_CONF_DIR/$CHASSIS_YAML
+
+exec $MESHER_DIR/mesher --config $ETC_CONF_DIR/$MESHER_YAML --mode edge
diff --git a/docs/configurations/admin.md b/docs/configurations/admin.md
index 3354953..0dffc61 100644
--- a/docs/configurations/admin.md
+++ b/docs/configurations/admin.md
@@ -16,13 +16,10 @@
```yaml
admin:
enable: true
- goRuntimeMetrics : true # enable metrics
```
**admin.enable**
>*(optional, bool)* default is false
-**admin.goRuntimeMetrics**
->*(optional, bool)* default is false, enable to expose go runtime metrics in /v1/mesher/metrics
diff --git a/examples/edge/conf/chassis.yaml b/examples/edge/conf/chassis.yaml
index 0ab8bd4..de8325b 100644
--- a/examples/edge/conf/chassis.yaml
+++ b/examples/edge/conf/chassis.yaml
@@ -8,71 +8,27 @@
service:
registry:
address: http://127.0.0.1:30100 # uri of service center
- #address: https://cse.cn-north-1.myhuaweicloud.com:443 # uri of service center
scope: full #set full to be able to discover other app's service
- watch: false # set if you want to watch instance change event
- autoIPIndex: true # set to true if u want to resolve source IP to micro service
-# config:
-# client:
-# serverUri: https://127.0.0.1:30110 #uri of config center
-# type: servicecomb-kie
-# refreshMode: 1 # 1: only pull config.
-# refreshInterval: 30 # unit is second
- # monitor: #Send monitoring data to CSE monitor Server
- # client:
- # serverUri: https://cse.cn-north-1.myhuaweicloud.com:443 # monitor server url
+ config:
+ client:
+ serverUri: https://127.0.0.1:30110 #uri of config center
+ type: servicecomb-kie
+ refreshMode: 1 # 1: only pull config.
+ refreshInterval: 30 # unit is second
handler:
chain:
Consumer:
- outgoing: router,bizkeeper-consumer,loadbalance,tracing-consumer,transport #consumer handlers
+ outgoing: router,bizkeeper-consumer,loadbalance,tracing-consumer,transport #consumer handlers
Provider:
- incoming: tracing-provider #provider handlers
-# loadbalance:
-# strategy:
-# name: RoundRobin # Random|RoundRobin|SessionStickiness
-# retryEnabled: false # if there is error, retry request or not
-# retryOnNext: 2 # times to switch to another instance based on strategy
-# retryOnSame: 3 # times to retry on the same instance
-# backoff: # backoff policy of retried request
-# kind: constant # jittered/constant/zero
-# MinMs: 200 # millisecond, Minimum duration to backoff
-# MaxMs: 400 # millisecond, Maximum duration to backoff
-## circuit breaker configurations
-# isolation:
-# Consumer:
-# timeout:
-# enabled: true
-# timeoutInMilliseconds: 1000
-# maxConcurrentRequests: 100
-# circuitBreaker:
-# Consumer:
-# enabled: true
-# forceOpen: false
-# forceClosed: false
-# sleepWindowInMilliseconds: 10000
-# requestVolumeThreshold: 20
-# errorThresholdPercentage: 50
-# fallback:
-# Consumer:
-# enabled: true
-# maxConcurrentRequests: 20
-# fallbackpolicy:
-# Consumer:
-# policy: throwexception
+ incoming: tracing-provider #provider handlers
-## Mesher TLS is base on Go Chassis TLS config
+## Mesher TLS is base on Go Chassis TLS config, https://docs.go-chassis.com/user-guides/tls.html
ssl:
# mesher-edge.rest.Provider.cipherPlugin: default
# mesher-edge.rest.Provider.verifyPeer: false
# mesher-edge.rest.Provider.cipherSuits: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
# mesher-edge.rest.Provider.protocol: TLSv1.2
# mesher-edge.rest.Provider.caFile:
- mesher-edge.rest.Provider.certFile: server.crt
- mesher-edge.rest.Provider.keyFile: server.key
-# mesher-edge.rest.Provider.certPwdFile:
-
-#tracing:
-# enabled: true #enable distribution tracing
-# collectorType: zipkin #zipkin: Send tracing info to zipkin server
-# #namedPipe: Write tracing info to linux named pipe.
-# collectorTarget: http://localhost:9411/api/v1/spans #If the collectorType is "zipkin", the target is a zipkin server url, if the collecterType is "file" or "namedPipe", the target is a file path.
+# mesher-edge.rest.Provider.certFile: server.crt
+# mesher-edge.rest.Provider.keyFile: server.key
+# mesher-edge.rest.Provider.certPwdFile:
\ No newline at end of file
diff --git a/examples/edge/conf/mesher.yaml b/examples/edge/conf/mesher.yaml
index 55aa97f..4c5a62f 100644
--- a/examples/edge/conf/mesher.yaml
+++ b/examples/edge/conf/mesher.yaml
@@ -11,42 +11,30 @@
#pprof:
# enable: false
-
-# this health check will ping local service port to check if service is still alive, if service can not reachable, mesher
-# will update status to OUT_OF_SERVICE in service center
-#localHealthCheck:
-# - port: 8080
-# uri: /health
-# interval: 30s
-# match:
-# status: 200
-# body: ok
-
-
-mesher:
- ingress:
- type: servicecomb
- rule:
- http: |
- - host: example.com
- limit: 30
- apiPath: /some/api
- service:
- name: example
- redirectPath: /another/api
- port:
- name: http-legacy
- value: 8080
- - apiPath: /sayerror/api
- service:
- name: Server
- redirectPath: /sayerror
- port:
- name: http
- value: 8080
- - apiPath: /some/api
- service:
- name: Server
- port:
- name: http
- value: 8080
\ No newline at end of file
+#mesher:
+# ingress:
+# type: servicecomb
+# rule:
+# http: |
+# - host: example.com
+# limit: 30
+# apiPath: /some/api
+# service:
+# name: example
+# redirectPath: /another/api
+# port:
+# name: http-legacy
+# value: 8080
+# - apiPath: /sayerror/api
+# service:
+# name: Server
+# redirectPath: /sayerror
+# port:
+# name: http
+# value: 8080
+# - apiPath: /some/api
+# service:
+# name: Server
+# port:
+# name: http
+# value: 8080
\ No newline at end of file
diff --git a/examples/edge/conf/microservice.yaml b/examples/edge/conf/microservice.yaml
index 8103479..0aba6be 100644
--- a/examples/edge/conf/microservice.yaml
+++ b/examples/edge/conf/microservice.yaml
@@ -1,3 +1,3 @@
service_description:
name: mesher-edge
- version: 0.0.1
+ version: 1.7.0
diff --git a/go.mod b/go.mod
index 0fa2317..0fb8ed6 100644
--- a/go.mod
+++ b/go.mod
@@ -1,31 +1,24 @@
module github.com/apache/servicecomb-mesher
require (
- github.com/Shopify/toxiproxy v2.1.3+incompatible // indirect
- github.com/emicklei/go-restful-swagger12 v0.0.0-20170926063155-7524189396c6 // indirect
github.com/envoyproxy/go-control-plane v0.6.0
github.com/ghodss/yaml v1.0.0
github.com/go-chassis/foundation v0.0.0-20190621030543-c3b63f787f4c
- github.com/go-chassis/go-archaius v0.20.0
- github.com/go-chassis/go-chassis v1.7.2-0.20190917011915-d49fa9cdd27d
- github.com/go-chassis/go-chassis-config v0.10.0
+ github.com/go-chassis/go-archaius v0.23.0
+ github.com/go-chassis/go-chassis v1.7.2-0.20191014010950-405e29b7566e
+ github.com/go-chassis/go-chassis-config v0.12.1-0.20190926020053-87487eaa3a72
github.com/go-chassis/gohessian v0.0.0-20180702061429-e5130c25af55
- github.com/go-logfmt/logfmt v0.4.0 // indirect
- github.com/go-mesh/openlogging v1.0.1-0.20181205082104-3d418c478b2d
- github.com/gogo/googleapis v1.1.0 // indirect
- github.com/gogo/protobuf v1.2.0
- github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
- github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
- github.com/imdario/mergo v0.3.6 // indirect
- github.com/lyft/protoc-gen-validate v0.0.11 // indirect
+ github.com/go-mesh/openlogging v1.0.1
+ github.com/gogo/googleapis v1.3.0 // indirect
+ github.com/gogo/protobuf v1.3.0
+ github.com/google/gofuzz v1.0.0 // indirect
+ github.com/imdario/mergo v0.3.7 // indirect
+ github.com/lyft/protoc-gen-validate v0.1.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v0.9.1
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f
- github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1 // indirect
- github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
- github.com/spf13/pflag v1.0.3 // indirect
+ github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.3.0
- github.com/uber-go/atomic v1.3.2 // indirect
github.com/urfave/cli v1.20.1-0.20181029213200-b67dcf995b6a
golang.org/x/net v0.0.0-20190311183353-d8887717615a
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
@@ -36,20 +29,4 @@
k8s.io/client-go v9.0.0+incompatible
)
-replace (
- cloud.google.com/go v0.28.0 => github.com/GoogleCloudPlatform/google-cloud-go v0.28.0
- github.com/kubernetes/client-go => ../k8s.io/client-go
- github.com/openzipkin-contrib/zipkin-go-opentracing v0.3.5 => github.com/go-chassis/zipkin-go-opentracing v0.3.5-0.20190321072447-42cf74fc2a92
- golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 => github.com/golang/crypto v0.0.0-20181030102418-4d3f4d9ffa16
- golang.org/x/net v0.0.0-20180906233101-161cd47e91fd => github.com/golang/net v0.0.0-20180906233101-161cd47e91fd
- golang.org/x/oauth2 v0.0.0-20180207181906-543e37812f10 => github.com/golang/oauth2 v0.0.0-20180207181906-543e37812f10
- golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f => github.com/golang/sync v0.0.0-20180314180146-1d60e4601c6f
- golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e => github.com/golang/sys v0.0.0-20180909124046-d0be0721c37e
- golang.org/x/sys v0.0.0-20181031143558-9b800f95dbbc => github.com/golang/sys v0.0.0-20181031143558-9b800f95dbbc
-
- golang.org/x/text v0.3.0 => github.com/golang/text v0.3.0
- golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 => github.com/golang/time v0.0.0-20180412165947-fbb02b2291d2
- google.golang.org/appengine v1.2.0 => github.com/golang/appengine v1.2.0
- google.golang.org/genproto v0.0.0-20181101192439-c830210a61df => github.com/google/go-genproto v0.0.0-20181101192439-c830210a61df
- google.golang.org/grpc v1.14.0 => github.com/grpc/grpc-go v1.14.0
-)
+replace github.com/openzipkin-contrib/zipkin-go-opentracing v0.3.5 => github.com/go-chassis/zipkin-go-opentracing v0.3.5-0.20190321072447-42cf74fc2a92
diff --git a/proxy/config/config.go b/proxy/config/config.go
index ac3143d..07ceef1 100644
--- a/proxy/config/config.go
+++ b/proxy/config/config.go
@@ -146,7 +146,7 @@
return ""
}
contents = string(b)
- archaius.AddKeyValue(key, contents)
+ archaius.Set(key, contents)
return contents
}
diff --git a/proxy/config/config_test.go b/proxy/config/config_test.go
index b17b731..9cbd597 100644
--- a/proxy/config/config_test.go
+++ b/proxy/config/config_test.go
@@ -24,6 +24,7 @@
// "github.com/go-chassis/go-chassis/pkg/util/fileutil"
"github.com/apache/servicecomb-mesher/proxy/cmd"
"github.com/apache/servicecomb-mesher/proxy/config"
+ "github.com/go-chassis/go-archaius"
"github.com/go-chassis/go-chassis/core/lager"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
@@ -37,7 +38,10 @@
}
func TestGetConfigFilePath(t *testing.T) {
var key = "mesher.yaml"
+ archaius.Init(archaius.WithENVSource())
cmd.Init()
+ err := config.Init()
+ assert.Error(t, err)
f, _ := config.GetConfigFilePath(key)
assert.Contains(t, f, key)
}
diff --git a/proxy/config/struct.go b/proxy/config/struct.go
index d4d5914..87b35f1 100644
--- a/proxy/config/struct.go
+++ b/proxy/config/struct.go
@@ -63,7 +63,6 @@
//Admin has attributes for enabling, serverURI and metrics for admin data
type Admin struct {
- Enable bool `yaml:"enable"`
- ServerURI string `yaml:"serverUri"`
- GoRuntimeMetrics bool `yaml:"goRuntimeMetrics"`
+ Enable bool `yaml:"enable"`
+ ServerURI string `yaml:"serverUri"`
}
diff --git a/proxy/config/struct_ingress_test.go b/proxy/config/struct_ingress_test.go
index 22d268e..8384e28 100644
--- a/proxy/config/struct_ingress_test.go
+++ b/proxy/config/struct_ingress_test.go
@@ -59,4 +59,6 @@
rules, err := config.NewRules(c.Mesher.Ingress.Rule["http"])
assert.NoError(t, err)
assert.Equal(t, 2, rules.Len())
+ v := rules.Value()
+ assert.Equal(t, "example", v[0].Service.Name)
}
diff --git a/proxy/ingress/servicecomb/listener.go b/proxy/ingress/servicecomb/listener.go
index a1cc7b8..d41051a 100644
--- a/proxy/ingress/servicecomb/listener.go
+++ b/proxy/ingress/servicecomb/listener.go
@@ -19,7 +19,7 @@
import (
"github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/go-chassis/go-archaius/core"
+ "github.com/go-chassis/go-archaius/event"
"github.com/go-chassis/go-chassis/core/common"
"github.com/go-mesh/openlogging"
)
@@ -27,7 +27,7 @@
type ingressRuleEventListener struct{}
//Event update ingress rule
-func (r *ingressRuleEventListener) Event(e *core.Event) {
+func (r *ingressRuleEventListener) Event(e *event.Event) {
if e == nil {
openlogging.Warn("Event pointer is nil")
return
diff --git a/proxy/pkg/egress/archaius/egress_manager.go b/proxy/pkg/egress/archaius/egress_manager.go
index 88e2f6f..eac986c 100644
--- a/proxy/pkg/egress/archaius/egress_manager.go
+++ b/proxy/pkg/egress/archaius/egress_manager.go
@@ -18,6 +18,8 @@
package archaius
import (
+ "github.com/go-chassis/go-archaius/event"
+ "github.com/go-chassis/go-archaius/source/util"
"gopkg.in/yaml.v2"
"path/filepath"
"strings"
@@ -25,8 +27,6 @@
"github.com/apache/servicecomb-mesher/proxy/config"
"github.com/apache/servicecomb-mesher/proxy/pkg/egress"
"github.com/go-chassis/go-archaius"
- "github.com/go-chassis/go-archaius/core"
- "github.com/go-chassis/go-archaius/sources/utils"
"github.com/go-chassis/go-chassis/core/lager"
"github.com/go-chassis/go-chassis/pkg/util/fileutil"
)
@@ -37,7 +37,7 @@
type egressRuleEventListener struct{}
// update egress rule of a service
-func (r *egressRuleEventListener) Event(e *core.Event) {
+func (r *egressRuleEventListener) Event(e *event.Event) {
if e == nil {
lager.Logger.Warn("Event pointer is nil", nil)
return
@@ -76,7 +76,7 @@
// initialize the config mgr and add several sources
func initEgressManager() error {
egressListener := &egressRuleEventListener{}
- archaius.AddFile(filepath.Join(fileutil.GetConfDir(), EgressYaml), archaius.WithFileHandler(utils.Convert2configMap))
+ archaius.AddFile(filepath.Join(fileutil.GetConfDir(), EgressYaml), archaius.WithFileHandler(util.UseFileNameAsKeyContentAsValue))
archaius.RegisterListener(egressListener, ".*")
return nil
diff --git a/proxy/pkg/egress/pilot/egress.go b/proxy/pkg/egress/pilot/egress.go
index ec4b1ac..678772d 100644
--- a/proxy/pkg/egress/pilot/egress.go
+++ b/proxy/pkg/egress/pilot/egress.go
@@ -52,13 +52,13 @@
// refresh all the egress config
func refresh() error {
- configs := pilotfetcher.GetConfigurations()
+ configs := pilotfetcher.Configs()
d := make(map[string][]*config.EgressRule)
for k, v := range configs {
rules, ok := v.([]*config.EgressRule)
if !ok {
- err := fmt.Errorf("Egress rule type assertion fail, key: %s", k)
+ err := fmt.Errorf("egress rule type assertion fail, key: %s", k)
return err
}
d[k] = rules
diff --git a/proxy/pkg/egress/pilot/pilotsource.go b/proxy/pkg/egress/pilot/pilotsource.go
index b290ce3..a66cc9e 100644
--- a/proxy/pkg/egress/pilot/pilotsource.go
+++ b/proxy/pkg/egress/pilot/pilotsource.go
@@ -20,6 +20,8 @@
import (
"errors"
"fmt"
+ "github.com/go-chassis/go-archaius/event"
+ "github.com/go-chassis/go-archaius/source"
"os"
"reflect"
"strconv"
@@ -31,9 +33,6 @@
"github.com/apache/servicecomb-mesher/proxy/control/istio"
"github.com/apache/servicecomb-mesher/proxy/pkg/egress"
istioinfra "github.com/apache/servicecomb-mesher/proxy/pkg/infras/istio"
- "github.com/go-chassis/go-archaius/core"
- cm "github.com/go-chassis/go-archaius/core/config-manager"
- "github.com/go-chassis/go-archaius/core/event-system"
"github.com/go-chassis/go-chassis/core/lager"
)
@@ -50,7 +49,7 @@
// TODO: use stream instead
var DefaultPilotRefresh = 10 * time.Second
-var pilotfetcher core.ConfigMgr
+var pilotfetcher *source.Manager
var pilotChan = make(chan string, 10)
func setChanForPilot(k string) bool {
@@ -64,12 +63,9 @@
// InitPilotFetcher init the config mgr and add several sources
func InitPilotFetcher(o egress.Options) error {
- d := eventsystem.NewDispatcher()
-
// register and init pilot fetcher
- d.RegisterListener(&pilotEventListener{}, ".*")
- pilotfetcher = cm.NewConfigurationManager(d)
-
+ pilotfetcher = source.NewManager()
+ pilotfetcher.RegisterListener(&pilotEventListener{}, ".*")
return addEgressPilotSource(o)
}
@@ -133,10 +129,9 @@
func (r *pilotSource) GetPriority() int { return r.priority }
func (r *pilotSource) Cleanup() error { return nil }
-func (r *pilotSource) AddDimensionInfo(d string) (map[string]string, error) { return nil, nil }
-func (r *pilotSource) GetConfigurationsByDI(d string) (map[string]interface{}, error) { return nil, nil }
-func (r *pilotSource) GetConfigurationByKeyAndDimensionInfo(key, d string) (interface{}, error) {
- return nil, nil
+//AddDimensionInfo no use
+func (r *pilotSource) AddDimensionInfo(labels map[string]string) error {
+ return nil
}
func (r *pilotSource) GetConfigurations() (map[string]interface{}, error) {
@@ -162,6 +157,16 @@
return nil, fmt.Errorf("not found %s", k)
}
+//Set no use
+func (r *pilotSource) Set(key string, value interface{}) error {
+ return nil
+}
+
+//Delete no use
+func (r *pilotSource) Delete(key string) error {
+ return nil
+}
+
// get egress config from pilot
func (r *pilotSource) getEgressConfigFromPilot() ([]*config.EgressRule, error) {
clusters, _ := r.fetcher.CDS()
@@ -201,7 +206,7 @@
func (r *pilotSource) SetPriority(priority int) {
r.priority = priority
}
-func (r *pilotSource) DynamicConfigHandler(callback core.DynamicConfigCallback) error {
+func (r *pilotSource) Watch(callback source.EventHandler) error {
// Periodically refresh configurations
ticker := time.NewTicker(r.refreshInverval)
for {
@@ -250,8 +255,8 @@
return data, nil
}
-func (r *pilotSource) populateEvents(updates map[string]interface{}) ([]*core.Event, error) {
- events := make([]*core.Event, 0)
+func (r *pilotSource) populateEvents(updates map[string]interface{}) ([]*event.Event, error) {
+ events := make([]*event.Event, 0)
new := make(map[string]interface{})
// generate create and update event
@@ -263,16 +268,16 @@
new[key] = value
currentValue, ok := current[key]
if !ok { // if new configuration introduced
- events = append(events, constructEvent(core.Create, key, value))
+ events = append(events, constructEvent(event.Create, key, value))
} else if !reflect.DeepEqual(currentValue, value) {
- events = append(events, constructEvent(core.Update, key, value))
+ events = append(events, constructEvent(event.Update, key, value))
}
}
// generate delete event
for key, value := range current {
_, ok := new[key]
if !ok { // when old config not present in new config
- events = append(events, constructEvent(core.Delete, key, value))
+ events = append(events, constructEvent(event.Delete, key, value))
}
}
@@ -283,8 +288,8 @@
return events, nil
}
-func constructEvent(eventType string, key string, value interface{}) *core.Event {
- return &core.Event{
+func constructEvent(eventType string, key string, value interface{}) *event.Event {
+ return &event.Event{
EventType: eventType,
EventSource: egressPilotSourceName,
Value: value,
@@ -296,13 +301,13 @@
type pilotEventListener struct{}
// update egress rule of a service
-func (r *pilotEventListener) Event(e *core.Event) {
+func (r *pilotEventListener) Event(e *event.Event) {
if e == nil {
lager.Logger.Warn("pilot event pointer is nil", nil)
return
}
- v := pilotfetcher.GetConfigurationsByKey(e.Key)
+ v := pilotfetcher.GetConfig(e.Key)
if v == nil {
istio.SaveToEgressCache(nil)
return
diff --git a/proxy/pkg/metrics/metrics.go b/proxy/pkg/metrics/metrics.go
index d35e12d..ffd4859 100644
--- a/proxy/pkg/metrics/metrics.go
+++ b/proxy/pkg/metrics/metrics.go
@@ -23,7 +23,6 @@
package metrics
import (
- mesherConf "github.com/apache/servicecomb-mesher/proxy/config"
"github.com/go-chassis/go-chassis/pkg/runtime"
"sync"
"time"
@@ -50,39 +49,26 @@
mutex = sync.Mutex{}
)
-//Recorder export the metrics into various of system
-type Recorder interface {
- RecordStatus(labelValues map[string]string, status int, opts *RecordOptions)
- RecordLatency(labelValues map[string]string, latency float64, opts *RecordOptions)
- RecordStartTime(labelValues map[string]string, start time.Time, opts *RecordOptions)
-}
-
//Options define recorder options
type Options struct {
- LabelNames []string //default label names, if RecordOptions LabelNames is nil
- EnableGoRuntimeMetrics bool
+ LabelNames []string //default label names, if RecordOptions LabelNames is nil
}
-//RecordOptions is options for record method
-type RecordOptions struct {
- LabelNames []string // able top custom label names
-}
-
-var defaultRecorder Recorder = &promRecorder{}
+var defaultRecorder *PromRecorder
//RecordStatus record an operation status
-func RecordStatus(labelValues map[string]string, statusCode int, opts *RecordOptions) {
- defaultRecorder.RecordStatus(labelValues, statusCode, opts)
+func RecordStatus(labelValues map[string]string, statusCode int) {
+ defaultRecorder.RecordStatus(labelValues, statusCode)
}
//RecordLatency record an operation latency
-func RecordLatency(labelValues map[string]string, latency float64, opts *RecordOptions) {
- defaultRecorder.RecordLatency(labelValues, latency, opts)
+func RecordLatency(labelValues map[string]string, latency float64) {
+ defaultRecorder.RecordLatency(labelValues, latency)
}
-//RecordStartTime record app start time
-func RecordStartTime(labelValues map[string]string, start time.Time, opts *RecordOptions) {
- defaultRecorder.RecordStartTime(labelValues, start, opts)
+//RecordStartTime record mesher start time
+func RecordStartTime(labelValues map[string]string, start time.Time) {
+ defaultRecorder.RecordStartTime(labelValues, start)
}
//Init initiate the recorder
@@ -90,12 +76,11 @@
var err error
LabelValues := map[string]string{LServiceName: runtime.ServiceName, LApp: runtime.App, LVersion: runtime.Version}
defaultRecorder, err = NewPromRecorder(&Options{
- LabelNames: LabelNames,
- EnableGoRuntimeMetrics: mesherConf.GetConfig().Admin.GoRuntimeMetrics,
+ LabelNames: LabelNames,
})
if err != nil {
return err
}
- RecordStartTime(LabelValues, time.Now(), nil)
+ RecordStartTime(LabelValues, time.Now())
return nil
}
diff --git a/proxy/pkg/metrics/metrics_test.go b/proxy/pkg/metrics/metrics_test.go
index 8e38b62..f61acbe 100644
--- a/proxy/pkg/metrics/metrics_test.go
+++ b/proxy/pkg/metrics/metrics_test.go
@@ -18,24 +18,17 @@
package metrics_test
import (
+ "github.com/prometheus/client_golang/prometheus"
+ "github.com/stretchr/testify/assert"
"net/http"
"strings"
"testing"
- "github.com/prometheus/client_golang/prometheus"
- "github.com/stretchr/testify/assert"
-
- mc "github.com/apache/servicecomb-mesher/proxy/config"
"github.com/apache/servicecomb-mesher/proxy/pkg/metrics"
"github.com/go-chassis/go-chassis/pkg/runtime"
)
func TestInit(t *testing.T) {
- mc.SetConfig(&mc.MesherConfig{
- Admin: mc.Admin{
- GoRuntimeMetrics: false,
- },
- })
err := metrics.Init()
runtime.ServiceName = "A"
runtime.Version = "v1.1"
@@ -51,9 +44,9 @@
metrics.LVersion: "",
metrics.LApp: "",
}
- metrics.RecordStatus(lvs, http.StatusOK, nil)
- metrics.RecordStatus(lvs, http.StatusNotFound, nil)
- metrics.RecordStatus(lvs, http.StatusInternalServerError, nil)
+ metrics.RecordStatus(lvs, http.StatusOK)
+ metrics.RecordStatus(lvs, http.StatusNotFound)
+ metrics.RecordStatus(lvs, http.StatusInternalServerError)
metricFamilies, err := prometheus.DefaultGatherer.Gather()
assert.Nil(err, "error should be nil while collecting metrics from prometheus")
for _, metricFamily := range metricFamilies {
@@ -69,4 +62,13 @@
assert.Equal(errorcount4xx, float64(1))
assert.Equal(errorcount5xx, float64(1))
+ metrics.RecordLatency(lvs, 1000)
+ metricFamilies, err = prometheus.DefaultGatherer.Gather()
+ var c float64
+ for _, metricFamily := range metricFamilies {
+ if name := metricFamily.GetName(); strings.Contains(name, metrics.LRequestLatencySeconds) {
+ c = *metricFamily.Metric[0].Summary.SampleSum
+ }
+ }
+ assert.Equal(1000, int(c))
}
diff --git a/proxy/pkg/metrics/prom_recorder.go b/proxy/pkg/metrics/prom_recorder.go
index 67305f1..dfa5164 100644
--- a/proxy/pkg/metrics/prom_recorder.go
+++ b/proxy/pkg/metrics/prom_recorder.go
@@ -19,7 +19,6 @@
import (
"errors"
- "github.com/prometheus/client_golang/prometheus"
"net/http"
"sync"
"time"
@@ -27,59 +26,41 @@
var onceEnable sync.Once
-type promRecorder struct {
+//PromRecorder record metrics
+type PromRecorder struct {
LabelNames []string
}
//NewPromRecorder return a prom recorder
-func NewPromRecorder(opts *Options) (Recorder, error) {
- promConfig := getPrometheusSinker(getSystemPrometheusRegistry())
+func NewPromRecorder(opts *Options) (*PromRecorder, error) {
if opts != nil {
- if opts.EnableGoRuntimeMetrics {
- onceEnable.Do(func() {
- promConfig.PromRegistry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
- promConfig.PromRegistry.MustRegister(prometheus.NewGoCollector())
- })
- }
- return &promRecorder{LabelNames: opts.LabelNames}, nil
+ return &PromRecorder{LabelNames: opts.LabelNames}, nil
}
return nil, errors.New("options can not be nil")
}
-//GetLN return label names based on options
-func (e *promRecorder) GetLN(opts *RecordOptions) (ln []string) {
- ln = e.LabelNames
- if opts != nil && len(opts.LabelNames) != 0 {
- ln = opts.LabelNames
- }
- return
-}
-
//RecordStatus record different metrics based on status
-func (e *promRecorder) RecordStatus(LabelValues map[string]string, statusCode int, opts *RecordOptions) {
- ln := e.GetLN(opts)
+func (e *PromRecorder) RecordStatus(LabelValues map[string]string, statusCode int) {
if statusCode >= http.StatusBadRequest && statusCode <= http.StatusUnavailableForLegalReasons {
- DefaultPrometheusExporter.Count(LError4XX, ln, LabelValues)
- DefaultPrometheusExporter.Count(LTotalFailures, ln, LabelValues)
+ DefaultPrometheusExporter.Count(LError4XX, e.LabelNames, LabelValues)
+ DefaultPrometheusExporter.Count(LTotalFailures, e.LabelNames, LabelValues)
} else if statusCode >= http.StatusInternalServerError && statusCode <= http.StatusNetworkAuthenticationRequired {
- DefaultPrometheusExporter.Count(LError5XX, ln, LabelValues)
- DefaultPrometheusExporter.Count(LTotalFailures, ln, LabelValues)
+ DefaultPrometheusExporter.Count(LError5XX, e.LabelNames, LabelValues)
+ DefaultPrometheusExporter.Count(LTotalFailures, e.LabelNames, LabelValues)
} else if statusCode >= http.StatusOK && statusCode <= http.StatusIMUsed {
- DefaultPrometheusExporter.Count(LTotalSuccess, ln, LabelValues)
+ DefaultPrometheusExporter.Count(LTotalSuccess, e.LabelNames, LabelValues)
}
- DefaultPrometheusExporter.Count(LTotalRequest, ln, LabelValues)
+ DefaultPrometheusExporter.Count(LTotalRequest, e.LabelNames, LabelValues)
}
//RecordLatency record operation latency
-func (e *promRecorder) RecordLatency(LabelValues map[string]string, latency float64, opts *RecordOptions) {
- ln := e.GetLN(opts)
- DefaultPrometheusExporter.Summary(LRequestLatencySeconds, latency, ln, LabelValues)
+func (e *PromRecorder) RecordLatency(LabelValues map[string]string, latency float64) {
+ DefaultPrometheusExporter.Summary(LRequestLatencySeconds, latency, e.LabelNames, LabelValues)
}
//RecordStartTime save start time
-func (e *promRecorder) RecordStartTime(LabelValues map[string]string, start time.Time, opts *RecordOptions) {
- ln := e.GetLN(opts)
- DefaultPrometheusExporter.Gauge(LStartTime, float64(start.Unix()), ln, LabelValues)
+func (e *PromRecorder) RecordStartTime(LabelValues map[string]string, start time.Time) {
+ DefaultPrometheusExporter.Gauge(LStartTime, float64(start.Unix()), e.LabelNames, LabelValues)
}
diff --git a/proxy/pkg/metrics/prometheus_exporter.go b/proxy/pkg/metrics/prometheus_exporter.go
index ee56857..d1dfc3e 100644
--- a/proxy/pkg/metrics/prometheus_exporter.go
+++ b/proxy/pkg/metrics/prometheus_exporter.go
@@ -44,30 +44,11 @@
var (
//DefaultPrometheusExporter stores value of default prometheus exporter type
DefaultPrometheusExporter = GetPrometheusExporter()
- prometheusRegistry = prometheus.NewRegistry()
onceInit sync.Once
//DefaultPrometheusSinker stores value of default prometheus exporter type
DefaultPrometheusSinker *PrometheusMesherSinker
)
-//GetSystemPrometheusRegistry return prometheus registry which mesher use
-func getSystemPrometheusRegistry() *prometheus.Registry {
- return prometheusRegistry
-}
-
-func newPrometheusProvider(promRegistry prometheus.Registerer) *PrometheusMesherSinker {
- return &PrometheusMesherSinker{
- PromRegistry: promRegistry,
- }
-}
-
-func getPrometheusSinker(pr *prometheus.Registry) *PrometheusMesherSinker {
- onceInit.Do(func() {
- DefaultPrometheusSinker = newPrometheusProvider(pr)
- })
- return DefaultPrometheusSinker
-}
-
//GetPrometheusExporter returns default prometheus exporter
func GetPrometheusExporter() *PrometheusExporter {
//use go chassis registry
diff --git a/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go b/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go
index 571b19e..3daec27 100755
--- a/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go
+++ b/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go
@@ -36,7 +36,6 @@
"github.com/go-chassis/go-chassis/client/rest"
"github.com/go-chassis/go-chassis/core/common"
chassisCommon "github.com/go-chassis/go-chassis/core/common"
- chassisconfig "github.com/go-chassis/go-chassis/core/config"
"github.com/go-chassis/go-chassis/core/handler"
"github.com/go-chassis/go-chassis/core/invocation"
"github.com/go-chassis/go-chassis/core/lager"
@@ -223,7 +222,7 @@
//发送请求
//value := ctx.Req.GetAttachment(ProxyTag, "")
if !IsProvider { //come from proxyedDubboSvc
- ctx.Req.SetAttachment(common.HeaderSourceName, chassisconfig.SelfServiceName)
+ ctx.Req.SetAttachment(common.HeaderSourceName, runtime.ServiceName)
ctx.Req.SetAttachment(ProxyTag, "true")
if mesherRuntime.Role == mesherCommon.RoleSidecar {
diff --git a/proxy/protocol/dubbo/proxy/rest2dubbo.go b/proxy/protocol/dubbo/proxy/rest2dubbo.go
index 69a8621..c327f33 100755
--- a/proxy/protocol/dubbo/proxy/rest2dubbo.go
+++ b/proxy/protocol/dubbo/proxy/rest2dubbo.go
@@ -19,6 +19,7 @@
import (
"fmt"
+ "github.com/go-chassis/go-chassis/pkg/runtime"
"io/ioutil"
"net/http"
"net/url"
@@ -160,8 +161,8 @@
func preHandleToDubbo(req *http.Request) (*invocation.Invocation, string) {
inv := new(invocation.Invocation)
- inv.MicroServiceName = chassisconfig.SelfServiceName
- inv.RouteTags = utiltags.NewDefaultTag(chassisconfig.SelfVersion, chassisconfig.GlobalDefinition.AppID)
+ inv.MicroServiceName = runtime.ServiceName
+ inv.RouteTags = utiltags.NewDefaultTag(runtime.Version, chassisconfig.GlobalDefinition.AppID)
inv.Protocol = "dubbo"
inv.URLPathFormat = req.URL.Path
diff --git a/proxy/protocol/grpc/reverse_proxy.go b/proxy/protocol/grpc/reverse_proxy.go
index 3cc62a2..fa61aac 100755
--- a/proxy/protocol/grpc/reverse_proxy.go
+++ b/proxy/protocol/grpc/reverse_proxy.go
@@ -32,7 +32,6 @@
"github.com/apache/servicecomb-mesher/proxy/util"
"github.com/go-chassis/go-chassis/client/rest"
chassisCommon "github.com/go-chassis/go-chassis/core/common"
- chassisconfig "github.com/go-chassis/go-chassis/core/config"
"github.com/go-chassis/go-chassis/core/handler"
"github.com/go-chassis/go-chassis/core/invocation"
"github.com/go-chassis/go-chassis/core/lager"
@@ -81,8 +80,8 @@
func providerPreHandler(req *http.Request) *invocation.Invocation {
inv := preHandler(req)
- inv.MicroServiceName = chassisconfig.SelfServiceName
- inv.RouteTags = utiltags.NewDefaultTag(chassisconfig.SelfVersion, chassisconfig.GlobalDefinition.AppID)
+ inv.MicroServiceName = runtime.ServiceName
+ inv.RouteTags = utiltags.NewDefaultTag(runtime.Version, runtime.App)
inv.SourceMicroService = req.Header.Get(chassisCommon.HeaderSourceName)
inv.Ctx = context.TODO()
return inv
@@ -127,7 +126,7 @@
defer func(begin time.Time) {
timeTaken := time.Since(begin).Seconds()
serviceLabelValues := map[string]string{metrics.LServiceName: inv.MicroServiceName, metrics.LApp: inv.RouteTags.AppID(), metrics.LVersion: inv.RouteTags.Version()}
- metrics.RecordLatency(serviceLabelValues, timeTaken, nil)
+ metrics.RecordLatency(serviceLabelValues, timeTaken)
}(time.Now())
var invRsp *invocation.Response
c.Next(inv, func(ir *invocation.Response) error {
@@ -259,7 +258,7 @@
//RecordStatus record an operation status
func RecordStatus(inv *invocation.Invocation, statusCode int) {
LabelValues := map[string]string{metrics.LServiceName: inv.MicroServiceName, metrics.LApp: inv.RouteTags.AppID(), metrics.LVersion: inv.RouteTags.Version()}
- metrics.RecordStatus(LabelValues, statusCode, nil)
+ metrics.RecordStatus(LabelValues, statusCode)
}
func copyHeader(dst, src http.Header) {
for k, vs := range src {
diff --git a/proxy/protocol/grpc/server.go b/proxy/protocol/grpc/server.go
index 435a477..1e8bc8d 100644
--- a/proxy/protocol/grpc/server.go
+++ b/proxy/protocol/grpc/server.go
@@ -23,13 +23,13 @@
"fmt"
"github.com/apache/servicecomb-mesher/proxy/common"
"github.com/apache/servicecomb-mesher/proxy/resolver"
+ chassisRuntime "github.com/go-chassis/go-chassis/pkg/runtime"
"net"
"net/http"
"strings"
"github.com/apache/servicecomb-mesher/proxy/pkg/runtime"
chassisCom "github.com/go-chassis/go-chassis/core/common"
- chassisConfig "github.com/go-chassis/go-chassis/core/config"
"github.com/go-chassis/go-chassis/core/lager"
"github.com/go-chassis/go-chassis/core/server"
chassisTLS "github.com/go-chassis/go-chassis/core/tls"
@@ -113,13 +113,13 @@
return nil
default:
serverTLSConfig, serverSSLConfig, serverErr := chassisTLS.GetTLSConfigByService(
- chassisConfig.SelfServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
+ chassisRuntime.ServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
if serverErr != nil {
if !chassisTLS.IsSSLConfigNotExist(serverErr) {
return serverErr
}
} else {
- sslTag := genTag(chassisConfig.SelfServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
+ sslTag := genTag(chassisRuntime.ServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
lager.Logger.Warnf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
sslTag, serverSSLConfig.VerifyPeer, serverSSLConfig.CipherPlugin)
}
diff --git a/proxy/protocol/http/gateway_test.go b/proxy/protocol/http/gateway_test.go
new file mode 100644
index 0000000..c27930b
--- /dev/null
+++ b/proxy/protocol/http/gateway_test.go
@@ -0,0 +1,70 @@
+package http
+
+import (
+ "github.com/apache/servicecomb-mesher/proxy/ingress"
+ _ "github.com/apache/servicecomb-mesher/proxy/ingress/servicecomb"
+ "github.com/apache/servicecomb-mesher/proxy/pkg/metrics"
+ "github.com/go-chassis/go-archaius"
+ "github.com/go-chassis/go-chassis/control"
+ _ "github.com/go-chassis/go-chassis/control/archaius"
+ "github.com/go-chassis/go-chassis/core/common"
+ "github.com/go-chassis/go-chassis/core/config"
+ "github.com/go-chassis/go-chassis/core/config/model"
+ "github.com/go-chassis/go-chassis/core/handler"
+ "github.com/stretchr/testify/assert"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+)
+
+func TestHandleIngressTraffic(t *testing.T) {
+ b := []byte(`
+ - host: example.com
+ limit: 30
+ apiPath: /some/api
+ service:
+ name: example
+ tags:
+ version: 1.0.0
+ redirectPath: /another/api
+ port:
+ name: http-legacy
+ value: 8080
+ - host: foo.com
+ apiPath: /some/api
+ service:
+ name: foo
+ tags:
+ version: 1.0.0
+ redirectPath: /another/api
+ port:
+ name: http
+ value: 8080
+`)
+ err := metrics.Init()
+ assert.NoError(t, err)
+ err = handler.CreateChains(common.Provider, map[string]string{
+ "incoming": strings.Join([]string{}, ","),
+ },
+ )
+ err = handler.CreateChains(common.Consumer, map[string]string{
+ "outgoing": strings.Join([]string{}, ","),
+ },
+ )
+ archaius.Init(archaius.WithMemorySource())
+ err = archaius.Set("mesher.ingress.rule.http", string(b))
+ assert.NoError(t, err)
+ config.GlobalDefinition = new(model.GlobalCfg)
+ config.HystrixConfig = &model.HystrixConfigWrapper{}
+ archaius.UnmarshalConfig(config.GlobalDefinition)
+ assert.NoError(t, err)
+ err = control.Init(control.Options{})
+ assert.NoError(t, err)
+ err = ingress.Init()
+ assert.NoError(t, err)
+
+ req, _ := http.NewRequest(http.MethodGet, "http://foo.com/some/api", nil)
+ w := httptest.NewRecorder()
+ HandleIngressTraffic(w, req)
+}
diff --git a/proxy/protocol/http/http_server.go b/proxy/protocol/http/http_server.go
index c7b73e6..a61452e 100644
--- a/proxy/protocol/http/http_server.go
+++ b/proxy/protocol/http/http_server.go
@@ -23,17 +23,16 @@
"errors"
"fmt"
"github.com/apache/servicecomb-mesher/proxy/ingress"
+ "github.com/apache/servicecomb-mesher/proxy/pkg/runtime"
"net"
"net/http"
"strings"
"github.com/apache/servicecomb-mesher/proxy/common"
"github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/apache/servicecomb-mesher/proxy/pkg/runtime"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/proxy"
"github.com/apache/servicecomb-mesher/proxy/resolver"
chassisCom "github.com/go-chassis/go-chassis/core/common"
- chassisConfig "github.com/go-chassis/go-chassis/core/config"
"github.com/go-chassis/go-chassis/core/lager"
"github.com/go-chassis/go-chassis/core/server"
chassisTLS "github.com/go-chassis/go-chassis/core/tls"
@@ -117,13 +116,13 @@
return nil
default:
serverTLSConfig, serverSSLConfig, serverErr := chassisTLS.GetTLSConfigByService(
- chassisConfig.SelfServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
+ chassisRuntime.ServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
if serverErr != nil {
if !chassisTLS.IsSSLConfigNotExist(serverErr) {
return serverErr
}
} else {
- sslTag := genTag(chassisConfig.SelfServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
+ sslTag := genTag(chassisRuntime.ServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
lager.Logger.Warnf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
sslTag, serverSSLConfig.VerifyPeer, serverSSLConfig.CipherPlugin)
}
diff --git a/proxy/protocol/http/sidecar.go b/proxy/protocol/http/sidecar.go
index 144e852..6ec2011 100755
--- a/proxy/protocol/http/sidecar.go
+++ b/proxy/protocol/http/sidecar.go
@@ -84,8 +84,8 @@
func providerPreHandler(req *http.Request) *invocation.Invocation {
inv := preHandler(req)
- inv.MicroServiceName = chassisconfig.SelfServiceName
- inv.RouteTags = utiltags.NewDefaultTag(chassisconfig.SelfVersion, chassisconfig.GlobalDefinition.AppID)
+ inv.MicroServiceName = runtime.ServiceName
+ inv.RouteTags = utiltags.NewDefaultTag(runtime.Version, chassisconfig.GlobalDefinition.AppID)
inv.SourceMicroService = req.Header.Get(chassisCommon.HeaderSourceName)
inv.Ctx = context.TODO()
return inv
@@ -119,19 +119,18 @@
var c *handler.Chain
ok, egressRule := egress.Match(inv.MicroServiceName)
if ok {
- var intport int32 = 80
+ var targetPort int32 = 80
for _, port := range egressRule.Ports {
if strings.EqualFold(port.Protocol, common.HTTPProtocol) {
- intport = port.Port
+ targetPort = port.Port
break
}
}
- inv.Endpoint = inv.MicroServiceName + ":" + strconv.Itoa(int(intport))
+ inv.Endpoint = inv.MicroServiceName + ":" + strconv.Itoa(int(targetPort))
c, err = handler.GetChain(common.ConsumerEgress, common.ChainConsumerEgress)
-
if err != nil {
handleErrorResponse(inv, w, http.StatusBadGateway, err)
- lager.Logger.Error("Get chain failed" + err.Error())
+ openlogging.Error("Get chain failed" + err.Error())
return
}
@@ -139,14 +138,14 @@
c, err = handler.GetChain(chassisCommon.Consumer, common.ChainConsumerOutgoing)
if err != nil {
handleErrorResponse(inv, w, http.StatusBadGateway, err)
- lager.Logger.Error("Get chain failed: " + err.Error())
+ openlogging.Error("Get chain failed: " + err.Error())
return
}
}
defer func(begin time.Time) {
timeTaken := time.Since(begin).Seconds()
serviceLabelValues := map[string]string{metrics.LServiceName: inv.MicroServiceName, metrics.LApp: inv.RouteTags.AppID(), metrics.LVersion: inv.RouteTags.Version()}
- metrics.RecordLatency(serviceLabelValues, timeTaken, nil)
+ metrics.RecordLatency(serviceLabelValues, timeTaken)
}(time.Now())
var invRsp *invocation.Response
c.Next(inv, func(ir *invocation.Response) error {
@@ -159,7 +158,7 @@
})
resp, err := handleRequest(w, inv, invRsp)
if err != nil {
- lager.Logger.Error("Handle request failed: " + err.Error())
+ openlogging.Error("handle request failed: " + err.Error())
return
}
RecordStatus(inv, resp.StatusCode)
@@ -304,7 +303,7 @@
//RecordStatus record an operation status
func RecordStatus(inv *invocation.Invocation, statusCode int) {
LabelValues := map[string]string{metrics.LServiceName: inv.MicroServiceName, metrics.LApp: inv.RouteTags.AppID(), metrics.LVersion: inv.RouteTags.Version()}
- metrics.RecordStatus(LabelValues, statusCode, nil)
+ metrics.RecordStatus(LabelValues, statusCode)
}
func copyHeader(dst, src http.Header) {
for k, vs := range src {
diff --git a/proxy/resource/v1/route/mock/route.go b/proxy/resource/v1/route/mock/route.go
deleted file mode 100644
index 5eb2109..0000000
--- a/proxy/resource/v1/route/mock/route.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 mock
-
-import (
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/router"
- "github.com/stretchr/testify/mock"
-)
-
-//RouterMock ..
-type RouterMock struct {
- mock.Mock
-}
-
-//Init ..
-func (m *RouterMock) Init(router.Options) error {
- return nil
-}
-
-//SetRouteRule ..
-func (m *RouterMock) SetRouteRule(map[string][]*model.RouteRule) {}
-
-//FetchRouteRule ..
-func (m *RouterMock) FetchRouteRule() map[string][]*model.RouteRule {
- return nil
-}
-
-//InitRouteRuleByKey ..
-func (m *RouterMock) InitRouteRuleByKey(k string) {}
-
-//FetchRouteRuleByServiceName ..
-func (m *RouterMock) FetchRouteRuleByServiceName(s string) []*model.RouteRule {
- args := m.Called(s)
- rules, ok := args.Get(0).([]*model.RouteRule)
- if !ok {
- return nil
- }
- return rules
-}
diff --git a/proxy/resource/v1/route/route.go b/proxy/resource/v1/route/route.go
index 13f5957..e04a223 100644
--- a/proxy/resource/v1/route/route.go
+++ b/proxy/resource/v1/route/route.go
@@ -18,19 +18,19 @@
package route
import (
- "github.com/go-chassis/go-chassis/core/config/model"
+ "github.com/go-chassis/go-chassis/core/config"
"github.com/go-chassis/go-chassis/core/router"
)
//Rules is the struct for route rule
type Rules struct {
- Destinations map[string][]*model.RouteRule `yaml:"routeRule"`
+ Destinations map[string][]*config.RouteRule `yaml:"routeRule"`
}
var routeRules *Rules
//GetServiceRouteRule gets route rule for that service
-func GetServiceRouteRule(serviceName string) []*model.RouteRule {
+func GetServiceRouteRule(serviceName string) []*config.RouteRule {
if routeRules != nil {
if v, ok := routeRules.Destinations[serviceName]; ok {
return v
@@ -42,7 +42,7 @@
routeRules = new(Rules)
}
if routeRules.Destinations == nil {
- routeRules.Destinations = make(map[string][]*model.RouteRule)
+ routeRules.Destinations = make(map[string][]*config.RouteRule)
}
routeRules.Destinations[serviceName] = rules
return rules
diff --git a/proxy/server/server.go b/proxy/server/server.go
index 3a8b90d..717f7f7 100644
--- a/proxy/server/server.go
+++ b/proxy/server/server.go
@@ -70,15 +70,17 @@
func profile() {
if config.GetConfig().PProf != nil {
if config.GetConfig().PProf.Enable {
- go func() {
- if config.GetConfig().PProf.Listen == "" {
- config.GetConfig().PProf.Listen = "127.0.0.1:6060"
- }
- openlogging.Warn("Enable pprof on " + config.GetConfig().PProf.Listen)
- if err := http.ListenAndServe(config.GetConfig().PProf.Listen, nil); err != nil {
- openlogging.Error("Can not enable pprof: " + err.Error())
- }
- }()
+ go startProfiling()
}
}
}
+
+func startProfiling() {
+ if config.GetConfig().PProf.Listen == "" {
+ config.GetConfig().PProf.Listen = "127.0.0.1:6060"
+ }
+ openlogging.Warn("Enable pprof on " + config.GetConfig().PProf.Listen)
+ if err := http.ListenAndServe(config.GetConfig().PProf.Listen, nil); err != nil {
+ openlogging.Error("Can not enable pprof: " + err.Error())
+ }
+}