Skip to content

Commit

Permalink
fix: docker-compose.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
liaosunny123 committed Feb 8, 2024
1 parent 4a67c6d commit 8abcea7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .env.docker.compose
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ REDIS_MASTER=
# Config state, if use `disable` the sampler will be closed. use `enable` to enable
TRACING_STATE=enable
# Config tracing sampler, suggest 0.01
TRACING_SAMPLER=0.1
TRACING_SAMPLER=0.01
TRACING_ENDPOINT=jaeger:4318
# Optional: Config Pyroscope
# Decide whether to enable the service, support : enable, disable.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine as builder
FROM golang:1.21-alpine as builder

WORKDIR /build

Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ services:
- '--opentsdbListenAddr=:4242'
- '--httpListenAddr=:8428'
- '--influxListenAddr=:8089'
restart: always
restart: unless-stopped
grafana:
container_name: "GuGoTik-Extra-Grafana"
image: grafana/grafana
Expand All @@ -99,7 +99,7 @@ services:
elasticsearch:
image: elasticsearch:7.17.12
container_name: "GuGoTik-Extra-ElasticSearch"
restart: always
restart: unless-stopped
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
Expand All @@ -119,7 +119,7 @@ services:
kibana:
image: kibana:7.17.12
container_name: "GuGoTik-Extra-Kibana"
restart: always
restart: unless-stopped
environment:
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
I18N_LOCALE: zh-CN
Expand Down
2 changes: 1 addition & 1 deletion src/extra/tracing/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func SetTraceProvider(name string) (*trace.TracerProvider, error) {
if config.EnvCfg.OtelState == "disable" {
sampler = trace.NeverSample()
} else {
sampler = trace.TraceIDRatioBased(config.EnvCfg.OtelSampler)
sampler = GetGuGoTikSampler(config.EnvCfg.OtelSampler)
}

tp := trace.NewTracerProvider(
Expand Down
55 changes: 55 additions & 0 deletions src/extra/tracing/sampler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package tracing

import (
"encoding/binary"
"go.opentelemetry.io/otel/sdk/trace"
trace2 "go.opentelemetry.io/otel/trace"
)

type GuGoTikSampler struct {
traceIDUpperBound uint64
}

func GetGuGoTikSampler(fraction float64) trace.Sampler {
if fraction >= 1 {
return trace.AlwaysSample()
}

if fraction <= 0 {
fraction = 0
}

return &GuGoTikSampler{
traceIDUpperBound: uint64(fraction * (1 << 63)),
}
}

func (cs *GuGoTikSampler) ShouldSample(p trace.SamplingParameters) trace.SamplingResult {
psc := trace2.SpanContextFromContext(p.ParentContext)

for _, attribute := range p.Attributes {
if attribute.Key == "error" {
return trace.SamplingResult{
Decision: trace.RecordAndSample,
Tracestate: psc.TraceState(),
}
}
}

x := binary.BigEndian.Uint64(p.TraceID[8:16]) >> 1
if x < cs.traceIDUpperBound {
return trace.SamplingResult{
Decision: trace.RecordAndSample,
Tracestate: psc.TraceState(),
}
}

return trace.SamplingResult{
Decision: trace.Drop,
Tracestate: psc.TraceState(),
}
}

func (cs *GuGoTikSampler) Description() string {
return "GuGoTikSampler"
}
2 changes: 2 additions & 0 deletions src/utils/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ func LogService(name string) *log.Entry {
func SetSpanError(span trace.Span, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, "Internal Error")
span.SetAttributes(attribute.String("errorMsg", err.Error()))
}

func SetSpanErrorWithDesc(span trace.Span, err error, desc string) {
span.RecordError(err)
span.SetStatus(codes.Error, desc)
span.SetAttributes(attribute.String("error", err.Error()))
}

func SetSpanWithHostname(span trace.Span) {
Expand Down

0 comments on commit 8abcea7

Please sign in to comment.