Skip to content

Commit

Permalink
Update Go SDK to v1.25.0 (#306)
Browse files Browse the repository at this point in the history
Update Go SDK to v1.25.0
  • Loading branch information
Quinn-With-Two-Ns authored Oct 10, 2023
1 parent 8ffb5fb commit e735bec
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
submodules: recursive
- uses: actions/setup-go@v2
with:
go-version: "1.19"
go-version: "1.21"
- name: CI Build
run: make ci-build
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test:

staticcheck:
@printf $(COLOR) "Run static check..."
@go install honnef.co/go/tools/cmd/staticcheck@2022.1.3
@go install honnef.co/go/tools/cmd/staticcheck@latest
@staticcheck ./...

errcheck:
Expand All @@ -51,4 +51,3 @@ clean:
rm -rf bin

ci-build: staticcheck errcheck workflowcheck bins test
GO111MODULE=off go get -u honnef.co/go/tools/cmd/staticcheck
27 changes: 15 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/temporalio/samples-go

go 1.19
go 1.21

replace github.com/cactus/go-statsd-client => github.com/cactus/go-statsd-client v3.2.1+incompatible

Expand All @@ -12,18 +12,18 @@ require (
github.com/opentracing/opentracing-go v1.2.0
github.com/pborman/uuid v1.2.1
github.com/prometheus/client_golang v1.12.1
github.com/stretchr/testify v1.8.3
github.com/stretchr/testify v1.8.4
github.com/uber-go/tally/v4 v4.1.1
github.com/uber/jaeger-client-go v2.29.1+incompatible
go.temporal.io/api v1.21.0
go.temporal.io/sdk v1.24.0
go.temporal.io/api v1.24.0
go.temporal.io/sdk v1.25.0
go.temporal.io/sdk/contrib/opentracing v0.1.0
go.temporal.io/sdk/contrib/tally v0.2.0
go.temporal.io/sdk/contrib/tools/workflowcheck v0.0.0-20230612164027-11c2cb9e7d2d
go.temporal.io/server v1.15.2
go.uber.org/multierr v1.7.0
go.uber.org/zap v1.20.0
google.golang.org/grpc v1.55.0
google.golang.org/grpc v1.57.0
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -49,6 +49,7 @@ require (
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/hashicorp/go-hclog v1.1.0 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
Expand All @@ -57,7 +58,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/oklog/run v1.1.0 // indirect
Expand Down Expand Up @@ -87,14 +88,16 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/dig v1.13.0 // indirect
go.uber.org/fx v1.16.0 // indirect
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/genproto v0.0.0-20230525154841-bd750badd5c6 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/genproto v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/validator.v2 v2.0.0-20210331031555-b37d688a7fb0 // indirect
)
283 changes: 269 additions & 14 deletions go.sum

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions slogadapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Steps to run this sample:
1) Run a [Temporal service](https://github.com/temporalio/samples-go/tree/main/#how-to-use).
2) Run the following command to start the worker
```
go run slogadapter/worker/main.go
```
3) Run the following command to start the example
```
go run slogadapter/starter/main.go
```
4) Check worker logs in colorful JSON format:
```json
{"time":"2023-10-06T14:16:30.511716-07:00","level":"INFO","source":{"function":"go.temporal.io/sdk/internal.(*AggregatedWorker).Start","file":"/Users/user/go/pkg/mod/go.temporal.io/[email protected]/internal/internal_worker.go","line":987},"msg":"Started Worker","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@"}
{"time":"2023-10-06T14:16:32.679875-07:00","level":"INFO","source":{"function":"github.com/temporalio/samples-go/slogadapter.Workflow","file":"/Users/user/Documents/Code/samples-go/slogadapter/workflow.go","line":22},"msg":"Logging from workflow","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@","WorkflowType":"Workflow","WorkflowID":"slog_logger_workflow_id","RunID":"7666eddc-a124-445a-a085-2fd0e9a719e3","Attempt":1,"name":"<param to log>"}
{"time":"2023-10-06T14:16:32.67998-07:00","level":"DEBUG","source":{"function":"go.temporal.io/sdk/internal.(*workflowEnvironmentImpl).ExecuteActivity","file":"/Users/user/go/pkg/mod/go.temporal.io/[email protected]/internal/internal_event_handlers.go","line":676},"msg":"ExecuteActivity","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@","WorkflowType":"Workflow","WorkflowID":"slog_logger_workflow_id","RunID":"7666eddc-a124-445a-a085-2fd0e9a719e3","Attempt":1,"ActivityID":"5","ActivityType":"LoggingActivity"}
{"time":"2023-10-06T14:16:32.689103-07:00","level":"INFO","source":{"function":"github.com/temporalio/samples-go/slogadapter.LoggingActivity","file":"/Users/user/Documents/Code/samples-go/slogadapter/workflow.go","line":45},"msg":"Executing LoggingActivity.","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@","ActivityID":"5","ActivityType":"LoggingActivity","Attempt":1,"WorkflowType":"Workflow","WorkflowID":"slog_logger_workflow_id","RunID":"7666eddc-a124-445a-a085-2fd0e9a719e3","activity":"LoggingActivity","name":"<param to log>"}
{"time":"2023-10-06T14:16:32.689144-07:00","level":"DEBUG","source":{"function":"github.com/temporalio/samples-go/slogadapter.LoggingActivity","file":"/Users/user/Documents/Code/samples-go/slogadapter/workflow.go","line":46},"msg":"Debugging LoggingActivity.","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@","ActivityID":"5","ActivityType":"LoggingActivity","Attempt":1,"WorkflowType":"Workflow","WorkflowID":"slog_logger_workflow_id","RunID":"7666eddc-a124-445a-a085-2fd0e9a719e3","activity":"LoggingActivity","value":"important debug data"}
{"time":"2023-10-06T14:16:32.703167-07:00","level":"DEBUG","source":{"function":"go.temporal.io/sdk/internal.(*workflowEnvironmentImpl).ExecuteActivity","file":"/Users/user/go/pkg/mod/go.temporal.io/[email protected]/internal/internal_event_handlers.go","line":676},"msg":"ExecuteActivity","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@","WorkflowType":"Workflow","WorkflowID":"slog_logger_workflow_id","RunID":"7666eddc-a124-445a-a085-2fd0e9a719e3","Attempt":1,"ActivityID":"11","ActivityType":"LoggingErrorAcctivity"}
{"time":"2023-10-06T14:16:32.70982-07:00","level":"WARN","source":{"function":"github.com/temporalio/samples-go/slogadapter.LoggingErrorAcctivity","file":"/Users/user/Documents/Code/samples-go/slogadapter/workflow.go","line":52},"msg":"Ignore next error message. It is just for demo purpose.","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@","ActivityID":"11","ActivityType":"LoggingErrorAcctivity","Attempt":1,"WorkflowType":"Workflow","WorkflowID":"slog_logger_workflow_id","RunID":"7666eddc-a124-445a-a085-2fd0e9a719e3"}
{"time":"2023-10-06T14:16:32.709847-07:00","level":"ERROR","source":{"function":"github.com/temporalio/samples-go/slogadapter.LoggingErrorAcctivity","file":"/Users/user/Documents/Code/samples-go/slogadapter/workflow.go","line":53},"msg":"Unable to execute LoggingErrorAcctivity.","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@","ActivityID":"11","ActivityType":"LoggingErrorAcctivity","Attempt":1,"WorkflowType":"Workflow","WorkflowID":"slog_logger_workflow_id","RunID":"7666eddc-a124-445a-a085-2fd0e9a719e3","error":"random error"}
{"time":"2023-10-06T14:16:32.720006-07:00","level":"INFO","source":{"function":"github.com/temporalio/samples-go/slogadapter.Workflow","file":"/Users/user/Documents/Code/samples-go/slogadapter/workflow.go","line":37},"msg":"Workflow completed.","Namespace":"default","TaskQueue":"slog-logger","WorkerID":"11177@worker@","WorkflowType":"Workflow","WorkflowID":"slog_logger_workflow_id","RunID":"7666eddc-a124-445a-a085-2fd0e9a719e3","Attempt":1}
```
38 changes: 38 additions & 0 deletions slogadapter/starter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"context"
"log"

"github.com/temporalio/samples-go/slogadapter"
"go.temporal.io/sdk/client"
)

func main() {
// The client is a heavyweight object that should be created once per process.
c, err := client.Dial(client.Options{})
if err != nil {
log.Fatalln("Unable to create client", err)
}
defer c.Close()

workflowOptions := client.StartWorkflowOptions{
ID: "slog_logger_workflow_id",
TaskQueue: "slog-logger",
}

we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, slogadapter.Workflow, "<param to log>")
if err != nil {
log.Fatalln("Unable to execute workflow", err)
}

log.Println("Started workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID())

// Synchronously wait for the workflow completion.
var result interface{}
err = we.Get(context.Background(), &result)
if err != nil {
log.Fatalln("Unable get workflow result", err)
}
log.Println("Workflow completed. Check worker logs.")
}
38 changes: 38 additions & 0 deletions slogadapter/worker/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"log"
"os"

"log/slog"

"github.com/temporalio/samples-go/slogadapter"
"go.temporal.io/sdk/client"
tlog "go.temporal.io/sdk/log"
"go.temporal.io/sdk/worker"
)

func main() {
c, err := client.Dial(client.Options{
Logger: tlog.NewStructuredLogger(
slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
AddSource: true,
Level: slog.LevelDebug,
}))),
})
if err != nil {
log.Fatalln("Unable to create client", err)
}
defer c.Close()

w := worker.New(c, "slog-logger", worker.Options{})

w.RegisterWorkflow(slogadapter.Workflow)
w.RegisterActivity(slogadapter.LoggingActivity)
w.RegisterActivity(slogadapter.LoggingErrorAcctivity)

err = w.Run(worker.InterruptCh())
if err != nil {
log.Fatalln("Unable to start worker", err)
}
}
55 changes: 55 additions & 0 deletions slogadapter/workflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package slogadapter

import (
"context"
"errors"
"time"

"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/log"
"go.temporal.io/sdk/workflow"
)

// Workflow is a workflow function which does some logging.
// Important note: workflow logger is replay aware and it won't log during replay.
func Workflow(ctx workflow.Context, name string) error {
ao := workflow.ActivityOptions{
StartToCloseTimeout: 10 * time.Second,
}
ctx = workflow.WithActivityOptions(ctx, ao)

logger := workflow.GetLogger(ctx)
logger.Info("Logging from workflow", "name", name)

var result interface{}
err := workflow.ExecuteActivity(ctx, LoggingActivity, name).Get(ctx, &result)
if err != nil {
logger.Error("LoggingActivity failed.", "Error", err)
return err
}

err = workflow.ExecuteActivity(ctx, LoggingErrorAcctivity).Get(ctx, &result)
if err != nil {
logger.Error("LoggingActivity failed.", "Error", err)
return err
}

logger.Info("Workflow completed.")
return nil
}

func LoggingActivity(ctx context.Context, name string) error {
logger := activity.GetLogger(ctx)
withLogger := logger.(log.WithLogger).With("activity", "LoggingActivity")

withLogger.Info("Executing LoggingActivity.", "name", name)
withLogger.Debug("Debugging LoggingActivity.", "value", "important debug data")
return nil
}

func LoggingErrorAcctivity(ctx context.Context) error {
logger := activity.GetLogger(ctx)
logger.Warn("Ignore next error message. It is just for demo purpose.")
logger.Error("Unable to execute LoggingErrorAcctivity.", "error", errors.New("random error"))
return nil
}
6 changes: 3 additions & 3 deletions temporal-fixtures/largepayload/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package largepayload

import (
"context"
"math/rand"
"crypto/rand"

"go.temporal.io/sdk/activity"
)
Expand All @@ -19,8 +19,8 @@ func (a *Activities) CreateLargeResultActivity(ctx context.Context, sizeBytes in
logger.Info("Creating large result payload...", sizeBytes)

token := make([]byte, sizeBytes)
rand.Read(token)
return token, nil
_, err := rand.Read(token)
return token, err
}

func (a *Activities) ProcessLargeInputActivity(ctx context.Context, input []byte) error {
Expand Down
4 changes: 2 additions & 2 deletions temporal-fixtures/largepayload/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"context"
"crypto/rand"
"log"
"math/rand"
"strconv"

"github.com/pborman/uuid"
Expand All @@ -29,7 +29,7 @@ func main() {
id := uuid.New()[0:4]

memoToken := make([]byte, PayloadSize)
rand.Read(memoToken)
_, _ = rand.Read(memoToken)

i := 1
for i <= NumberOfWorkflows {
Expand Down
4 changes: 4 additions & 0 deletions zapadapter/zap_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ func (log *ZapAdapter) Error(msg string, keyvals ...interface{}) {
func (log *ZapAdapter) With(keyvals ...interface{}) log.Logger {
return &ZapAdapter{zl: log.zl.With(log.fields(keyvals)...)}
}

func (log *ZapAdapter) WithCallerSkip(skip int) log.Logger {
return &ZapAdapter{zl: log.zl.WithOptions(zap.AddCallerSkip(skip))}
}

0 comments on commit e735bec

Please sign in to comment.