Skip to content

Commit

Permalink
Add script to generate manifest with default config
Browse files Browse the repository at this point in the history
The script:
- generates the manifest with default config YAML which is included in the docs as a reference.
- runs in CI to check if the manifest needs to be updated as a result of new changes in the default config.
  • Loading branch information
carles-grafana committed Dec 10, 2024
1 parent 2fff84a commit 9b2de05
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:

- name: Check out code
uses: actions/checkout@v4
with:
Expand All @@ -29,6 +30,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: check-fmt
run: make check-fmt

Expand All @@ -38,6 +40,9 @@ jobs:
- name: lint
run: make lint base=origin/${{github.base_ref}}

- name: generate-manifest
run: go run pkg/docsgen/generate_manifest.go

unit-tests:
name: Run Unit Tests
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions cmd/tempo/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (t *App) writeStatusConfig(w io.Writer, r *http.Request) error {
mode := r.URL.Query().Get("mode")
switch mode {
case "diff":
defaultCfg := newDefaultConfig()
defaultCfg := NewDefaultConfig()

defaultCfgYaml, err := util.YAMLMarshalUnmarshal(defaultCfg)
if err != nil {
Expand All @@ -287,7 +287,7 @@ func (t *App) writeStatusConfig(w io.Writer, r *http.Request) error {
return err
}
case "defaults":
output = newDefaultConfig()
output = NewDefaultConfig()
case "":
output = t.cfg
default:
Expand Down
2 changes: 1 addition & 1 deletion cmd/tempo/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Config struct {
CacheProvider cache.Config `yaml:"cache,omitempty"`
}

func newDefaultConfig() *Config {
func NewDefaultConfig() *Config {
defaultConfig := &Config{}
defaultFS := flag.NewFlagSet("", flag.PanicOnError)
defaultConfig.RegisterFlagsAndApplyDefaults("", defaultFS)
Expand Down
14 changes: 7 additions & 7 deletions cmd/tempo/app/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestConfig_CheckConfig(t *testing.T) {
}{
{
name: "check default cfg and expect no warnings",
config: newDefaultConfig(),
config: NewDefaultConfig(),
expect: nil,
},
{
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestConfig_CheckConfig(t *testing.T) {
{
name: "hit local backend warnings",
config: func() *Config {
cfg := newDefaultConfig()
cfg := NewDefaultConfig()
cfg.StorageConfig.Trace = tempodb.Config{
Backend: backend.Local,
BlocklistPollConcurrency: 1,
Expand All @@ -92,7 +92,7 @@ func TestConfig_CheckConfig(t *testing.T) {
{
name: "warnings for v2 settings when they drift from default",
config: func() *Config {
cfg := newDefaultConfig()
cfg := NewDefaultConfig()
cfg.StorageConfig.Trace.Block.Version = vparquet4.VersionString
cfg.StorageConfig.Trace.Block.IndexDownsampleBytes = 1
cfg.StorageConfig.Trace.Block.IndexPageSizeBytes = 1
Expand All @@ -112,7 +112,7 @@ func TestConfig_CheckConfig(t *testing.T) {
{
name: "no warnings for v2 settings when they drift from default and v2 is the block version",
config: func() *Config {
cfg := newDefaultConfig()
cfg := NewDefaultConfig()
cfg.StorageConfig.Trace.Block.Version = v2.VersionString
cfg.StorageConfig.Trace.Block.IndexDownsampleBytes = 1
cfg.StorageConfig.Trace.Block.IndexPageSizeBytes = 1
Expand All @@ -126,7 +126,7 @@ func TestConfig_CheckConfig(t *testing.T) {
{
name: "trace storage conflicts with overrides storage - local",
config: func() *Config {
cfg := newDefaultConfig()
cfg := NewDefaultConfig()
cfg.StorageConfig.Trace.Backend = backend.Local
cfg.StorageConfig.Trace.Local.Path = "/var/tempo"
cfg.Overrides.UserConfigurableOverridesConfig.Client.Backend = backend.Local
Expand All @@ -138,7 +138,7 @@ func TestConfig_CheckConfig(t *testing.T) {
{
name: "trace storage conflicts with overrides storage - gcs",
config: func() *Config {
cfg := newDefaultConfig()
cfg := NewDefaultConfig()
cfg.StorageConfig.Trace.Backend = backend.GCS
cfg.StorageConfig.Trace.GCS.BucketName = "bucketname"
cfg.StorageConfig.Trace.GCS.Prefix = "tempo"
Expand All @@ -152,7 +152,7 @@ func TestConfig_CheckConfig(t *testing.T) {
{
name: "trace storage conflicts with overrides storage - different backends",
config: func() *Config {
cfg := newDefaultConfig()
cfg := NewDefaultConfig()
cfg.StorageConfig.Trace.Backend = backend.GCS
cfg.StorageConfig.Trace.GCS.BucketName = "my-bucket"
cfg.Overrides.UserConfigurableOverridesConfig.Client.Backend = backend.S3
Expand Down
42 changes: 17 additions & 25 deletions docs/sources/tempo/configuration/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ title: Manifest
description: This manifest lists of all Tempo options and their defaults.
weight: 110
---
[//]: # THIS FILE IS GENERATED AUTOMATICALLY BY 'go run pkg/docsgen/generate_manifest.go'
[//]: # DO NOT EDIT THIS FILE DIRECTLY'

# Manifest

This document is a reference for all Tempo options and their defaults. If you are just getting
started with Tempo, refer to [Tempo examples](https://github.com/grafana/tempo/tree/main/example/docker-compose)
and other [configuration documentation]({{< relref "../configuration" >}}). Most installations will require only setting 10 to 20 of these options.

It was generated by running Tempo with a minimal configuration and accessing the `/status/config` endpoint:
```
go run ./cmd/tempo --storage.trace.backend=local --storage.trace.local.path=/var/tempo/traces --storage.trace.wal.path=/var/tempo/wal
```

## Complete configuration

{{< admonition type="note" >}}
This manifest was generated on 2024-11-28.
{{% /admonition %}}

```yaml
target: all
http_api_prefix: ""
Expand Down Expand Up @@ -177,7 +170,7 @@ distributor:
mirror_timeout: 2s
heartbeat_period: 5s
heartbeat_timeout: 5m0s
instance_id: local-instance
instance_id: instance_id
instance_interface_names:
- eth0
- en0
Expand All @@ -202,7 +195,7 @@ ingester_client:
grpc_client_config:
max_recv_msg_size: 104857600
max_send_msg_size: 104857600
grpc_compression: snappy
grpc_compression: ""
rate_limit: 0
rate_limit_burst: 0
backoff_on_ratelimits: false
Expand Down Expand Up @@ -233,7 +226,7 @@ metrics_generator_client:
grpc_client_config:
max_recv_msg_size: 104857600
max_send_msg_size: 104857600
grpc_compression: snappy
grpc_compression: ""
rate_limit: 0
rate_limit_burst: 0
backoff_on_ratelimits: false
Expand Down Expand Up @@ -270,15 +263,15 @@ querier:
time_overlap_cutoff: 0.2
max_concurrent_queries: 20
frontend_worker:
frontend_address: 127.0.0.1:9095
frontend_address: ""
dns_lookup_duration: 10s
parallelism: 2
match_max_concurrent: true
id: ""
grpc_client_config:
max_recv_msg_size: 104857600
max_send_msg_size: 16777216
grpc_compression: gzip
grpc_compression: ""
rate_limit: 0
rate_limit_burst: 0
backoff_on_ratelimits: false
Expand Down Expand Up @@ -370,7 +363,7 @@ compactor:
heartbeat_timeout: 1m0s
wait_stability_min_duration: 1m0s
wait_stability_max_duration: 5m0s
instance_id: local-instance
instance_id: instance_id
instance_interface_names:
- eth0
- en0
Expand All @@ -395,7 +388,7 @@ ingester:
lifecycler:
ring:
kvstore:
store: inmemory
store: memberlist
prefix: collectors/
consul:
host: localhost:8500
Expand Down Expand Up @@ -435,16 +428,16 @@ ingester:
join_after: 0s
min_ready_duration: 15s
interface_names:
- en0
- eth0
enable_inet6: false
final_sleep: 0s
tokens_file_path: ""
availability_zone: ""
unregister_on_shutdown: true
readiness_check_ring_health: true
address: 127.0.0.1
address: ""
port: 0
id: local-instance
id: instance_id
concurrent_flushes: 4
flush_check_period: 10s
flush_op_timeout: 5m0s
Expand All @@ -457,7 +450,7 @@ ingester:
metrics_generator:
ring:
kvstore:
store: inmemory
store: memberlist
prefix: collectors/
consul:
host: localhost:8500
Expand Down Expand Up @@ -488,11 +481,11 @@ metrics_generator:
mirror_timeout: 2s
heartbeat_period: 5s
heartbeat_timeout: 1m0s
instance_id: local-instance
instance_id: instance_id
instance_interface_names:
- eth0
- en0
instance_addr: 127.0.0.1
instance_addr: ""
instance_port: 0
enable_inet6: false
processor:
Expand Down Expand Up @@ -616,7 +609,6 @@ storage:
v2_encoding: snappy
search_encoding: none
ingestion_time_range_slack: 2m0s
version: vParquet4
block:
bloom_filter_false_positive: 0.01
bloom_filter_shard_size_bytes: 102400
Expand Down Expand Up @@ -648,9 +640,9 @@ storage:
blocklist_poll_tolerate_tenant_failures: 1
empty_tenant_deletion_enabled: false
empty_tenant_deletion_age: 0s
backend: local
backend: ""
local:
path: /var/tempo/traces
path: ""
gcs:
bucket_name: ""
prefix: ""
Expand Down
63 changes: 63 additions & 0 deletions pkg/docsgen/generate_manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"fmt"
"log"
"os"
"os/exec"

"github.com/grafana/tempo/cmd/tempo/app"
"gopkg.in/yaml.v3"
)

const ManifestPath = "docs/sources/tempo/configuration/manifest.md"

const Cmd = "go run pkg/docsgen/generate_manifest.go"

var Manifest = fmt.Sprintf(`---
title: Manifest
description: This manifest lists of all Tempo options and their defaults.
weight: 110
---
[//]: # THIS FILE IS GENERATED AUTOMATICALLY BY '%s'
[//]: # DO NOT EDIT THIS FILE DIRECTLY'
# Manifest
This document is a reference for all Tempo options and their defaults. If you are just getting
started with Tempo, refer to [Tempo examples](https://github.com/grafana/tempo/tree/main/example/docker-compose)
and other [configuration documentation]({{< relref "../configuration" >}}). Most installations will require only setting 10 to 20 of these options.
## Complete configuration
`, Cmd)

func main() {
newConfig := app.NewDefaultConfig()
// Override values that depend on the host specifics
const hostname = "hostname"
newConfig.Distributor.DistributorRing.InstanceID = hostname
newConfig.Compactor.ShardingRing.InstanceID = hostname
newConfig.Ingester.LifecyclerConfig.ID = hostname
newConfig.Ingester.LifecyclerConfig.InfNames = []string{"eth0"}
newConfig.Generator.Ring.InstanceID = hostname

newConfigBytes, err := yaml.Marshal(newConfig)
if err != nil {
panic(err)
}
newManifest := Manifest + "```yaml\n" + string(newConfigBytes) + "```\n"

err = os.WriteFile(ManifestPath, []byte(newManifest), 0o644)
if err != nil {
panic(err)
}

cmd := exec.Command("git", "diff", "--exit-code", ManifestPath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Fatalf("The manifest with the default Tempo configuration has changed. Please run '%s' and commit the changes.", Cmd)
}
}

0 comments on commit 9b2de05

Please sign in to comment.