diff --git a/README.md b/README.md index 7536409..8056e8f 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ Install the [OpenTelemetry Collector Builder](https://github.com/open-telemetry/ ### Get the code 1. Clone the [telemetry generator repo](https://github.com/lightstep/telemetry-generator) to a directory of your choosing: 1. `$ cd ~/Code` (or wherever) - 1. `$ git clone https://github.com/lightstep/telemetry-generator` - 1. `$ cd telemetry-generator` -1. Copy `hipster_shop.yaml` to `dev.yaml` for local development. Not strictly necessary (you can point the `TOPO_FILE` environment variable to any config file) but will potentially save heartache and hassle 😅 This file is in .gitignore, so it won't be included in your commits. If you want to share config changes, add them to a new example config file. + 2. `$ git clone https://github.com/lightstep/telemetry-generator` + 3. `$ cd telemetry-generator` +2. Copy `hipster_shop.yaml` to `dev.yaml` for local development. Not strictly necessary (you can point the `TOPO_FILE` environment variable to any config file) but will potentially save heartache and hassle 😅 This file is in .gitignore, so it won't be included in your commits. If you want to share config changes, add them to a new example config file. `$ cp examples/hipster_shop.yaml examples/dev.yaml` ## Environment variables @@ -101,14 +101,14 @@ When building with Docker, you need to re-run both steps for any code *or* confi ## Publishing a Release These steps enable a new Docker image to be available with `docker pull ghcr.io/lightstep/telemetry-generator:` -0. Make your code changes and add to a new PR, ensure to include an: +1. Make your code changes and add to a new PR, ensure to include an: * Update to VERSION in the file `VERSION` * Update to `CHANGELOG.md` * Update to [Compatibility Matrix](#compatibility-matrix) below. -1. Create PR, get approvals, merge changes -2. Run `make add-tag` +2. Create PR, get approvals, merge changes +3. Run `make add-tag` * (This will run `git tag` under the hood using the version number in VERSION) -3. Run `make push-tag` +4. Run `make push-tag` * (This will push the tags to Github. **THIS** is the operation that will kick off the GHA workflow, build and push a new image out to GHCR.io) ## Compatibility Matrix diff --git a/generatorreceiver/generator_receiver.go b/generatorreceiver/generator_receiver.go index c4cc243..92c8931 100644 --- a/generatorreceiver/generator_receiver.go +++ b/generatorreceiver/generator_receiver.go @@ -28,7 +28,7 @@ type generatorReceiver struct { server *httpServer } -func (g generatorReceiver) loadTopoFile(topoInline string, path string) (topoFile *topology.File, err error) { +func (g generatorReceiver) loadTopoFile(path string) (topoFile *topology.File, err error) { g.logger.Info("reading topo from file path", zap.String("path", g.topoPath)) topoFile, err = parseTopoFile(path) if err != nil { @@ -45,7 +45,7 @@ func (g generatorReceiver) loadTopoFile(topoInline string, path string) (topoFil } func (g generatorReceiver) Start(ctx context.Context, host component.Host) error { - topoFile, err := g.loadTopoFile(g.topoInline, g.topoPath) + topoFile, err := g.loadTopoFile(g.topoPath) if err != nil { return fmt.Errorf("could not load topo file: %w", err) } @@ -62,6 +62,7 @@ func (g generatorReceiver) Start(ctx context.Context, host component.Host) error generatorRand := rand.New(rand.NewSource(g.randomSeed)) // Metrics generator uses the global rand.Rand + // TODO: LS-60180 - rand.Seed is deprecated, use rand.NewSource rand.Seed(generatorRand.Int63()) if g.server != nil { @@ -87,7 +88,7 @@ func (g generatorReceiver) Start(ctx context.Context, host component.Host) error // Service defined metrics for _, m := range s.Metrics { - metricTicker := g.startMetricGenerator(ctx, host, s.ServiceName, m) + metricTicker := g.startMetricGenerator(ctx, s.ServiceName, m) g.tickers = append(g.tickers, metricTicker) } @@ -103,7 +104,7 @@ func (g generatorReceiver) Start(ctx context.Context, host component.Host) error // keep the same flags as the resources. k8sMetrics[i].EmbeddedFlags = resource.EmbeddedFlags - metricTicker := g.startMetricGenerator(ctx, host, s.ServiceName, k8sMetrics[i]) + metricTicker := g.startMetricGenerator(ctx, s.ServiceName, k8sMetrics[i]) g.tickers = append(g.tickers, metricTicker) } } @@ -149,7 +150,7 @@ func (g generatorReceiver) Start(ctx context.Context, host component.Host) error return nil } -func (g *generatorReceiver) startMetricGenerator(ctx context.Context, host component.Host, serviceName string, m topology.Metric) *time.Ticker { +func (g *generatorReceiver) startMetricGenerator(ctx context.Context, serviceName string, m topology.Metric) *time.Ticker { // TODO: do we actually need to generate every second? metricTicker := time.NewTicker(topology.DefaultMetricTickerPeriod) go func() { diff --git a/generatorreceiver/helper.go b/generatorreceiver/helper.go index 26993d7..d127918 100644 --- a/generatorreceiver/helper.go +++ b/generatorreceiver/helper.go @@ -33,7 +33,7 @@ func parseTopoFile(topoPath string) (*topology.File, error) { if hasAnySuffix(lowerTopoPath, []string{".yaml", ".yml"}) { err = yaml.Unmarshal(byteValue, &topo) } else { - err = fmt.Errorf("Unrecognized topology file type: %s", topoPath) + err = fmt.Errorf("unrecognized topology file type: %s", topoPath) } if err != nil { diff --git a/generatorreceiver/internal/generator/metric_generator.go b/generatorreceiver/internal/generator/metric_generator.go index ef7cdeb..5bf9faf 100644 --- a/generatorreceiver/internal/generator/metric_generator.go +++ b/generatorreceiver/internal/generator/metric_generator.go @@ -1,8 +1,8 @@ package generator import ( - "time" "math/rand" + "time" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" @@ -12,7 +12,7 @@ import ( type MetricGenerator struct { metricCount int - random *rand.Rand + random *rand.Rand } func NewMetricGenerator(seed int64) *MetricGenerator { @@ -20,7 +20,7 @@ func NewMetricGenerator(seed int64) *MetricGenerator { r.Seed(seed) return &MetricGenerator{ metricCount: 0, - random: r, + random: r, } } diff --git a/generatorreceiver/internal/topology/kubernetes.go b/generatorreceiver/internal/topology/kubernetes.go index 58cdccd..d9d1bbb 100644 --- a/generatorreceiver/internal/topology/kubernetes.go +++ b/generatorreceiver/internal/topology/kubernetes.go @@ -250,7 +250,7 @@ func (k *Kubernetes) GenerateMetrics() []Metric { memoryShape = Leaking } - metrics := []Metric{} + var metrics []Metric for _, pod := range k.pods { k8sTags := k.GetK8sTags(pod) @@ -673,4 +673,3 @@ func generateK8sName(n int) string { } return string(b) } - diff --git a/generatorreceiver/internal/topology/latency_percentiles.go b/generatorreceiver/internal/topology/latency_percentiles.go index bdf88de..52bcbef 100644 --- a/generatorreceiver/internal/topology/latency_percentiles.go +++ b/generatorreceiver/internal/topology/latency_percentiles.go @@ -36,9 +36,9 @@ func (l *LatencyPercentiles) Sample() int64 { return 0 } uniform := func(timeA, timeB time.Duration) int64 { - min := float64(timeA.Nanoseconds()) - max := float64(timeB.Nanoseconds()) - return int64(min + (max-min)*rand.Float64()) + minimum := float64(timeA.Nanoseconds()) + maximum := float64(timeB.Nanoseconds()) + return int64(minimum + (maximum-minimum)*rand.Float64()) } genNumber := rand.Float64() switch {