Skip to content

Commit

Permalink
feat: support baggage propagation in httpc (zeromicro#2375)
Browse files Browse the repository at this point in the history
* feat: support baggage propagation in httpc

* chore: use go 1.16

* chore: use go 1.16

* chore: use go ^1.16

* chore: remove deprecated
  • Loading branch information
kevwan authored Sep 10, 2022
1 parent 590d784 commit d935c83
Show file tree
Hide file tree
Showing 44 changed files with 141 additions and 154 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
go-version: ^1.16
id: go

- name: Check out code into the Go module directory
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
go-version: ^1.16

- name: Checkout codebase
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions core/codec/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/base64"
"encoding/pem"
"errors"
"io/ioutil"
"os"
)

var (
Expand Down Expand Up @@ -48,7 +48,7 @@ type (

// NewRsaDecrypter returns a RsaDecrypter with the given file.
func NewRsaDecrypter(file string) (RsaDecrypter, error) {
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions core/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package conf

import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
Expand All @@ -20,7 +19,7 @@ var loaders = map[string]func([]byte, interface{}) error{

// Load loads config into v from file, .json, .yaml and .yml are acceptable.
func Load(file string, v interface{}, opts ...Option) error {
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions core/conf/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package conf

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -146,12 +145,12 @@ func TestConfigJsonEnv(t *testing.T) {
}

func createTempFile(ext, text string) (string, error) {
tmpfile, err := ioutil.TempFile(os.TempDir(), hash.Md5Hex([]byte(text))+"*"+ext)
tmpfile, err := os.CreateTemp(os.TempDir(), hash.Md5Hex([]byte(text))+"*"+ext)
if err != nil {
return "", err
}

if err := ioutil.WriteFile(tmpfile.Name(), []byte(text), os.ModeTemporary); err != nil {
if err := os.WriteFile(tmpfile.Name(), []byte(text), os.ModeTemporary); err != nil {
return "", err
}

Expand Down
4 changes: 2 additions & 2 deletions core/discov/internal/accountmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package internal
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"os"
"sync"
)

Expand Down Expand Up @@ -37,7 +37,7 @@ func AddTLS(endpoints []string, certFile, certKeyFile, caFile string, insecureSk
return err
}

caData, err := ioutil.ReadFile(caFile)
caData, err := os.ReadFile(caFile)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions core/fs/temps.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fs

import (
"io/ioutil"
"os"

"github.com/zeromicro/go-zero/core/hash"
Expand All @@ -12,12 +11,12 @@ import (
// The file is kept as open, the caller should close the file handle,
// and remove the file by name.
func TempFileWithText(text string) (*os.File, error) {
tmpfile, err := ioutil.TempFile(os.TempDir(), hash.Md5Hex([]byte(text)))
tmpfile, err := os.CreateTemp(os.TempDir(), hash.Md5Hex([]byte(text)))
if err != nil {
return nil, err
}

if err := ioutil.WriteFile(tmpfile.Name(), []byte(text), os.ModeTemporary); err != nil {
if err := os.WriteFile(tmpfile.Name(), []byte(text), os.ModeTemporary); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions core/fs/temps_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fs

import (
"io/ioutil"
"io"
"os"
"testing"

Expand All @@ -21,7 +21,7 @@ func TestTempFileWithText(t *testing.T) {
}
defer os.Remove(f.Name())

bs, err := ioutil.ReadAll(f)
bs, err := io.ReadAll(f)
assert.Nil(t, err)
if len(bs) != 4 {
t.Error("TempFileWithText returned wrong file size")
Expand All @@ -41,7 +41,7 @@ func TestTempFilenameWithText(t *testing.T) {
}
defer os.Remove(f)

bs, err := ioutil.ReadFile(f)
bs, err := os.ReadFile(f)
assert.Nil(t, err)
if len(bs) != 4 {
t.Error("TempFilenameWithText returned wrong file size")
Expand Down
4 changes: 2 additions & 2 deletions core/fx/stream_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fx

import (
"io/ioutil"
"io"
"log"
"math/rand"
"reflect"
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestLast(t *testing.T) {

func TestMap(t *testing.T) {
runCheckedTest(t, func(t *testing.T) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)

tests := []struct {
mapper MapFunc
Expand Down
5 changes: 2 additions & 3 deletions core/iox/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"io"
"io/ioutil"
"os"
"strings"
)
Expand All @@ -26,7 +25,7 @@ type (
func DupReadCloser(reader io.ReadCloser) (io.ReadCloser, io.ReadCloser) {
var buf bytes.Buffer
tee := io.TeeReader(reader, &buf)
return ioutil.NopCloser(tee), ioutil.NopCloser(&buf)
return io.NopCloser(tee), io.NopCloser(&buf)
}

// KeepSpace customizes the reading functions to keep leading and tailing spaces.
Expand Down Expand Up @@ -54,7 +53,7 @@ func ReadBytes(reader io.Reader, buf []byte) error {

// ReadText reads content from the given file with leading and tailing spaces trimmed.
func ReadText(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand Down
9 changes: 4 additions & 5 deletions core/iox/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package iox
import (
"bytes"
"io"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -97,10 +96,10 @@ func TestReadTextLines(t *testing.T) {

func TestDupReadCloser(t *testing.T) {
input := "hello"
reader := ioutil.NopCloser(bytes.NewBufferString(input))
reader := io.NopCloser(bytes.NewBufferString(input))
r1, r2 := DupReadCloser(reader)
verify := func(r io.Reader) {
output, err := ioutil.ReadAll(r)
output, err := io.ReadAll(r)
assert.Nil(t, err)
assert.Equal(t, input, string(output))
}
Expand All @@ -110,15 +109,15 @@ func TestDupReadCloser(t *testing.T) {
}

func TestReadBytes(t *testing.T) {
reader := ioutil.NopCloser(bytes.NewBufferString("helloworld"))
reader := io.NopCloser(bytes.NewBufferString("helloworld"))
buf := make([]byte, 5)
err := ReadBytes(reader, buf)
assert.Nil(t, err)
assert.Equal(t, "hello", string(buf))
}

func TestReadBytesNotEnough(t *testing.T) {
reader := ioutil.NopCloser(bytes.NewBufferString("hell"))
reader := io.NopCloser(bytes.NewBufferString("hell"))
buf := make([]byte, 5)
err := ReadBytes(reader, buf)
assert.Equal(t, io.EOF, err)
Expand Down
3 changes: 1 addition & 2 deletions core/iox/textfile_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package iox

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -13,7 +12,7 @@ func TestCountLines(t *testing.T) {
2
3
4`
file, err := ioutil.TempFile(os.TempDir(), "test-")
file, err := os.CreateTemp(os.TempDir(), "test-")
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions core/logx/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"reflect"
Expand Down Expand Up @@ -649,7 +649,7 @@ func BenchmarkCopyByteSlice(b *testing.B) {
buf = make([]byte, len(s))
copy(buf, s)
}
fmt.Fprint(ioutil.Discard, buf)
fmt.Fprint(io.Discard, buf)
}

func BenchmarkCopyOnWriteByteSlice(b *testing.B) {
Expand All @@ -658,7 +658,7 @@ func BenchmarkCopyOnWriteByteSlice(b *testing.B) {
size := len(s)
buf = s[:size:size]
}
fmt.Fprint(ioutil.Discard, buf)
fmt.Fprint(io.Discard, buf)
}

func BenchmarkCacheByteSlice(b *testing.B) {
Expand All @@ -672,7 +672,7 @@ func BenchmarkCacheByteSlice(b *testing.B) {
func BenchmarkLogs(b *testing.B) {
b.ReportAllocs()

log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
for i := 0; i < b.N; i++ {
Info(i)
}
Expand Down
4 changes: 2 additions & 2 deletions core/mr/mapreduce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mr
import (
"context"
"errors"
"io/ioutil"
"io"
"log"
"runtime"
"sync/atomic"
Expand All @@ -17,7 +17,7 @@ import (
var errDummy = errors.New("dummy")

func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}

func TestFinish(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/stores/mongoc/cachedcollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mongoc
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"log"
"os"
"runtime"
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestStat(t *testing.T) {

func TestStatCacheFails(t *testing.T) {
resetStats()
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
defer log.SetOutput(os.Stdout)

r := redis.New("localhost:59999")
Expand Down
4 changes: 2 additions & 2 deletions core/stores/sqlc/cachedsql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"runtime"
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestCachedConn_QueryRowIndex_HasWrongCache(t *testing.T) {

func TestStatCacheFails(t *testing.T) {
resetStats()
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
defer log.SetOutput(os.Stdout)

r := redis.New("localhost:59999")
Expand Down
4 changes: 2 additions & 2 deletions core/threading/routinegroup_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package threading

import (
"io/ioutil"
"io"
"log"
"sync"
"sync/atomic"
Expand All @@ -25,7 +25,7 @@ func TestRoutineGroupRun(t *testing.T) {
}

func TestRoutingGroupRunSafe(t *testing.T) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)

var count int32
group := NewRoutineGroup()
Expand Down
4 changes: 2 additions & 2 deletions core/threading/routines_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package threading

import (
"io/ioutil"
"io"
"log"
"testing"

Expand All @@ -14,7 +14,7 @@ func TestRoutineId(t *testing.T) {
}

func TestRunSafe(t *testing.T) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)

i := 0

Expand Down
5 changes: 1 addition & 4 deletions core/trace/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/exporters/zipkin"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
Expand Down Expand Up @@ -66,7 +65,7 @@ func startAgent(c Config) error {
opts := []sdktrace.TracerProviderOption{
// Set the sampling rate based on the parent span to 100%
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(c.Sampler))),
// Record information about this application in an Resource.
// Record information about this application in a Resource.
sdktrace.WithResource(resource.NewSchemaless(semconv.ServiceNameKey.String(c.Name))),
}

Expand All @@ -83,8 +82,6 @@ func startAgent(c Config) error {

tp = sdktrace.NewTracerProvider(opts...)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{}, propagation.Baggage{}))
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {
logx.Errorf("[otel] error: %v", err)
}))
Expand Down
Loading

0 comments on commit d935c83

Please sign in to comment.