Skip to content

Commit

Permalink
Merge pull request #127 from ymtdzzz/feature/zipkin-support
Browse files Browse the repository at this point in the history
feat: zipkin support and option to enable it
  • Loading branch information
ymtdzzz authored Aug 11, 2024
2 parents d8e1166 + 7897fbe commit 0e3c257
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 37 deletions.
25 changes: 25 additions & 0 deletions Dockerfile
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" ]
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# otel-tui

A terminal OpenTelemetry viewer inspired by [otel-desktop-viewer](https://github.com/CtrlSpice/otel-desktop-viewer/tree/main)
A terminal OpenTelemetry viewer inspired by [otel-desktop-viewer](https://github.com/CtrlSpice/otel-desktop-viewer/tree/main).

This tool currently supports OpenTelemetry and Zipkin formats.

Traces
![Traces](./docs/traces.png)
Expand All @@ -13,7 +15,25 @@ Logs
![Logs](./docs/logs.png)

## Getting Started
Currently, this tool exposes port 4317 to receive OpenTelemetry signals.
Currently, this tool exposes the ports:
- `4317` to receive OpenTelemetry signals (gRPC)
- `4318` to receive OpenTelemetry signals (HTTP)
- `9411` to receive Zipkin traces (enabled by `--enable-zipkin` option)

Options:

```
Usage:
otel-tui [flags]
Flags:
--enable-zipkin Enable the zipkin receiver
--grpc int The port number on which we listen for OTLP grpc payloads (default 4317)
-h, --help help for otel-tui
--host string The host where we expose our OTLP endpoints (default "0.0.0.0")
--http int The port number on which we listen for OTLP http payloads (default 4318)
-v, --version version for otel-tui
```

### Homebrew

Expand All @@ -37,6 +57,8 @@ $ docker run --rm -dit --name otel-tui ymtdzzz/otel-tui:latest

# Show TUI in your current terminal session
$ docker attach otel-tui

# Detach by pressing Ctrl+p -> Ctrl+q
```

### Docker Compose
Expand All @@ -49,6 +71,8 @@ First, add service to your manifest (`docker-compose.yaml`) for the instrumanted
container_name: otel-tui
stdin_open: true
tty: true
# Override entrypoint if you want use options
entrypoint: ["/otel-tui", "--enable-zipkin"]
```
Modify configuration for otelcol
Expand All @@ -73,6 +97,8 @@ $ docker compose up -d

# Show TUI in your current terminal session
$ docker compose attach oteltui

# Detach by pressing Ctrl+p -> Ctrl+q
```


Expand Down
2 changes: 2 additions & 0 deletions components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions config.go
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
}
34 changes: 34 additions & 0 deletions config.yml.tpl
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
100 changes: 100 additions & 0 deletions config_test.go
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)
}
15 changes: 11 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ require (
)

require (
github.com/apache/thrift v0.20.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
Expand All @@ -43,13 +44,14 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jaegertracing/jaeger v1.59.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
Expand All @@ -58,8 +60,13 @@ require (
github.com/mostynb/go-grpc-compression v1.2.3 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/navidys/tvxwidgets v0.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.106.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.106.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.106.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.106.1 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand Down
Loading

0 comments on commit 0e3c257

Please sign in to comment.