Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore: add search and override filters in pricing model list api (#11735)

Nityananda Gohain560057672271
diff --git a/docs/api/openapi.yml b/docs/api/openapi.yml
index 8df6bc4b68..98f4b6432f 100644
--- a/docs/api/openapi.yml
+++ b/docs/api/openapi.yml
@@ -10309,6 +10309,15 @@ paths:
name: limit
schema:
type: integer
+ - in: query
+ name: q
+ schema:
+ type: string
+ - in: query
+ name: isOverride
+ schema:
+ nullable: true
+ type: boolean
responses:
"200":
content:
diff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.ts
index 87fa26ca32..32341f98de 100644
--- a/frontend/src/api/generated/services/sigNoz.schemas.ts
+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts
@@ -9500,6 +9500,16 @@ export type ListLLMPricingRulesParams = {
* @description undefined
*/
limit?: number;
+ /**
+ * @type string
+ * @description undefined
+ */
+ q?: string;
+ /**
+ * @type boolean,null
+ * @description undefined
+ */
+ isOverride?: boolean | null;
};
export type ListLLMPricingRules200 = {
diff --git a/pkg/modules/llmpricingrule/impllmpricingrule/handler.go b/pkg/modules/llmpricingrule/impllmpricingrule/handler.go
index 7d7e13d786..0ac39e2e37 100644
--- a/pkg/modules/llmpricingrule/impllmpricingrule/handler.go
+++ b/pkg/modules/llmpricingrule/impllmpricingrule/handler.go
@@ -54,7 +54,7 @@ func (h *handler) List(rw http.ResponseWriter, r *http.Request) {
return
}
- rules, total, err := h.module.List(ctx, orgID, q.Offset, q.Limit)
+ rules, total, err := h.module.List(ctx, orgID, q.Offset, q.Limit, q.Search, q.IsOverride)
if err != nil {
render.Error(rw, err)
return
diff --git a/pkg/modules/llmpricingrule/impllmpricingrule/module.go b/pkg/modules/llmpricingrule/impllmpricingrule/module.go
index b5afa42c57..fce804cb56 100644
--- a/pkg/modules/llmpricingrule/impllmpricingrule/module.go
+++ b/pkg/modules/llmpricingrule/impllmpricingrule/module.go
@@ -21,8 +21,8 @@ func NewModule(store llmpricingruletypes.Store) llmpricingrule.Module {
return &module{store: store}
}
-func (module *module) List(ctx context.Context, orgID valuer.UUID, offset, limit int) ([]*llmpricingruletypes.LLMPricingRule, int, error) {
- return module.store.List(ctx, orgID, offset, limit)
+func (module *module) List(ctx context.Context, orgID valuer.UUID, offset, limit int, search string, isOverride *bool) ([]*llmpricingruletypes.LLMPricingRule, int, error) {
+ return module.store.List(ctx, orgID, offset, limit, search, isOverride)
}
func (module *module) Get(ctx context.Context, orgID valuer.UUID, id valuer.UUID) (*llmpricingruletypes.LLMPricingRule, error) {
@@ -108,7 +108,7 @@ func (module *module) RecommendAgentConfig(orgID valuer.UUID, currentConfYaml []
}
func (module *module) getEnabledRules(ctx context.Context, orgID valuer.UUID) ([]*llmpricingruletypes.LLMPricingRule, error) {
- rules, _, err := module.List(ctx, orgID, 0, 10000)
+ rules, _, err := module.List(ctx, orgID, 0, 10000, "", nil)
if err != nil {
return nil, err
}
diff --git a/pkg/modules/llmpricingrule/impllmpricingrule/store.go b/pkg/modules/llmpricingrule/impllmpricingrule/store.go
index 9c0cb5b014..cf05a7cf4e 100644
--- a/pkg/modules/llmpricingrule/impllmpricingrule/store.go
+++ b/pkg/modules/llmpricingrule/impllmpricingrule/store.go
@@ -17,14 +17,25 @@ func NewStore(sqlstore sqlstore.SQLStore) llmpricingruletypes.Store {
return &store{sqlstore: sqlstore}
}
-func (store *store) List(ctx context.Context, orgID valuer.UUID, offset, limit int) ([]*llmpricingruletypes.LLMPricingRule, int, error) {
+func (store *store) List(ctx context.Context, orgID valuer.UUID, offset, limit int, search string, isOverride *bool) ([]*llmpricingruletypes.LLMPricingRule, int, error) {
rules := make([]*llmpricingruletypes.LLMPricingRule, 0)
- count, err := store.sqlstore.
+ query := store.sqlstore.
BunDBCtx(ctx).
NewSelect().
Model(&rules).
- Where("org_id = ?", orgID).
+ Where("org_id = ?", orgID)
+
+ if search != "" {
+ like := "%" + search + "%"
+ query = query.Where("(LOWER(model) LIKE LOWER(?) OR LOWER(provider) LIKE LOWER(?))", like, like)
+ }
+
+ if isOverride != nil {
+ query = query.Where("is_override = ?", *isOverride)
+ }
+
+ count, err := query.
Order("created_at DESC").
Offset(offset).
Limit(limit).
diff --git a/pkg/modules/llmpricingrule/llmpricingrule.go b/pkg/modules/llmpricingrule/llmpricingrule.go
index cfe3811171..545c2f88c0 100644
--- a/pkg/modules/llmpricingrule/llmpricingrule.go
+++ b/pkg/modules/llmpricingrule/llmpricingrule.go
@@ -13,7 +13,7 @@ type Module interface {
// Since this module interacts with OpAMP, it must implement the AgentFeature interface.
agentConf.AgentFeature
- List(ctx context.Context, orgID valuer.UUID, offset, limit int) ([]*llmpricingruletypes.LLMPricingRule, int, error)
+ List(ctx context.Context, orgID valuer.UUID, offset, limit int, search string, isOverride *bool) ([]*llmpricingruletypes.LLMPricingRule, int, error)
Get(ctx context.Context, orgID valuer.UUID, id valuer.UUID) (*llmpricingruletypes.LLMPricingRule, error)
CreateOrUpdate(ctx context.Context, orgID valuer.UUID, userEmail string, rules []*llmpricingruletypes.UpdatableLLMPricingRule) (err error)
Delete(ctx context.Context, orgID, id valuer.UUID) error
diff --git a/pkg/types/llmpricingruletypes/pricing.go b/pkg/types/llmpricingruletypes/pricing.go
index a9f9b1a5a9..141020e4a7 100644
--- a/pkg/types/llmpricingruletypes/pricing.go
+++ b/pkg/types/llmpricingruletypes/pricing.go
@@ -125,8 +125,10 @@ type UpdatableLLMPricingRules struct {
}
type ListPricingRulesQuery struct {
- Offset int `query:"offset" json:"offset"`
- Limit int `query:"limit" json:"limit"`
+ Offset int `query:"offset" json:"offset"`
+ Limit int `query:"limit" json:"limit"`
+ Search string `query:"q" json:"q"`
+ IsOverride *bool `query:"isOverride" json:"isOverride"`
}
type GettablePricingRules struct {
diff --git a/pkg/types/llmpricingruletypes/store.go b/pkg/types/llmpricingruletypes/store.go
index d8b2deda48..a8b60551cf 100644
--- a/pkg/types/llmpricingruletypes/store.go
+++ b/pkg/types/llmpricingruletypes/store.go
@@ -7,7 +7,7 @@ import (
)
type Store interface {
- List(ctx context.Context, orgID valuer.UUID, offset, limit int) ([]*LLMPricingRule, int, error)
+ List(ctx context.Context, orgID valuer.UUID, offset, limit int, search string, isOverride *bool) ([]*LLMPricingRule, int, error)
Get(ctx context.Context, orgID, id valuer.UUID) (*LLMPricingRule, error)
GetBySourceID(ctx context.Context, orgID, sourceID valuer.UUID) (*LLMPricingRule, error)
Create(ctx context.Context, rule *LLMPricingRule) error