Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Logrus with Zap for logging #136

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17 as build
FROM golang:1.20 as build
RUN mkdir /package
COPY /internal /package/internal
COPY /sdk /package/sdk
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
module github.com/conductor-sdk/conductor-go

go 1.17
go 1.20

require (
github.com/antihax/optional v1.0.0
github.com/google/uuid v1.3.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.12.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.4.0
github.com/prometheus/client_golang v0.9.2
github.com/stretchr/testify v1.8.1
go.uber.org/zap v1.27.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/sys v0.6.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
467 changes: 26 additions & 441 deletions go.sum

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions internal/testdata/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ package testdata
import (
"context"
"fmt"

"os"
"reflect"
"time"

"github.com/conductor-sdk/conductor-go/sdk/authentication"
"github.com/conductor-sdk/conductor-go/sdk/client"
"github.com/conductor-sdk/conductor-go/sdk/log"
"github.com/conductor-sdk/conductor-go/sdk/model"
"github.com/conductor-sdk/conductor-go/sdk/settings"
"github.com/conductor-sdk/conductor-go/sdk/worker"
"github.com/conductor-sdk/conductor-go/sdk/workflow"
"github.com/conductor-sdk/conductor-go/sdk/workflow/executor"

log "github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -59,12 +59,6 @@ var TaskRunner = worker.NewTaskRunnerWithApiClient(apiClient)

var WorkflowExecutor = executor.NewWorkflowExecutor(apiClient)

func init() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.ErrorLevel)
}

func ValidateWorkflowDaemon(waitTime time.Duration, outputChannel chan error, workflowId string, expectedOutput map[string]interface{}, expectedStatus model.WorkflowStatus) {
time.Sleep(waitTime)
workflow, _, err := WorkflowClient.GetExecutionStatus(
Expand Down
8 changes: 0 additions & 8 deletions internal/testdata/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ package testdata

import (
"fmt"
"os"
"testing"
"time"

"github.com/conductor-sdk/conductor-go/sdk/model"
log "github.com/sirupsen/logrus"
)

const (
Expand All @@ -30,12 +28,6 @@ const (
WorkerPollInterval = 250 * time.Millisecond
)

func init() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.ErrorLevel)
}

func ExampleWorker(t *model.Task) (interface{}, error) {
taskResult := model.NewTaskResultFromTask(t)
taskResult.OutputData = map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion sdk/authentication/token_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"encoding/xml"
"errors"
"fmt"
"github.com/conductor-sdk/conductor-go/sdk/log"
"io"
"mime/multipart"
"net/http"
Expand All @@ -29,7 +30,6 @@ import (

"github.com/conductor-sdk/conductor-go/sdk/model"
"github.com/conductor-sdk/conductor-go/sdk/settings"
log "github.com/sirupsen/logrus"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion sdk/authentication/token_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
package authentication

import (
"github.com/conductor-sdk/conductor-go/sdk/log"
"net/http"
"sync"

"github.com/conductor-sdk/conductor-go/sdk/settings"
"github.com/patrickmn/go-cache"
log "github.com/sirupsen/logrus"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions sdk/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"encoding/xml"
"errors"
"fmt"
"github.com/conductor-sdk/conductor-go/sdk/log"
"io"
"mime/multipart"
"net"
Expand All @@ -31,7 +32,6 @@ import (

"github.com/conductor-sdk/conductor-go/sdk/authentication"
"github.com/conductor-sdk/conductor-go/sdk/settings"
"github.com/sirupsen/logrus"
)

var (
Expand Down Expand Up @@ -293,7 +293,7 @@ func getDecompressedBody(response *http.Response) ([]byte, error) {
case "gzip":
reader, err = gzip.NewReader(response.Body)
if err != nil {
logrus.Error("Unable to decompress the response ", err.Error())
log.Error("Unable to decompress the response ", err.Error())
if err == io.EOF {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/concurrency/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
package concurrency

import (
"github.com/conductor-sdk/conductor-go/sdk/log"
"github.com/conductor-sdk/conductor-go/sdk/metrics"
log "github.com/sirupsen/logrus"
"runtime/debug"
)

Expand Down
29 changes: 29 additions & 0 deletions sdk/log/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package log

import "go.uber.org/zap"

var (
sugar *zap.SugaredLogger
)

func init() {
logger, _ := zap.NewProduction()
defer logger.Sync() // flushes buffer, if any
sugar = logger.Sugar()

}
func Info(args ...interface{}) {
sugar.Info(args)
}
func Debug(args ...interface{}) {
sugar.Debug(args)
}
func Trace(args ...interface{}) {
//sugar.Debug(args)
}
func Error(args ...interface{}) {
sugar.Error(args)
}
func Warning(args ...interface{}) {
sugar.Warn(args)
}
8 changes: 3 additions & 5 deletions sdk/metrics/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
package metrics

import (
log "github.com/conductor-sdk/conductor-go/sdk/log"
"net/http"
"strconv"

"github.com/conductor-sdk/conductor-go/sdk/settings"
log "github.com/sirupsen/logrus"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -40,14 +40,12 @@ func ProvideMetrics(metricsSettings *settings.MetricsSettings) {
prometheus.MustRegister(gaugeByName[metricName])
}
collectionEnabled = true

http.Handle(
metricsSettings.ApiEndpoint,
promhttp.HandlerFor(
prometheus.DefaultGatherer,
promhttp.HandlerOpts{
EnableOpenMetrics: true,
},
promhttp.HandlerOpts{},
),
)
portString := strconv.Itoa(metricsSettings.Port)
Expand Down
3 changes: 1 addition & 2 deletions sdk/model/task_execute_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ package model

import (
"encoding/json"
"github.com/conductor-sdk/conductor-go/sdk/log"
"os"
"sync"

log "github.com/sirupsen/logrus"
)

var hostname string
Expand Down
2 changes: 1 addition & 1 deletion sdk/worker/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/conductor-sdk/conductor-go/sdk/settings"

"github.com/antihax/optional"
log "github.com/sirupsen/logrus"
log "github.com/conductor-sdk/conductor-go/sdk/log"
)

const taskUpdateRetryAttemptsLimit = 3
Expand Down
3 changes: 1 addition & 2 deletions sdk/workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"context"
"errors"
"fmt"
"github.com/conductor-sdk/conductor-go/sdk/log"
"net/http"
"os"
"strconv"
Expand All @@ -25,8 +26,6 @@ import (
"github.com/conductor-sdk/conductor-go/sdk/concurrency"
"github.com/conductor-sdk/conductor-go/sdk/event/queue"
"github.com/conductor-sdk/conductor-go/sdk/model"

log "github.com/sirupsen/logrus"
)

type WorkflowExecutor struct {
Expand Down
3 changes: 1 addition & 2 deletions sdk/workflow/executor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import (
"context"
"fmt"
"github.com/antihax/optional"
"github.com/conductor-sdk/conductor-go/sdk/log"
"sync"
"time"

"github.com/conductor-sdk/conductor-go/sdk/client"
"github.com/conductor-sdk/conductor-go/sdk/concurrency"
"github.com/conductor-sdk/conductor-go/sdk/model"

log "github.com/sirupsen/logrus"
)

type WorkflowMonitor struct {
Expand Down
2 changes: 1 addition & 1 deletion sdk/workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ package workflow

import (
"encoding/json"
"github.com/conductor-sdk/conductor-go/sdk/log"

"github.com/conductor-sdk/conductor-go/sdk/model"
"github.com/conductor-sdk/conductor-go/sdk/workflow/executor"
log "github.com/sirupsen/logrus"
)

type TimeoutPolicy string
Expand Down
5 changes: 2 additions & 3 deletions test/integration_tests/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/conductor-sdk/conductor-go/sdk/model"
"github.com/conductor-sdk/conductor-go/sdk/workflow"
"github.com/conductor-sdk/conductor-go/test/common"
"github.com/sirupsen/logrus"
)

func TestWorkerBatchSize(t *testing.T) {
Expand Down Expand Up @@ -71,7 +70,7 @@ func TestWorkerBatchSize(t *testing.T) {
}

func TestFaultyWorker(t *testing.T) {
logrus.SetLevel(logrus.ErrorLevel)

taskName := "TEST_GO_FAULTY_TASK"
wf := workflow.NewConductorWorkflow(testdata.WorkflowExecutor).
Name("TEST_GO_FAULTY_WORKFLOW").
Expand All @@ -97,7 +96,7 @@ func TestFaultyWorker(t *testing.T) {
}

func TestWorkerWithNonRetryableError(t *testing.T) {
logrus.SetLevel(logrus.ErrorLevel)

taskName := "TEST_GO_NON_RETRYABLE_ERROR_TASK"
wf := workflow.NewConductorWorkflow(testdata.WorkflowExecutor).
Name("TEST_GO_NON_RETRYABLE_ERROR_WF").
Expand Down
9 changes: 1 addition & 8 deletions test/integration_tests/workflow_def_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,16 @@ package integration_tests
import (
"context"
"fmt"
"os"
"testing"

"github.com/conductor-sdk/conductor-go/internal/testdata"
"github.com/conductor-sdk/conductor-go/sdk/model"
"github.com/conductor-sdk/conductor-go/sdk/workflow"
"github.com/conductor-sdk/conductor-go/test/common"
log "github.com/sirupsen/logrus"

"github.com/stretchr/testify/assert"
)

func init() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.ErrorLevel)
}

func TestHttpTask(t *testing.T) {
httpTaskWorkflow := workflow.NewConductorWorkflow(testdata.WorkflowExecutor).
Name("TEST_GO_WORKFLOW_HTTP").
Expand Down