Skip to content

Commit

Permalink
Fixes CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzaldysanchez committed Nov 14, 2024
1 parent 5595d01 commit 331bced
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
17 changes: 8 additions & 9 deletions core/capabilities/compute/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var _ capabilities.ActionCapability = (*Compute)(nil)
type Compute struct {
stopCh services.StopChan
log logger.Logger
metrics computeMetricsLabeler
metrics *computeMetricsLabeler

// emitter is used to emit messages from the WASM module to a configured collector.
emitter custmsg.MessageEmitter
Expand Down Expand Up @@ -248,11 +248,6 @@ func (c *Compute) Info(ctx context.Context) (capabilities.CapabilityInfo, error)
func (c *Compute) Start(ctx context.Context) error {
c.modules.start()

err := initMonitoringResources()
if err != nil {
return fmt.Errorf("failed to initialize monitoring resources: %w", err)
}

c.wg.Add(c.numWorkers)
for i := 0; i < c.numWorkers; i++ {
go func() {
Expand Down Expand Up @@ -373,18 +368,22 @@ func NewAction(
handler *webapi.OutgoingConnectorHandler,
idGenerator func() string,
opts ...func(*Compute),
) *Compute {
) (*Compute, error) {
if config.NumWorkers == 0 {
config.NumWorkers = defaultNumWorkers
}
metricsLabeler, err := newComputeMetricsLabeler(metrics.NewLabeler().With("capability", CapabilityIDCompute))
if err != nil {
return nil, fmt.Errorf("failed to create compute metrics labeler: %w", err)
}
var (
lggr = logger.Named(log, "CustomCompute")
labeler = custmsg.NewLabeler()
compute = &Compute{
stopCh: make(services.StopChan),
log: lggr,
emitter: labeler,
metrics: computeMetricsLabeler{metrics.NewLabeler().With("capability", CapabilityIDCompute)},
metrics: metricsLabeler,
registry: registry,
modules: newModuleCache(clockwork.NewRealClock(), 1*time.Minute, 10*time.Minute, 3),
transformer: NewTransformer(lggr, labeler),
Expand All @@ -399,5 +398,5 @@ func NewAction(
opt(compute)
}

return compute
return compute, nil
}
25 changes: 12 additions & 13 deletions core/capabilities/compute/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@ import (

const timestampKey = "computeTimestamp"

var computeHTTPRequestCounter metric.Int64Counter
type computeMetricsLabeler struct {
metrics.Labeler
computeHTTPRequestCounter metric.Int64Counter
}

func initMonitoringResources() (err error) {
computeHTTPRequestCounter, err = beholder.GetMeter().Int64Counter("capabilities_compute_http_request_count")
func newComputeMetricsLabeler(l metrics.Labeler) (*computeMetricsLabeler, error) {
computeHTTPRequestCounter, err := beholder.GetMeter().Int64Counter("capabilities_compute_http_request_count")
if err != nil {
return fmt.Errorf("failed to register compute http request counter: %w", err)
return nil, fmt.Errorf("failed to register compute http request counter: %w", err)
}

return nil
}

type computeMetricsLabeler struct {
metrics.Labeler
return &computeMetricsLabeler{Labeler: l, computeHTTPRequestCounter: computeHTTPRequestCounter}, nil
}

func (c computeMetricsLabeler) with(keyValues ...string) computeMetricsLabeler {
return computeMetricsLabeler{c.With(keyValues...)}
func (c *computeMetricsLabeler) with(keyValues ...string) *computeMetricsLabeler {
return &computeMetricsLabeler{c.With(keyValues...), c.computeHTTPRequestCounter}
}

func (c computeMetricsLabeler) incrementHTTPRequestCounter(ctx context.Context) {
func (c *computeMetricsLabeler) incrementHTTPRequestCounter(ctx context.Context) {
otelLabels := localMonitoring.KvMapToOtelAttributes(c.Labels)
computeHTTPRequestCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
c.computeHTTPRequestCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
}

0 comments on commit 331bced

Please sign in to comment.