From 95d100aedf9fa44da5f090ffeb5a74cc51189fe6 Mon Sep 17 00:00:00 2001 From: nityanandagohain Date: Thu, 30 Apr 2026 18:33:21 +0530 Subject: [PATCH] fix: lint --- .../impllmpricingrule/module.go | 21 +++++++------------ .../testdata/collector_baseline.yaml | 16 ++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/pkg/modules/llmpricingrule/impllmpricingrule/module.go b/pkg/modules/llmpricingrule/impllmpricingrule/module.go index 7a7b41e29d..35d1198e80 100644 --- a/pkg/modules/llmpricingrule/impllmpricingrule/module.go +++ b/pkg/modules/llmpricingrule/impllmpricingrule/module.go @@ -41,10 +41,9 @@ func (module *module) CreateOrUpdate(ctx context.Context, orgID valuer.UUID, use for _, u := range rules { existing, err := module.findExisting(ctx, orgID, u) if err != nil { - return err - } - - if existing == nil { + if !errors.Ast(err, errors.TypeNotFound) { + return err + } if err := module.store.Create(ctx, llmpricingruletypes.NewLLMPricingRuleFromUpdatable(u, orgID, userEmail, now)); err != nil { return err } @@ -76,20 +75,16 @@ func (module *module) Delete(ctx context.Context, orgID, id valuer.UUID) error { return nil } +// findExisting returns the row matching the updatable's ID or SourceID. +// Returns a TypeNotFound error when neither matches; the caller treats that +// as "insert new". func (module *module) findExisting(ctx context.Context, orgID valuer.UUID, u llmpricingruletypes.UpdatableLLMPricingRule) (*llmpricingruletypes.LLMPricingRule, error) { switch { case u.ID != nil: return module.store.Get(ctx, orgID, *u.ID) case u.SourceID != nil: - s, err := module.store.GetBySourceID(ctx, orgID, *u.SourceID) - if err != nil { - if errors.Ast(err, errors.TypeNotFound) { - return nil, nil - } - return nil, err - } - return s, nil + return module.store.GetBySourceID(ctx, orgID, *u.SourceID) default: - return nil, nil + return nil, errors.Newf(errors.TypeNotFound, llmpricingruletypes.ErrCodePricingRuleNotFound, "rule has neither id nor sourceId") } } diff --git a/pkg/modules/llmpricingrule/impllmpricingrule/testdata/collector_baseline.yaml b/pkg/modules/llmpricingrule/impllmpricingrule/testdata/collector_baseline.yaml index 7c21a47d7d..342b0a84dc 100644 --- a/pkg/modules/llmpricingrule/impllmpricingrule/testdata/collector_baseline.yaml +++ b/pkg/modules/llmpricingrule/impllmpricingrule/testdata/collector_baseline.yaml @@ -3,6 +3,22 @@ receivers: protocols: grpc: processors: + signozllmpricing: + attrs: + model: gen_ai.request.model + in: gen_ai.usage.input_tokens + out: gen_ai.usage.output_tokens + cache_read: gen_ai.usage.cache_read.input_tokens + cache_write: gen_ai.usage.cache_creation.input_tokens + default_pricing: + unit: per_million_tokens + rules: [] + output_attrs: + in: _signoz.gen_ai.cost_input + out: _signoz.gen_ai.cost_output + cache_read: _signoz.gen_ai.cost_cache_read + cache_write: _signoz.gen_ai.cost_cache_write + total: _signoz.gen_ai.total_cost batch: {} exporters: otlp: