-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from ymtdzzz/feature/zipkin-support
feat: zipkin support and option to enable it
- Loading branch information
Showing
10 changed files
with
399 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# | ||
# Build | ||
# | ||
FROM golang:1.22 AS builder | ||
|
||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
WORKDIR /build | ||
|
||
COPY . . | ||
|
||
RUN go build -o otel-tui ./... | ||
|
||
# | ||
# Deploy | ||
# | ||
FROM gcr.io/distroless/static-debian12:latest | ||
|
||
WORKDIR / | ||
|
||
COPY --from=builder /build/otel-tui /otel-tui | ||
|
||
USER nonroot | ||
|
||
CMD [ "/otel-tui" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"html/template" | ||
"strings" | ||
) | ||
|
||
//go:embed config.yml.tpl | ||
var configYmlTpl string | ||
|
||
type Config struct { | ||
OTLPHost string | ||
OTLPHTTPPort int | ||
OTLPGRPCPort int | ||
EnableZipkin bool | ||
} | ||
|
||
func (c *Config) RenderYml() (string, error) { | ||
tpl, err := template.New("config").Parse(configYmlTpl) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
params, err := structToMap(c) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var buf strings.Builder | ||
if err := tpl.Execute(&buf, params); err != nil { | ||
return "", err | ||
} | ||
|
||
return buf.String(), nil | ||
} | ||
|
||
func structToMap(s interface{}) (map[string]any, error) { | ||
var result map[string]any | ||
|
||
jsonData, err := json.Marshal(s) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = json.Unmarshal(jsonData, &result) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
yaml: | ||
receivers: | ||
otlp: | ||
protocols: | ||
http: | ||
endpoint: {{ .OTLPHost }}:{{ .OTLPHTTPPort }} | ||
grpc: | ||
endpoint: {{ .OTLPHost }}:{{ .OTLPGRPCPort }} | ||
{{if .EnableZipkin}} zipkin: | ||
endpoint: 0.0.0.0:9411{{end}} | ||
processors: | ||
exporters: | ||
tui: | ||
service: | ||
pipelines: | ||
traces: | ||
receivers: | ||
- otlp | ||
{{if .EnableZipkin}} - zipkin{{end}} | ||
processors: | ||
exporters: | ||
- tui | ||
logs: | ||
receivers: | ||
- otlp | ||
processors: | ||
exporters: | ||
- tui | ||
metrics: | ||
receivers: | ||
- otlp | ||
processors: | ||
exporters: | ||
- tui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfigRenderYml(t *testing.T) { | ||
cfg := &Config{ | ||
OTLPHost: "0.0.0.0", | ||
OTLPHTTPPort: 4318, | ||
OTLPGRPCPort: 4317, | ||
EnableZipkin: true, | ||
} | ||
want := `yaml: | ||
receivers: | ||
otlp: | ||
protocols: | ||
http: | ||
endpoint: 0.0.0.0:4318 | ||
grpc: | ||
endpoint: 0.0.0.0:4317 | ||
zipkin: | ||
endpoint: 0.0.0.0:9411 | ||
processors: | ||
exporters: | ||
tui: | ||
service: | ||
pipelines: | ||
traces: | ||
receivers: | ||
- otlp | ||
- zipkin | ||
processors: | ||
exporters: | ||
- tui | ||
logs: | ||
receivers: | ||
- otlp | ||
processors: | ||
exporters: | ||
- tui | ||
metrics: | ||
receivers: | ||
- otlp | ||
processors: | ||
exporters: | ||
- tui | ||
` | ||
got, err := cfg.RenderYml() | ||
assert.Nil(t, err) | ||
assert.Equal(t, want, got) | ||
} | ||
|
||
func TestConfigRenderYmlZipkinDisabled(t *testing.T) { | ||
cfg := &Config{ | ||
OTLPHost: "0.0.0.0", | ||
OTLPHTTPPort: 4318, | ||
OTLPGRPCPort: 4317, | ||
EnableZipkin: false, | ||
} | ||
want := `yaml: | ||
receivers: | ||
otlp: | ||
protocols: | ||
http: | ||
endpoint: 0.0.0.0:4318 | ||
grpc: | ||
endpoint: 0.0.0.0:4317 | ||
processors: | ||
exporters: | ||
tui: | ||
service: | ||
pipelines: | ||
traces: | ||
receivers: | ||
- otlp | ||
processors: | ||
exporters: | ||
- tui | ||
logs: | ||
receivers: | ||
- otlp | ||
processors: | ||
exporters: | ||
- tui | ||
metrics: | ||
receivers: | ||
- otlp | ||
processors: | ||
exporters: | ||
- tui | ||
` | ||
got, err := cfg.RenderYml() | ||
assert.Nil(t, err) | ||
assert.Equal(t, want, got) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.