Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdurham committed Dec 13, 2023
1 parent 29a4b7c commit bdf2fb3
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions component/prometheus/test/metrics/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ func (c *Component) discovery(w httpgo.ResponseWriter, r *httpgo.Request) {
for x := range c.instances {
instances[x] = createTarget(c.handler.HTTPListenAddr, fmt.Sprintf("%sinstance/%d/metrics", c.path, x))
}
marshalledBytes, _ := json.Marshal(instances)
_, _ = w.Write(marshalledBytes)
marshalledBytes, err := json.Marshal(instances)
if err != nil {
level.Error(c.o.Logger).Log("msg", "error marshalling discovery", "err", err)
return
}
_, err = w.Write(marshalledBytes)
if err != nil {
level.Error(c.o.Logger).Log("msg", "error writing discovery", "err", err)
return
}
}

func (c *Component) serveMetrics(w httpgo.ResponseWriter, r *httpgo.Request) {
Expand Down Expand Up @@ -113,9 +121,6 @@ func (c *Component) Run(ctx context.Context) error {
}

func (c *Component) Update(args component.Arguments) error {
c.mut.Lock()
defer c.mut.Unlock()

c.argsUpdate <- args.(Arguments)
return nil
}
Expand Down Expand Up @@ -143,6 +148,24 @@ func (a *Arguments) SetToDefault() {
*a = getDefault()
}

// Validate returns whether args is valid.
func (a *Arguments) Validate() error {
if a.NumberOfInstances <= 0 {
return fmt.Errorf("number_of_instances must be positive and is %d", a.NumberOfInstances)
}
if a.NumberOfMetrics <= 0 {
return fmt.Errorf("number_of_metrics must be positive and is %d", a.NumberOfMetrics)
}
if a.NumberOfSeries < 0 {
return fmt.Errorf("number_of_seires must not be negative and is %d", a.NumberOfSeries)
}
if a.ChurnPercent < 0 || a.ChurnPercent > 1 {
return fmt.Errorf("churn_percent must be between 0 and 1 and is %f", a.ChurnPercent)
}

return nil
}

type Exports struct {
Targets []map[string]string `river:"targets,attr,optional"`
}
Expand Down

0 comments on commit bdf2fb3

Please sign in to comment.