Skip to content

Commit

Permalink
Merge pull request #128 from guoming0000/main
Browse files Browse the repository at this point in the history
fix metadata  set get err
  • Loading branch information
luduoxin authored Sep 1, 2023
2 parents 56a294a + c1016e3 commit 3a4f9f7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/streadway/amqp v1.1.0
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.16.0
github.com/ugorji/go v1.2.7 // indirect
github.com/urfave/cli/v2 v2.25.7
github.com/zserge/lorca v0.1.10
go.mongodb.org/mongo-driver v1.12.1
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1567,9 +1567,11 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v2.4.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
Expand Down
1 change: 1 addition & 0 deletions lib/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type PrometheusPushGateway struct {

// NewPrometheus generates a new set of metrics with a certain subsystem name
func NewPrometheus(subsystem string, customMetricsList ...[]*Metric) *Prometheus {
subsystem = "app"

var metricsList []*Metric

Expand Down
8 changes: 4 additions & 4 deletions utils/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func GetMetaData(ctx context.Context, key string) string {
if md, b := metadata.FromIncomingContext(ctx); b {
vals := md[key]
vals := md.Get(key)
if len(vals) > 0 {
return vals[0]
}
Expand All @@ -21,7 +21,7 @@ func SetMetaData(ctx context.Context, key string, val string) context.Context {
if !b {
md = metadata.MD{}
}
md[key] = []string{val}
md.Set(key, val)
return metadata.NewIncomingContext(ctx, md)
}

Expand All @@ -31,7 +31,7 @@ func SetMetaDataMulti(ctx context.Context, kvs map[string]string) context.Contex
md = metadata.MD{}
}
for k, v := range kvs {
md[k] = []string{v}
md.Set(k, v)
}
return metadata.NewIncomingContext(ctx, md)
}
Expand All @@ -43,7 +43,7 @@ func GetMetaDataMulti(ctx context.Context, keys []string) map[string]string {
}
res := make(map[string]string)
for _, k := range keys {
vals := md[k]
vals := md.Get(k)
if len(vals) > 0 {
res[k] = vals[0]
} else {
Expand Down

0 comments on commit 3a4f9f7

Please sign in to comment.