Skip to content

Commit

Permalink
Merge branch 'main' into repo-cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Nguyen <[email protected]>
  • Loading branch information
mikeee authored Jul 1, 2024
2 parents 3702dd4 + c417f95 commit 8afc3e0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-chi/chi/v5 v5.0.12
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/microsoft/durabletask-go v0.4.1-0.20240503173355-60e42f2bb250
github.com/microsoft/durabletask-go v0.4.1-0.20240621011625-bfcc3331ca58
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.62.0
google.golang.org/protobuf v1.33.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/marusama/semaphore/v2 v2.5.0 h1:o/1QJD9DBYOWRnDhPwDVAXQn6mQYD0gZaS1Tpx6DJGM=
github.com/marusama/semaphore/v2 v2.5.0/go.mod h1:z9nMiNUekt/LTpTUQdpp+4sJeYqUGpwMHfW0Z8V8fnQ=
github.com/microsoft/durabletask-go v0.4.1-0.20240503173355-60e42f2bb250 h1:VlEXgoRZM5eb64n5/PfBOEEqfIf5D22sCVdUrptfGZ8=
github.com/microsoft/durabletask-go v0.4.1-0.20240503173355-60e42f2bb250/go.mod h1:goe2gmMgLptCijMDQ7JsekaR86KjPUG64V9JDXvKBhE=
github.com/microsoft/durabletask-go v0.4.1-0.20240621011625-bfcc3331ca58 h1:+HZ6RzZz6YBfA+Chtn0SnMU2OgY6nafl2sGbZ9FmerY=
github.com/microsoft/durabletask-go v0.4.1-0.20240621011625-bfcc3331ca58/go.mod h1:goe2gmMgLptCijMDQ7JsekaR86KjPUG64V9JDXvKBhE=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
Expand Down
22 changes: 18 additions & 4 deletions service/http/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const (

// PubSubHandlerDropStatusCode is the pubsub event appcallback response code indicating that Dapr should drop that message.
PubSubHandlerDropStatusCode int = http.StatusSeeOther

// HealthzRoute Health check default route used by the server
HealthzRoute = "healthz"
)

// topicEventJSON is identical to `common.TopicEvent`
Expand Down Expand Up @@ -129,11 +132,22 @@ func (s *Server) registerBaseHandler() {
}
s.mux.HandleFunc("/dapr/subscribe", f)

// register health check handler
fHealth := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
// check if the healthz route is already registered by the user to avoid overwriting it
hasHealthz := false
for _, route := range s.mux.Routes() {
if route.Pattern == "/"+HealthzRoute || route.Pattern == HealthzRoute {
hasHealthz = true
break
}
}

if !hasHealthz {
// register health check handler
fHealth := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
s.mux.Get("/"+HealthzRoute, fHealth)
}
s.mux.Get("/healthz", fHealth)

// register actor config handler
fRegister := func(w http.ResponseWriter, r *http.Request) {
Expand Down
42 changes: 42 additions & 0 deletions service/http/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,48 @@ func TestHealthCheck(t *testing.T) {
makeRequest(t, s, "/healthz", "", http.MethodGet, http.StatusOK)
}

func TestCustomHealthCheck(t *testing.T) {
s := newServer("", nil)
err := s.AddHealthCheckHandler("/healthz", func(ctx context.Context) error {
return nil
})
require.NoErrorf(t, err, "error adding custom health check handler")
s.registerBaseHandler()
makeRequest(t, s, "/healthz", "", http.MethodGet, http.StatusNoContent)
}

func TestCustomHealthCheckWithoutLeadingSlash(t *testing.T) {
s := newServer("", nil)
err := s.AddHealthCheckHandler("healthz", func(ctx context.Context) error {
return nil
})
require.NoErrorf(t, err, "error adding custom health check handler")
s.registerBaseHandler()
makeRequest(t, s, "/healthz", "", http.MethodGet, http.StatusNoContent)
}

func TestCustomRouteHealthCheck(t *testing.T) {
s := newServer("", nil)
err := s.AddHealthCheckHandler("custom-health-check", func(ctx context.Context) error {
return nil
})
require.NoErrorf(t, err, "error adding custom health check handler")
s.registerBaseHandler()
makeRequest(t, s, "/custom-health-check", "", http.MethodGet, http.StatusNoContent)
makeRequest(t, s, "/healthz", "", http.MethodGet, http.StatusOK)
}

func TestCustomHealthCheckError(t *testing.T) {
s := newServer("", nil)
err := s.AddHealthCheckHandler("custom-health-check", func(ctx context.Context) error {
return errors.New("not feeling well, will take day off")
})
require.NoErrorf(t, err, "error adding custom health check handler")
s.registerBaseHandler()
makeRequest(t, s, "/custom-health-check", "", http.MethodGet, http.StatusInternalServerError)
makeRequest(t, s, "/healthz", "", http.MethodGet, http.StatusOK)
}

func TestActorConfig(t *testing.T) {
s := newServer("", nil)
s.registerBaseHandler()
Expand Down
9 changes: 9 additions & 0 deletions workflow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (c *client) FetchWorkflowMetadata(ctx context.Context, id string, opts ...a
return nil, errors.New("no workflow id specified")
}
wfMetadata, err := c.taskHubClient.FetchOrchestrationMetadata(ctx, api.InstanceID(id), opts...)
if err != nil {
return nil, err
}

return convertMetadata(wfMetadata), err
}
Expand All @@ -145,6 +148,9 @@ func (c *client) WaitForWorkflowStart(ctx context.Context, id string, opts ...ap
return nil, errors.New("no workflow id specified")
}
wfMetadata, err := c.taskHubClient.WaitForOrchestrationStart(ctx, api.InstanceID(id), opts...)
if err != nil {
return nil, err
}

return convertMetadata(wfMetadata), err
}
Expand All @@ -155,6 +161,9 @@ func (c *client) WaitForWorkflowCompletion(ctx context.Context, id string, opts
return nil, errors.New("no workflow id specified")
}
wfMetadata, err := c.taskHubClient.WaitForOrchestrationCompletion(ctx, api.InstanceID(id), opts...)
if err != nil {
return nil, err
}

return convertMetadata(wfMetadata), err
}
Expand Down

0 comments on commit 8afc3e0

Please sign in to comment.