Skip to content

Commit

Permalink
support one-dapr-sidecar-per-function mode
Browse files Browse the repository at this point in the history
Signed-off-by: wrongerror <[email protected]>
  • Loading branch information
wrongerror committed Sep 22, 2022
1 parent 4c93345 commit 46bce09
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 1,603 deletions.
22 changes: 17 additions & 5 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
"os"
"strconv"
Expand All @@ -22,7 +23,8 @@ import (
)

var (
clientGRPCPort string
daprGRPCHost string
daprGRPCPort string
bindingQueueComponents = map[string]bool{
"bindings.kafka": true,
"bindings.rabbitmq": true,
Expand Down Expand Up @@ -50,7 +52,8 @@ const (
InternalError = 500
defaultPort = "8080"
defaultHttpPattern = "/"
daprSidecarGRPCPort = "50001"
defaultDaprHost = "127.0.0.1"
defaultDaprGRPCPort = "50001"
TracingProviderSkywalking = "skywalking"
TracingProviderOpentelemetry = "opentelemetry"
KubernetesMode = "kubernetes"
Expand Down Expand Up @@ -451,7 +454,8 @@ func (ctx *FunctionContext) InitDaprClientIfNil() {
defer ctx.mu.Unlock()

for attempts := 120; attempts > 0; attempts-- {
c, e := dapr.NewClientWithPort(clientGRPCPort)
address := net.JoinHostPort(daprGRPCHost, daprGRPCPort)
c, e := dapr.NewClientWithAddress(address)
if e == nil {
ctx.daprClient = c
break
Expand Down Expand Up @@ -851,13 +855,21 @@ func parseContext() (*FunctionContext, error) {
ctx.HttpPattern = defaultHttpPattern
}

// Support one-sidecar-per-function mode
host := os.Getenv("DAPR_HOST")
if host == "" {
daprGRPCHost = defaultDaprHost
} else {
daprGRPCHost = host
}

// When using self-hosted mode, configure the client port via env,
// refer to https://docs.dapr.io/reference/environment/
port := os.Getenv("DAPR_GRPC_PORT")
if port == "" {
clientGRPCPort = daprSidecarGRPCPort
daprGRPCPort = defaultDaprGRPCPort
} else {
clientGRPCPort = port
daprGRPCPort = port
}

// Initialize the context options
Expand Down
71 changes: 70 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,92 @@ require (
)

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.1 // indirect
contrib.go.opencensus.io/exporter/zipkin v0.1.1 // indirect
github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dapr/components-contrib v1.8.1-rc.1 // indirect
github.com/dapr/kit v0.0.2-0.20210614175626-b9074b64d233 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fasthttp/router v1.3.8 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/cel-go v0.9.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.14.4 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/openzipkin/zipkin-go v0.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/statsd_exporter v0.22.3 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/savsgio/gotils v0.0.0-20210217112953-d4a072536008 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sony/gobreaker v0.4.2-0.20210216022020-dd874f9dd33b // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.31.1-0.20211216042702-258a4c17b4f4 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/net v0.0.0-20220621193019-9d032be2e588 // indirect
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220622171453-ea41d75dfa0f // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.23.0 // indirect
k8s.io/apiextensions-apiserver v0.23.0 // indirect
k8s.io/apimachinery v0.23.0 // indirect
k8s.io/client-go v0.23.0 // indirect
k8s.io/component-base v0.23.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
sigs.k8s.io/controller-runtime v0.11.0 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace go.opentelemetry.io/otel => go.opentelemetry.io/otel v0.20.0
Loading

0 comments on commit 46bce09

Please sign in to comment.