From 95fc0872b90597af020bf20335c47caa9d9ea00c Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Wed, 27 Dec 2023 12:27:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8DLoadBalance=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E9=80=89=E6=8B=A9=E5=A4=84=E4=BA=8E=E5=8D=8A=E5=BC=80?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E4=BE=8B=20(#196)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/quickstart/consumer/Dockerfile | 19 +++++++ examples/quickstart/consumer/go.mod | 2 +- examples/quickstart/consumer/go.sum | 9 +--- examples/quickstart/consumer/polaris.yaml | 2 +- .../quickstart/k8s/configmap-consumer.yaml | 11 ++++ .../quickstart/k8s/configmap-provider.yaml | 11 ++++ .../quickstart/k8s/deployment-consumer.yaml | 35 ++++++++++++ .../quickstart/k8s/deployment-provider.yaml | 54 +++++++++++++++++++ examples/quickstart/provider/Dockerfile | 20 +++++++ examples/quickstart/provider/go.mod | 2 +- examples/quickstart/provider/go.sum | 9 +--- examples/quickstart/provider/isolate.sh | 5 ++ examples/quickstart/provider/main.go | 9 ++-- examples/quickstart/provider/polaris.yaml | 2 +- pkg/plugin/loadbalancer/proxy.go | 3 +- 15 files changed, 169 insertions(+), 24 deletions(-) create mode 100644 examples/quickstart/consumer/Dockerfile create mode 100644 examples/quickstart/k8s/configmap-consumer.yaml create mode 100644 examples/quickstart/k8s/configmap-provider.yaml create mode 100644 examples/quickstart/k8s/deployment-consumer.yaml create mode 100644 examples/quickstart/k8s/deployment-provider.yaml create mode 100644 examples/quickstart/provider/Dockerfile create mode 100644 examples/quickstart/provider/isolate.sh diff --git a/examples/quickstart/consumer/Dockerfile b/examples/quickstart/consumer/Dockerfile new file mode 100644 index 00000000..f2693367 --- /dev/null +++ b/examples/quickstart/consumer/Dockerfile @@ -0,0 +1,19 @@ +FROM alpine:3.13.6 + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add busybox-extras && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +COPY consumer /root/consumer + +WORKDIR /root + +CMD ["/root/consumer"] \ No newline at end of file diff --git a/examples/quickstart/consumer/go.mod b/examples/quickstart/consumer/go.mod index 86f3aac6..91f78fac 100644 --- a/examples/quickstart/consumer/go.mod +++ b/examples/quickstart/consumer/go.mod @@ -17,7 +17,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/polarismesh/specification v1.3.2-alpha.2 // indirect + github.com/polarismesh/specification v1.4.1 // indirect github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect diff --git a/examples/quickstart/consumer/go.sum b/examples/quickstart/consumer/go.sum index 093a5191..d93306f5 100644 --- a/examples/quickstart/consumer/go.sum +++ b/examples/quickstart/consumer/go.sum @@ -171,7 +171,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -321,7 +320,6 @@ github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99 github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c= github.com/googleapis/gax-go/v2 v2.5.1/go.mod h1:h6B0KMMFNtI2ddbGJn3T3ZbwkeT6yqEF02fYlzkUCyo= github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -340,7 +338,6 @@ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= @@ -375,8 +372,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA= -github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= +github.com/polarismesh/specification v1.4.1 h1:lTZqeyUhhWuKyr6NDKBwmUrNfcUDvKLxWT/uOq71T5A= +github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= @@ -404,9 +401,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= -github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= diff --git a/examples/quickstart/consumer/polaris.yaml b/examples/quickstart/consumer/polaris.yaml index c6ac55cf..07e08516 100644 --- a/examples/quickstart/consumer/polaris.yaml +++ b/examples/quickstart/consumer/polaris.yaml @@ -1,7 +1,7 @@ global: serverConnector: addresses: - - 119.91.66.223:8091 + - 127.0.0.1:8091 statReporter: enable: true chain: diff --git a/examples/quickstart/k8s/configmap-consumer.yaml b/examples/quickstart/k8s/configmap-consumer.yaml new file mode 100644 index 00000000..c36e0b3e --- /dev/null +++ b/examples/quickstart/k8s/configmap-consumer.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +data: + polaris.yaml: |- + global: + serverConnector: + addresses: + - { PolarisServerIP:GrpcPort } +kind: ConfigMap +metadata: + name: polaris-consumer-config + namespace: examples-go diff --git a/examples/quickstart/k8s/configmap-provider.yaml b/examples/quickstart/k8s/configmap-provider.yaml new file mode 100644 index 00000000..b8a480c1 --- /dev/null +++ b/examples/quickstart/k8s/configmap-provider.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +data: + polaris.yaml: |- + global: + serverConnector: + addresses: + - { PolarisServerIP:GrpcPort } +kind: ConfigMap +metadata: + name: polaris-provider-config + namespace: examples-go diff --git a/examples/quickstart/k8s/deployment-consumer.yaml b/examples/quickstart/k8s/deployment-consumer.yaml new file mode 100644 index 00000000..9c1fcff0 --- /dev/null +++ b/examples/quickstart/k8s/deployment-consumer.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: consumer + namespace: examples-go +spec: + replicas: 1 + selector: + matchLabels: + app: consumer + template: + metadata: + labels: + app: consumer + spec: + containers: + - image: polarismesh/examples-go-consumer:latest + imagePullPolicy: Always + name: polaris-consumer + resources: + limits: + cpu: "500m" + memory: 1000Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /root/polaris.yaml + name: polaris-consumer-config + subPath: polaris.yaml + restartPolicy: Always + volumes: + - configMap: + defaultMode: 420 + name: polaris-consumer-config + name: polaris-consumer-config diff --git a/examples/quickstart/k8s/deployment-provider.yaml b/examples/quickstart/k8s/deployment-provider.yaml new file mode 100644 index 00000000..6d9dbfb7 --- /dev/null +++ b/examples/quickstart/k8s/deployment-provider.yaml @@ -0,0 +1,54 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: provider + namespace: examples-go +spec: + replicas: 3 + selector: + matchLabels: + app: provider + template: + metadata: + labels: + app: provider + spec: + containers: + - image: polarismesh/examples-go-provider:latest + imagePullPolicy: Always + name: polaris-provider + env: + - name: INSTANCE_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: INSTANCE_PORT + value: "28080" + - name: "INSTANCE_SERVICE" + value: "DiscoverEchoServer" + - name: "INSTANCE_NAMESPACE" + value: "default" + - name: "POLARIS_OPEN_API" + value: "" + - name: "POLARIS_TOKEN" + value: "" + resources: + limits: + cpu: "500m" + memory: 1000Mi + lifecycle: + preStop: + exec: + command: ["/bin/bash", "-c", "cd /root; bash ./isolate.sh; sleep 30; exit 0;"] + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /root/polaris.yaml + name: polaris-provider-config + subPath: polaris.yaml + restartPolicy: Always + volumes: + - configMap: + defaultMode: 420 + name: polaris-provider-config + name: polaris-provider-config diff --git a/examples/quickstart/provider/Dockerfile b/examples/quickstart/provider/Dockerfile new file mode 100644 index 00000000..4ff74488 --- /dev/null +++ b/examples/quickstart/provider/Dockerfile @@ -0,0 +1,20 @@ +FROM alpine:3.13.6 + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add busybox-extras && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +COPY provider /root/provider +COPY isolate.sh /root/isolate.sh + +WORKDIR /root + +CMD ["/root/provider", "-port", "28080"] \ No newline at end of file diff --git a/examples/quickstart/provider/go.mod b/examples/quickstart/provider/go.mod index dc988a11..4c23a466 100644 --- a/examples/quickstart/provider/go.mod +++ b/examples/quickstart/provider/go.mod @@ -17,7 +17,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/polarismesh/specification v1.4.0 // indirect + github.com/polarismesh/specification v1.4.1 // indirect github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect diff --git a/examples/quickstart/provider/go.sum b/examples/quickstart/provider/go.sum index 41c830a6..d93306f5 100644 --- a/examples/quickstart/provider/go.sum +++ b/examples/quickstart/provider/go.sum @@ -171,7 +171,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -321,7 +320,6 @@ github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99 github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c= github.com/googleapis/gax-go/v2 v2.5.1/go.mod h1:h6B0KMMFNtI2ddbGJn3T3ZbwkeT6yqEF02fYlzkUCyo= github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -340,7 +338,6 @@ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= @@ -375,8 +372,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/specification v1.4.0 h1:fm7sUtFZC2g9+lLmRCtjGrUow47CY5JDFoZXwwCQGGY= -github.com/polarismesh/specification v1.4.0/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= +github.com/polarismesh/specification v1.4.1 h1:lTZqeyUhhWuKyr6NDKBwmUrNfcUDvKLxWT/uOq71T5A= +github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= @@ -404,9 +401,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= -github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= diff --git a/examples/quickstart/provider/isolate.sh b/examples/quickstart/provider/isolate.sh new file mode 100644 index 00000000..0e9df827 --- /dev/null +++ b/examples/quickstart/provider/isolate.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +data="[{\"service\":\"${INSTANCE_SERVICE}\",\"namespace\":\"${INSTANCE_NAMESPACE}\",\"host\":\"${INSTANCE_IP}\",\"port\":\"${INSTANCE_PORT}\",\"isolate\":true}]" +echo "${data}" +curl -H "X-Polaris-Token; ${POLARIS_TOKEN}" -H 'Content-Type: application/json' -X PUT -d "${data}" "http://${POLARIS_OPEN_API}/naming/v1/instances" diff --git a/examples/quickstart/provider/main.go b/examples/quickstart/provider/main.go index b611f08a..ea7dc25c 100644 --- a/examples/quickstart/provider/main.go +++ b/examples/quickstart/provider/main.go @@ -54,6 +54,7 @@ type PolarisProvider struct { host string port int isShutdown bool + webSvr *http.Server } // Run starts the provider @@ -83,7 +84,8 @@ func (svr *PolarisProvider) runWebServer() { go func() { log.Printf("[INFO] start http server, listen port is %v", svr.port) - if err := http.Serve(ln, nil); err != nil { + svr.webSvr = &http.Server{Handler: nil} + if err := svr.webSvr.Serve(ln); err != nil { svr.isShutdown = false log.Fatalf("[ERROR]fail to run webServer, err is %v", err) } @@ -99,8 +101,6 @@ func (svr *PolarisProvider) registerService() { registerRequest.Port = svr.port registerRequest.ServiceToken = token registerRequest.SetTTL(1) - // 实例id不是必填,如果不填,服务端会默认生成一个唯一Id,否则当提供实例id时,需要保证实例id是唯一的 - registerRequest.InstanceId = providedInstanceId(namespace, service, svr.host, svr.port) resp, err := svr.provider.RegisterInstance(registerRequest) if err != nil { log.Fatalf("fail to register instance, err is %v", err) @@ -116,8 +116,6 @@ func (svr *PolarisProvider) deregisterService() { deregisterRequest.Host = svr.host deregisterRequest.Port = svr.port deregisterRequest.ServiceToken = token - // 实例id不是必填,如果注册时指定了实例id,则反注册时需要提供同样的id - deregisterRequest.InstanceID = providedInstanceId(namespace, service, svr.host, svr.port) if err := svr.provider.Deregister(deregisterRequest); err != nil { log.Fatalf("fail to deregister instance, err is %v", err) } @@ -135,6 +133,7 @@ func (svr *PolarisProvider) runMainLoop() { log.Printf("catch signal(%+v), stop servers", s) svr.isShutdown = true svr.deregisterService() + _ = svr.webSvr.Close() return } } diff --git a/examples/quickstart/provider/polaris.yaml b/examples/quickstart/provider/polaris.yaml index c6ac55cf..07e08516 100644 --- a/examples/quickstart/provider/polaris.yaml +++ b/examples/quickstart/provider/polaris.yaml @@ -1,7 +1,7 @@ global: serverConnector: addresses: - - 119.91.66.223:8091 + - 127.0.0.1:8091 statReporter: enable: true chain: diff --git a/pkg/plugin/loadbalancer/proxy.go b/pkg/plugin/loadbalancer/proxy.go index 5da24d26..1a1c5b6d 100644 --- a/pkg/plugin/loadbalancer/proxy.go +++ b/pkg/plugin/loadbalancer/proxy.go @@ -43,7 +43,8 @@ type SelectStatus struct { // ChooseInstance proxy LoadBalancer ChooseInstance func (p *Proxy) ChooseInstance(criteria *Criteria, instances model.ServiceInstances) (model.Instance, error) { - // 第一次进行负载均衡,包括半开实例 + // 包括处于半开的实例 + criteria.Cluster.IncludeHalfOpen = true result, err := p.LoadBalancer.ChooseInstance(criteria, instances) return result, err }