From dc50c0d446cb6de99362c726af5b158f19475f4b Mon Sep 17 00:00:00 2001 From: luckyxiaoqiang Date: Sat, 20 Mar 2021 01:25:05 +0800 Subject: [PATCH 1/4] Fix typos in comments (#2928) Co-authored-by: Nghia Tran Co-authored-by: Artur Souza --- pkg/diagnostics/grpc_tracing.go | 2 +- pkg/diagnostics/http_tracing.go | 2 +- pkg/diagnostics/tracing.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/diagnostics/grpc_tracing.go b/pkg/diagnostics/grpc_tracing.go index 1803f958607..aacb9644b6c 100644 --- a/pkg/diagnostics/grpc_tracing.go +++ b/pkg/diagnostics/grpc_tracing.go @@ -80,7 +80,7 @@ func GRPCTraceUnaryServerInterceptor(appID string, spec config.TracingSpec) grpc } } -// userDefinedMetadata returns dapr- prefixed header from incoming metdata. +// userDefinedMetadata returns dapr- prefixed header from incoming metadata. // Users can add dapr- prefixed headers that they want to see in span attributes. func userDefinedMetadata(ctx context.Context) map[string]string { var daprMetadata = map[string]string{} diff --git a/pkg/diagnostics/http_tracing.go b/pkg/diagnostics/http_tracing.go index b49db27edce..513448bb723 100644 --- a/pkg/diagnostics/http_tracing.go +++ b/pkg/diagnostics/http_tracing.go @@ -69,7 +69,7 @@ func HTTPTraceMiddleware(next fasthttp.RequestHandler, appID string, spec config } } -// userDefinedHTTPHeaders returns dapr- prefixed header from incoming metdata. +// userDefinedHTTPHeaders returns dapr- prefixed header from incoming metadata. // Users can add dapr- prefixed headers that they want to see in span attributes. func userDefinedHTTPHeaders(reqCtx *fasthttp.RequestCtx) map[string]string { var m = map[string]string{} diff --git a/pkg/diagnostics/tracing.go b/pkg/diagnostics/tracing.go index 6e4f9081b1d..558907d76a4 100644 --- a/pkg/diagnostics/tracing.go +++ b/pkg/diagnostics/tracing.go @@ -29,7 +29,7 @@ const ( // daprInternalSpanAttrPrefix is the internal span attribution prefix. // Middleware will not populate it if the span key starts with this prefix. daprInternalSpanAttrPrefix = "__dapr." - // daprAPISpanNameInternal is the internal attributation, but not populated + // daprAPISpanNameInternal is the internal attribution, but not populated // to span attribution. daprAPISpanNameInternal = daprInternalSpanAttrPrefix + "spanname" From bd6d46a6ece07a54f9c6fdab047ef920e4239c31 Mon Sep 17 00:00:00 2001 From: luckyxiaoqiang Date: Sat, 20 Mar 2021 01:41:40 +0800 Subject: [PATCH 2/4] Use filepath pkg to do file path joining operations (#2920) Co-authored-by: Yaron Schneider --- pkg/components/standalone_loader.go | 8 ++++---- pkg/runtime/pubsub/subscriptions.go | 4 ++-- pkg/runtime/pubsub/subscriptions_test.go | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/components/standalone_loader.go b/pkg/components/standalone_loader.go index 65d1ff921d6..ee335dc230a 100644 --- a/pkg/components/standalone_loader.go +++ b/pkg/components/standalone_loader.go @@ -8,7 +8,6 @@ package components import ( "bufio" "bytes" - "fmt" "io" "io/ioutil" "path/filepath" @@ -48,14 +47,15 @@ func (s *StandaloneComponents) LoadComponents() ([]components_v1alpha1.Component for _, file := range files { if !file.IsDir() && s.isYaml(file.Name()) { - b, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", dir, file.Name())) + path := filepath.Join(dir, file.Name()) + b, err := ioutil.ReadFile(path) if err != nil { - log.Warnf("error reading file %s/%s : %s", dir, file.Name(), err) + log.Warnf("error reading file %s : %s", path, err) continue } - components, _ := s.decodeYaml(fmt.Sprintf("%s/%s", dir, file.Name()), b) + components, _ := s.decodeYaml(path, b) list = append(list, components...) } } diff --git a/pkg/runtime/pubsub/subscriptions.go b/pkg/runtime/pubsub/subscriptions.go index 85c7a1d943c..861bb4f9aaf 100644 --- a/pkg/runtime/pubsub/subscriptions.go +++ b/pkg/runtime/pubsub/subscriptions.go @@ -3,10 +3,10 @@ package pubsub import ( "context" "encoding/json" - "fmt" "io/ioutil" "net/http" "os" + "path/filepath" subscriptionsapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1" "github.com/dapr/dapr/pkg/channel" @@ -106,7 +106,7 @@ func DeclarativeSelfHosted(componentsPath string, log logger.Logger) []Subscript for _, f := range files { if !f.IsDir() { - filePath := fmt.Sprintf("%s/%s", componentsPath, f.Name()) + filePath := filepath.Join(componentsPath, f.Name()) b, err := ioutil.ReadFile(filePath) if err != nil { log.Errorf("failed to read file %s: %s", filePath, err) diff --git a/pkg/runtime/pubsub/subscriptions_test.go b/pkg/runtime/pubsub/subscriptions_test.go index e7cf22def21..7539c0ca742 100644 --- a/pkg/runtime/pubsub/subscriptions_test.go +++ b/pkg/runtime/pubsub/subscriptions_test.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "testing" subscriptionsapi "github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1" @@ -56,7 +57,7 @@ func writeSubscriptionToDisk(subscription subscriptionsapi.Subscription, filePat } func TestDeclarativeSubscriptions(t *testing.T) { - dir := "./components" + dir := filepath.Join(".", "components") os.Mkdir(dir, 0777) defer os.RemoveAll(dir) @@ -64,7 +65,7 @@ func TestDeclarativeSubscriptions(t *testing.T) { s := testDeclarativeSubscription() s.Scopes = []string{"scope1"} - filePath := "./components/sub.yaml" + filePath := filepath.Join(".", "components", "sub.yaml") writeSubscriptionToDisk(s, filePath) subs := DeclarativeSelfHosted(dir, log) From 6472e08a3960981544f0123386ee7a59c970c100 Mon Sep 17 00:00:00 2001 From: yellow chicks Date: Fri, 19 Mar 2021 12:55:53 -0500 Subject: [PATCH 3/4] fixme(fasthttp/router): upgrade fasthttp router to solve '/' (#2863) Co-authored-by: Yaron Schneider Co-authored-by: Artur Souza --- go.mod | 7 +++++-- go.sum | 16 +++++++++++----- pkg/http/api.go | 3 +-- pkg/http/api_test.go | 4 ++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 9258861a33e..b5a2b0f841a 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,10 @@ require ( github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a github.com/PuerkitoBio/purell v1.1.1 github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b + github.com/andybalholm/brotli v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.1.0 github.com/dapr/components-contrib v1.0.1-0.20210318212214-192461889c55 - github.com/fasthttp/router v1.3.5 + github.com/fasthttp/router v1.3.8 github.com/fsnotify/fsnotify v1.4.9 github.com/ghodss/yaml v1.0.0 github.com/golang/protobuf v1.4.3 @@ -24,6 +25,7 @@ require ( github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea github.com/json-iterator/go v1.1.10 github.com/kelseyhightower/envconfig v1.4.0 + github.com/klauspost/compress v1.11.8 // indirect github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 github.com/mitchellh/mapstructure v1.3.3 github.com/nats-io/nats-streaming-server v0.21.1 // indirect @@ -33,10 +35,11 @@ require ( github.com/prometheus/client_golang v1.8.0 github.com/prometheus/client_model v0.2.0 github.com/prometheus/common v0.14.0 + github.com/savsgio/gotils v0.0.0-20210225112730-595c7e5a8a7a // indirect github.com/sendgrid/rest v2.6.2+incompatible // indirect github.com/sirupsen/logrus v1.6.0 github.com/stretchr/testify v1.6.1 - github.com/valyala/fasthttp v1.19.0 + github.com/valyala/fasthttp v1.21.0 go.opencensus.io v0.22.5 go.opentelemetry.io/otel v0.13.0 go.uber.org/atomic v1.6.0 diff --git a/go.sum b/go.sum index 98cf0b12ad5..6af3eaf2417 100644 --- a/go.sum +++ b/go.sum @@ -182,8 +182,9 @@ github.com/alicebob/miniredis/v2 v2.13.3/go.mod h1:uS970Sw5Gs9/iK3yBg0l9Uj9s25wX github.com/aliyun/aliyun-oss-go-sdk v2.0.7+incompatible h1:HXvOJsZw8JT/ldxjX74Aq4H2IY4ojV/mXMDPWFitpv8= github.com/aliyun/aliyun-oss-go-sdk v2.0.7+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4= github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc= +github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/apache/pulsar-client-go v0.1.0 h1:2BFZztxtNgFyOzBc+5On84CX6aIZW5xwh7KM0MWigGI= github.com/apache/pulsar-client-go v0.1.0/go.mod h1:G+CQVHnh2EPfNEQXOuisIDAyPMiKnzz4Vim/kjtj4U4= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= @@ -360,8 +361,9 @@ github.com/fasthttp-contrib/sessions v0.0.0-20160905201309-74f6ac73d5d5 h1:M4CVM github.com/fasthttp-contrib/sessions v0.0.0-20160905201309-74f6ac73d5d5/go.mod h1:MQXNGeXkpojWTxbN7vXoE3f7EmlA11MlJbsrJpVBINA= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= github.com/fasthttp/router v1.3.2/go.mod h1:athTSKMdel0Qhh3W4nB8qn+EPYuyj6YZMUo6ZcXWTgc= -github.com/fasthttp/router v1.3.5 h1:XGZZtcYUH+9ZoLxKhwF66F8sGnMT+Jg00j0JdVzwmDA= github.com/fasthttp/router v1.3.5/go.mod h1:BylQKgvh6YQkR0mvL60+HJyTaGwcn5d8UFNweOb/Nw8= +github.com/fasthttp/router v1.3.8 h1:2ByFINIskXMu8aim/JmZ8WPU7FD4FjaXdUE/tBoAgDI= +github.com/fasthttp/router v1.3.8/go.mod h1:DQBvuHvYbn3SUN6pGjwjPbpCNpWfCFc5Ipn/Fj6XxFc= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= @@ -771,8 +773,9 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg= github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/klauspost/compress v1.11.8 h1:difgzQsp5mdAz9v8lm3P/I+EpDKMU/6uTMw1y1FObuo= +github.com/klauspost/compress v1.11.8/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/konsorten/go-windows-terminal-sequences v0.0.0-20180402223658-b729f2633dfe/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -1049,8 +1052,10 @@ github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0 github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/savsgio/gotils v0.0.0-20200616100644-13ff1fd2c28c/go.mod h1:TWNAOTaVzGOXq8RbEvHnhzA/A2sLZzgn0m6URjnukY8= -github.com/savsgio/gotils v0.0.0-20210105085219-0567298fdcac h1:5pr1F6tcjeIKPKlrQZW6hzB0WxZge7SkkYVGG/e5pLY= github.com/savsgio/gotils v0.0.0-20210105085219-0567298fdcac/go.mod h1:TWNAOTaVzGOXq8RbEvHnhzA/A2sLZzgn0m6URjnukY8= +github.com/savsgio/gotils v0.0.0-20210217112953-d4a072536008/go.mod h1:TWNAOTaVzGOXq8RbEvHnhzA/A2sLZzgn0m6URjnukY8= +github.com/savsgio/gotils v0.0.0-20210225112730-595c7e5a8a7a h1:9AQ3IfP72fCdbYAJNNwovzXrarhaWtxosEuN1fpent0= +github.com/savsgio/gotils v0.0.0-20210225112730-595c7e5a8a7a/go.mod h1:TWNAOTaVzGOXq8RbEvHnhzA/A2sLZzgn0m6URjnukY8= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sendgrid/rest v2.4.1+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE= @@ -1133,8 +1138,9 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w= github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= -github.com/valyala/fasthttp v1.19.0 h1:PfTS4PeH3xDr3WomrDS2ID8lU2GskK1xS3YG6gIpibU= github.com/valyala/fasthttp v1.19.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= +github.com/valyala/fasthttp v1.21.0 h1:fJjaQ7cXdaSF9vDBujlHLDGj7AgoMTMIXvICeePzYbU= +github.com/valyala/fasthttp v1.21.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4= github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= diff --git a/pkg/http/api.go b/pkg/http/api.go index ac282719476..a454052a18d 100644 --- a/pkg/http/api.go +++ b/pkg/http/api.go @@ -1195,8 +1195,7 @@ func (a *api) onPublish(reqCtx *fasthttp.RequestCtx) { } topic := reqCtx.UserValue(topicParam).(string) - // FIXME: isn't it "" instead? - if topic == "/" { + if topic == "" { msg := NewErrorResponse("ERR_TOPIC_EMPTY", fmt.Sprintf(messages.ErrTopicEmpty, pubsubName)) respondWithError(reqCtx, fasthttp.StatusNotFound, msg) log.Debug(msg) diff --git a/pkg/http/api_test.go b/pkg/http/api_test.go index e71fce2d67a..f5f6f39fd7d 100644 --- a/pkg/http/api_test.go +++ b/pkg/http/api_test.go @@ -139,14 +139,14 @@ func TestPubSubEndpoints(t *testing.T) { } }) - t.Run("Publish without topic name ending in // - 404", func(t *testing.T) { + t.Run("Publish with topic name '/' - 204", func(t *testing.T) { apiPath := fmt.Sprintf("%s/publish/pubsubname//", apiVersionV1) testMethods := []string{"POST", "PUT"} for _, method := range testMethods { // act resp := fakeServer.DoRequest(method, apiPath, []byte("{\"key\": \"value\"}"), nil) // assert - assert.Equal(t, 404, resp.StatusCode, "unexpected success publishing with %s", method) + assert.Equal(t, 204, resp.StatusCode, "success publishing with %s", method) } }) From 034022589c6fb4f9cf32aebc6278bd18d45e23b5 Mon Sep 17 00:00:00 2001 From: yellow chicks Date: Fri, 19 Mar 2021 13:13:22 -0500 Subject: [PATCH 4/4] feature(direct_messaging): add grpc failed call's log (#2930) * feat(direct_messaging): add grpc call failed log * Update direct_messaging.go * Update direct_messaging.go Co-authored-by: Yaron Schneider Co-authored-by: Artur Souza --- pkg/messaging/direct_messaging.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/messaging/direct_messaging.go b/pkg/messaging/direct_messaging.go index 7350c75d75f..d08e7348e0e 100644 --- a/pkg/messaging/direct_messaging.go +++ b/pkg/messaging/direct_messaging.go @@ -16,6 +16,7 @@ import ( "github.com/dapr/dapr/pkg/config" diag "github.com/dapr/dapr/pkg/diagnostics" diag_utils "github.com/dapr/dapr/pkg/diagnostics/utils" + "github.com/dapr/dapr/pkg/logger" "github.com/dapr/dapr/pkg/modes" "github.com/dapr/dapr/pkg/retry" "github.com/dapr/dapr/utils" @@ -29,6 +30,8 @@ import ( internalv1pb "github.com/dapr/dapr/pkg/proto/internals/v1" ) +var log = logger.NewLogger("dapr.runtime.direct_messaging") + // messageClientConnection is the function type to connect to the other // applications to send the message using service invocation. type messageClientConnection func(address, id string, namespace string, skipTLS, recreateIfExists, enableSSL bool) (*grpc.ClientConn, error) @@ -123,6 +126,8 @@ func (d *directMessaging) invokeWithRetry( if err == nil { return resp, nil } + log.Debugf("retry count: %d, grpc call failed, ns: %s, addr: %s, appid: %s, err: %s", + i+1, app.namespace, app.address, app.id, err.Error()) time.Sleep(backoffInterval) code := status.Code(err)