Skip to content

Commit

Permalink
Merge pull request krzko#125 from krzko/feat-add-additional-usecases
Browse files Browse the repository at this point in the history
feat: update many things
  • Loading branch information
krzko authored Sep 29, 2024
2 parents 47738d7 + 04cdba8 commit 622cf2a
Show file tree
Hide file tree
Showing 33 changed files with 2,323 additions and 842 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build

on:
workflow_dispatch:
push:
branches:
- "*"
- "!main"
paths-ignore:
- "**/.md"

env:
REGISTRY_IMAGE: ghcr.io/krzko/otelgen

jobs:
build:
permissions:
contents: read
packages: write
attestations: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build only
run: |
docker buildx build \
--platform linux/amd64 \
-t ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} \
.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Lint
on:
push:
tags:
- v*
# tags:
# - v*
branches:
- main
pull_request:
- foo
# pull_request:
permissions:
contents: read

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Custom ###

/build
/otelgen

# goreleaser
Expand Down
7 changes: 6 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ dockers:
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --platform=linux/amd64
- --build-arg=BUILD_VERSION={{ .Version }}
- --build-arg=BUILD_DATE={{ .CommitDate }}
- --build-arg=COMMIT_ID={{ .FullCommit }}
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/krzko/{{ .ProjectName }}
Expand All @@ -38,6 +40,9 @@ dockers:
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --build-arg=BUILD_VERSION={{ .Version }}
- --build-arg=BUILD_DATE={{ .CommitDate }}
- --build-arg=COMMIT_ID={{ .FullCommit }}
- --platform=linux/arm64/v8
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
Expand Down
21 changes: 18 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
FROM scratch
ENTRYPOINT ["/otelgen"]
COPY otelgen /otelgen
FROM golang:1.23 AS builder

WORKDIR /go/src/github.com/krzko/otelgen

COPY . .

ARG BUILD_VERSION=0.0.0
ARG BUILD_DATE=1970-01-01T00:00:00Z
ARG COMMIT_ID=unknown

RUN CGO_ENABLED=0 go build -ldflags "-X main.version=${BUILD_VERSION} -X main.date=${BUILD_DATE} -X main.commit=${COMMIT_ID}" \
-o /usr/bin/otelgen -v /go/src/github.com/krzko/otelgen/cmd/otelgen

FROM cgr.dev/chainguard/static:latest

COPY --from=builder /usr/bin/otelgen /

CMD ["/otelgen"]
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOLINT=golangci-lint

# Binary name
BINARY_NAME=otelgen

# Main package path
MAIN_PACKAGE=./cmd/otelgen

# Build directory
BUILD_DIR=./build

# Source files
SRC=$(shell find . -name "*.go")

# Test coverage output
COVERAGE_OUTPUT=coverage.out

.PHONY: all build clean test coverage lint deps tidy run help

all: build

build: ## Build the binary
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE)

clean: ## Remove build artifacts
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -f $(COVERAGE_OUTPUT)

test: ## Run tests
$(GOTEST) -v ./...

coverage: ## Run tests with coverage
$(GOTEST) -v -coverprofile=$(COVERAGE_OUTPUT) ./...
$(GOCMD) tool cover -html=$(COVERAGE_OUTPUT)

lint: ## Run linter
$(GOLINT) run

deps: ## Download dependencies
$(GOGET) -v -t -d ./...

tidy: ## Tidy and verify dependencies
$(GOMOD) tidy
$(GOMOD) verify

run: build ## Run the application
$(BUILD_DIR)/$(BINARY_NAME)

docker-build: ## Build Docker image
docker build -t $(BINARY_NAME) .

docker-run: ## Run Docker container
docker run --rm $(BINARY_NAME)

help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help
120 changes: 71 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ Often synthetics are used to validate certain configurations, to ensure that th

`otelgen` allows you to quickly validate these configurations using the [OpenTelemetry Protocol Specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md), which supports both [OTLP/gRPC](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc) and [OTLP/HTTP](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp) using the [OTLP Receiver](https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver).

## Supported Specifications
## Supported Signals

The following specifications are supported.

- [X] Traces: Yes
- Scenarios to simulate differnt trace patterns
- Span Events
- Span Links
- [X] Metrics: Yes
- Counter
- Histogram
- UpDownCounter
- [ ] Logs: Not started yet
- Metric Types:
- Exponential Histogram
- Guage
- Histogram
- Sum
- Exemplars
- [X] Logs: Yes
- Log Levels
- Log Attributes
- Trace Context Correlation

## Getting Started

Expand Down Expand Up @@ -57,9 +66,10 @@ USAGE:
otelgen [global options] command [command options] [arguments...]

VERSION:
v0.0.3
develop

COMMANDS:
logs, l Generate logs
metrics, m Generate metrics
traces, t Generate traces
help, h Shows a list of commands or help for one command
Expand All @@ -77,47 +87,9 @@ GLOBAL OPTIONS:
--version, -v print the version (default: false)
```

### Metrics

The `otelgen metrics` command supports many different **metric** types. Here is an example of how to generate metrics:

```sh
$ otelgen --otel-exporter-otlp-endpoint otelcol.foo.bar:443 metrics counter

{"level":"info","ts":1658746679.286242,"caller":"cli/metrics_counter.go:70","msg":"starting gRPC exporter"}
{"level":"info","ts":1658746679.46613,"caller":"cli/metrics_counter.go:87","msg":"Starting metrics generation"}
{"level":"info","ts":1658746679.466242,"caller":"metrics/config.go:59","msg":"generation of metrics is limited","per-second":5}
{"level":"info","ts":1658746679.467317,"caller":"metrics/metrics.go:47","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746684.4677298,"caller":"metrics/metrics.go:47","msg":"generating","name":"otelgen.metrics.counter"}
...
```

Here is an example, of how to limit the `duration` in seconds of a generation process:

```sh
$ otelgen --otel-exporter-otlp-endpoint otelcol.foo.bar:443 --duration 30 metrics counter

{"level":"info","ts":1658746721.598725,"caller":"cli/metrics_counter.go:70","msg":"starting gRPC exporter"}
{"level":"info","ts":1658746721.789262,"caller":"cli/metrics_counter.go:87","msg":"Starting metrics generation"}
{"level":"info","ts":1658746721.789321,"caller":"metrics/config.go:59","msg":"generation of metrics is limited","per-second":5}
{"level":"info","ts":1658746721.7894,"caller":"metrics/metrics.go:30","msg":"generation duration","seconds":30}
{"level":"info","ts":1658746721.789411,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746726.7905679,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746731.790965,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746736.791102,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746741.791389,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746746.791574,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746751.791806,"caller":"cli/metrics_counter.go:79","msg":"stopping the exporter"}
```

If you need to pass in additional HTTP headers to allow for authentication to vendor backends, simply utilise the `--header key=value` flag. The unit is a slice of headers so it accepts multiple headers during invocation. Such as:
## Signals

```sh
$ otelgen --otel-exporter-otlp-endpoint api.vendor.xyz:443 \
--header 'x-auth=xxxxxx' \
--header 'x-dataset=xxxxxx' \
metrics counter
```
`otelgen` emits three types of signals, `logs`, `metrics` and `traces`. Each signal has a different set of options, which can be configured via the command line.

### Traces

Expand Down Expand Up @@ -173,8 +145,58 @@ $ otelgen --otel-exporter-otlp-endpoint api.vendor.xyz:443 \
traces single
```

## Acknowledgements
### Metrics

The `otelgen metrics` command supports many different **metric** types. Here is an example of how to generate metrics:

```sh
$ otelgen --otel-exporter-otlp-endpoint otelcol.foo.bar:443 metrics counter

{"level":"info","ts":1658746679.286242,"caller":"cli/metrics_counter.go:70","msg":"starting gRPC exporter"}
{"level":"info","ts":1658746679.46613,"caller":"cli/metrics_counter.go:87","msg":"Starting metrics generation"}
{"level":"info","ts":1658746679.466242,"caller":"metrics/config.go:59","msg":"generation of metrics is limited","per-second":5}
{"level":"info","ts":1658746679.467317,"caller":"metrics/metrics.go:47","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746684.4677298,"caller":"metrics/metrics.go:47","msg":"generating","name":"otelgen.metrics.counter"}
...
```

Here is an example, of how to limit the `duration` in seconds of a generation process:

```sh
$ otelgen --otel-exporter-otlp-endpoint otelcol.foo.bar:443 --duration 30 metrics counter

{"level":"info","ts":1658746721.598725,"caller":"cli/metrics_counter.go:70","msg":"starting gRPC exporter"}
{"level":"info","ts":1658746721.789262,"caller":"cli/metrics_counter.go:87","msg":"Starting metrics generation"}
{"level":"info","ts":1658746721.789321,"caller":"metrics/config.go:59","msg":"generation of metrics is limited","per-second":5}
{"level":"info","ts":1658746721.7894,"caller":"metrics/metrics.go:30","msg":"generation duration","seconds":30}
{"level":"info","ts":1658746721.789411,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746726.7905679,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746731.790965,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746736.791102,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746741.791389,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746746.791574,"caller":"metrics/metrics.go:40","msg":"generating","name":"otelgen.metrics.counter"}
{"level":"info","ts":1658746751.791806,"caller":"cli/metrics_counter.go:79","msg":"stopping the exporter"}
```

If you need to pass in additional HTTP headers to allow for authentication to vendor backends, simply utilise the `--header key=value` flag. The unit is a slice of headers so it accepts multiple headers during invocation. Such as:

```sh
$ otelgen --otel-exporter-otlp-endpoint api.vendor.xyz:443 \
--header 'x-auth=xxxxxx' \
--header 'x-dataset=xxxxxx' \
metrics counter
```

### Logs

The `otelgen logs` command generates synthetic logs that simulate realistic workloads, useful for testing and validating observability pipelines.

```sh
$ otelgen --otel-exporter-otlp-endpoint localhost:4317 --insecure logs

2024-09-29T15:03:10.092+1000 INFO logs/logs.go:63 generation of logs is limited {"per-second": 5}
2024-09-29T15:03:10.093+1000 INFO logs/logs.go:177 starting log generation {"worker": 0, "worker_id": 0}
2024-09-29T15:03:18.976+1000 INFO logs/logs.go:138 log generation completed {"total_logs": 30}
```

This tool was developed in a short amount of time due to the awesome idea of the following sources:

- [tracegen](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/tracegen): This utility simulates a client generating traces, useful for testing and demonstration purposes. In essence, `otelgen` uses `tracegen` as the tracing infrastructure.
Loading

0 comments on commit 622cf2a

Please sign in to comment.