Skip to content

Commit 28cbda8

Browse files
authored
Merge pull request #65 from wrongerror/main
support one-dapr-sidecar-per-function mode
2 parents f6a2325 + 449f37a commit 28cbda8

File tree

11 files changed

+189
-1602
lines changed

11 files changed

+189
-1602
lines changed

context/context.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"net"
89
"net/http"
910
"os"
1011
"strconv"
@@ -22,7 +23,8 @@ import (
2223
)
2324

2425
var (
25-
clientGRPCPort string
26+
daprGRPCHost string
27+
daprGRPCPort string
2628
bindingQueueComponents = map[string]bool{
2729
"bindings.kafka": true,
2830
"bindings.rabbitmq": true,
@@ -50,7 +52,8 @@ const (
5052
InternalError = 500
5153
defaultPort = "8080"
5254
defaultHttpPattern = "/"
53-
daprSidecarGRPCPort = "50001"
55+
defaultDaprHost = "127.0.0.1"
56+
defaultDaprGRPCPort = "50001"
5457
TracingProviderSkywalking = "skywalking"
5558
TracingProviderOpentelemetry = "opentelemetry"
5659
KubernetesMode = "kubernetes"
@@ -451,7 +454,8 @@ func (ctx *FunctionContext) InitDaprClientIfNil() {
451454
defer ctx.mu.Unlock()
452455

453456
for attempts := 120; attempts > 0; attempts-- {
454-
c, e := dapr.NewClientWithPort(clientGRPCPort)
457+
address := net.JoinHostPort(daprGRPCHost, daprGRPCPort)
458+
c, e := dapr.NewClientWithAddress(address)
455459
if e == nil {
456460
ctx.daprClient = c
457461
break
@@ -851,13 +855,21 @@ func parseContext() (*FunctionContext, error) {
851855
ctx.HttpPattern = defaultHttpPattern
852856
}
853857

858+
// Support one-sidecar-per-function mode
859+
host := os.Getenv("DAPR_HOST")
860+
if host == "" {
861+
daprGRPCHost = defaultDaprHost
862+
} else {
863+
daprGRPCHost = host
864+
}
865+
854866
// When using self-hosted mode, configure the client port via env,
855867
// refer to https://docs.dapr.io/reference/environment/
856868
port := os.Getenv("DAPR_GRPC_PORT")
857869
if port == "" {
858-
clientGRPCPort = daprSidecarGRPCPort
870+
daprGRPCPort = defaultDaprGRPCPort
859871
} else {
860-
clientGRPCPort = port
872+
daprGRPCPort = port
861873
}
862874

863875
// Initialize the context options

go.mod

+70-1
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,92 @@ require (
1919
)
2020

2121
require (
22+
contrib.go.opencensus.io/exporter/prometheus v0.4.1 // indirect
23+
contrib.go.opencensus.io/exporter/zipkin v0.1.1 // indirect
24+
github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a // indirect
25+
github.com/PuerkitoBio/purell v1.1.1 // indirect
26+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
27+
github.com/andybalholm/brotli v1.0.2 // indirect
28+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e // indirect
29+
github.com/beorn7/perks v1.0.1 // indirect
30+
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
31+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
32+
github.com/dapr/components-contrib v1.8.1-rc.1 // indirect
33+
github.com/dapr/kit v0.0.2-0.20210614175626-b9074b64d233 // indirect
2234
github.com/davecgh/go-spew v1.1.1 // indirect
35+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
36+
github.com/fasthttp/router v1.3.8 // indirect
37+
github.com/fsnotify/fsnotify v1.5.4 // indirect
38+
github.com/ghodss/yaml v1.0.0 // indirect
39+
github.com/go-kit/log v0.2.0 // indirect
40+
github.com/go-logfmt/logfmt v0.5.1 // indirect
2341
github.com/go-logr/logr v1.2.3 // indirect
42+
github.com/gogo/protobuf v1.3.2 // indirect
43+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
44+
github.com/golang/mock v1.6.0 // indirect
45+
github.com/google/cel-go v0.9.0 // indirect
46+
github.com/google/go-cmp v0.5.8 // indirect
47+
github.com/google/gofuzz v1.2.0 // indirect
48+
github.com/googleapis/gnostic v0.5.5 // indirect
49+
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
50+
github.com/hashicorp/errwrap v1.1.0 // indirect
51+
github.com/hashicorp/go-multierror v1.1.1 // indirect
52+
github.com/hashicorp/golang-lru v0.5.4 // indirect
53+
github.com/imdario/mergo v0.3.12 // indirect
2454
github.com/json-iterator/go v1.1.12 // indirect
55+
github.com/klauspost/compress v1.14.4 // indirect
2556
github.com/kr/pretty v0.3.0 // indirect
57+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
58+
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
59+
github.com/mitchellh/mapstructure v1.5.0 // indirect
2660
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2761
github.com/modern-go/reflect2 v1.0.2 // indirect
62+
github.com/openzipkin/zipkin-go v0.2.2 // indirect
2863
github.com/pmezard/go-difflib v1.0.0 // indirect
64+
github.com/prometheus/client_golang v1.12.2 // indirect
65+
github.com/prometheus/client_model v0.2.0 // indirect
66+
github.com/prometheus/common v0.34.0 // indirect
67+
github.com/prometheus/procfs v0.7.3 // indirect
68+
github.com/prometheus/statsd_exporter v0.22.3 // indirect
2969
github.com/rogpeppe/go-internal v1.8.0 // indirect
70+
github.com/savsgio/gotils v0.0.0-20210217112953-d4a072536008 // indirect
71+
github.com/sirupsen/logrus v1.8.1 // indirect
72+
github.com/sony/gobreaker v0.4.2-0.20210216022020-dd874f9dd33b // indirect
73+
github.com/spf13/pflag v1.0.5 // indirect
74+
github.com/stoewer/go-strcase v1.2.0 // indirect
75+
github.com/stretchr/objx v0.4.0 // indirect
76+
github.com/valyala/bytebufferpool v1.0.0 // indirect
77+
github.com/valyala/fasthttp v1.31.1-0.20211216042702-258a4c17b4f4 // indirect
78+
go.opencensus.io v0.23.0 // indirect
79+
go.opentelemetry.io/otel v1.7.0 // indirect
3080
go.uber.org/atomic v1.9.0 // indirect
31-
go.uber.org/goleak v1.1.12 // indirect
3281
go.uber.org/multierr v1.7.0 // indirect
3382
go.uber.org/zap v1.21.0 // indirect
3483
golang.org/x/net v0.0.0-20220621193019-9d032be2e588 // indirect
84+
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect
3585
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
86+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
3687
golang.org/x/text v0.3.7 // indirect
88+
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
89+
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
90+
google.golang.org/appengine v1.6.7 // indirect
3791
google.golang.org/genproto v0.0.0-20220622171453-ea41d75dfa0f // indirect
3892
google.golang.org/protobuf v1.28.0 // indirect
3993
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
94+
gopkg.in/inf.v0 v0.9.1 // indirect
95+
gopkg.in/yaml.v2 v2.4.0 // indirect
4096
gopkg.in/yaml.v3 v3.0.1 // indirect
97+
k8s.io/api v0.23.0 // indirect
98+
k8s.io/apiextensions-apiserver v0.23.0 // indirect
99+
k8s.io/apimachinery v0.23.0 // indirect
100+
k8s.io/client-go v0.23.0 // indirect
101+
k8s.io/component-base v0.23.0 // indirect
102+
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
103+
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
104+
sigs.k8s.io/controller-runtime v0.11.0 // indirect
105+
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
106+
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
107+
sigs.k8s.io/yaml v1.3.0 // indirect
41108
)
109+
110+
replace go.opentelemetry.io/otel => go.opentelemetry.io/otel v0.20.0

0 commit comments

Comments
 (0)