Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LS-60099 addressing code warnings. #69

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just so you know, this change probably isn't necessary, lists with all value of 1. should render with actual numbers. But I don't mind the change. It makes the raw markdown text more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, thank you! I was trying to address all the low hanging fruit code warnings in this PR.

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
Expand Down Expand Up @@ -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:<tag>`

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
Expand Down
11 changes: 6 additions & 5 deletions generatorreceiver/generator_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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)
}

Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions generatorreceiver/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
2 changes: 1 addition & 1 deletion generatorreceiver/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions generatorreceiver/internal/generator/metric_generator.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package generator

import (
"time"
"math/rand"
"time"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand All @@ -12,15 +12,15 @@ import (

type MetricGenerator struct {
metricCount int
random *rand.Rand
random *rand.Rand
}

func NewMetricGenerator(seed int64) *MetricGenerator {
r := rand.New(rand.NewSource(seed))
r.Seed(seed)
return &MetricGenerator{
metricCount: 0,
random: r,
random: r,
}
}

Expand Down
3 changes: 1 addition & 2 deletions generatorreceiver/internal/topology/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -673,4 +673,3 @@ func generateK8sName(n int) string {
}
return string(b)
}

6 changes: 3 additions & 3 deletions generatorreceiver/internal/topology/latency_percentiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading