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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(statsreporter): track role counts (#11866)
Vikrant Guptaee3b45b80d7c
diff --git a/ee/authz/openfgaauthz/provider.go b/ee/authz/openfgaauthz/provider.goindex a2f7d137dd..758eaf42ac 100644--- a/ee/authz/openfgaauthz/provider.go+++ b/ee/authz/openfgaauthz/provider.go@@ -143,6 +143,10 @@ func (provider *provider) List(ctx context.Context, orgID valuer.UUID) ([]*authtreturn provider.pkgAuthzService.List(ctx, orgID)}+func (provider *provider) Collect(ctx context.Context, orgID valuer.UUID) (map[string]any, error) {+ return provider.pkgAuthzService.Collect(ctx, orgID)+}+func (provider *provider) ListByOrgIDAndNames(ctx context.Context, orgID valuer.UUID, names []string) ([]*authtypes.Role, error) {return provider.pkgAuthzService.ListByOrgIDAndNames(ctx, orgID, names)}diff --git a/pkg/authz/authz.go b/pkg/authz/authz.goindex 0a3f0b6d20..cacd1673cf 100644--- a/pkg/authz/authz.go+++ b/pkg/authz/authz.go@@ -66,6 +66,9 @@ type AuthZ interface {// Lists all the roles for the organization.List(context.Context, valuer.UUID) ([]*authtypes.Role, error)+ // Collect returns per-org role usage stats for the stats reporter.+ Collect(context.Context, valuer.UUID) (map[string]any, error)+// Lists all the roles for the organization filtered by nameListByOrgIDAndNames(context.Context, valuer.UUID, []string) ([]*authtypes.Role, error)diff --git a/pkg/authz/openfgaauthz/provider.go b/pkg/authz/openfgaauthz/provider.goindex cee1268e03..f4957048fd 100644--- a/pkg/authz/openfgaauthz/provider.go+++ b/pkg/authz/openfgaauthz/provider.go@@ -95,6 +95,15 @@ func (provider *provider) List(ctx context.Context, orgID valuer.UUID) ([]*authtreturn provider.store.List(ctx, orgID)}+func (provider *provider) Collect(ctx context.Context, orgID valuer.UUID) (map[string]any, error) {+ roles, err := provider.List(ctx, orgID)+ if err != nil {+ return nil, err+ }++ return authtypes.NewStatsFromRoles(roles), nil+}+func (provider *provider) ListByOrgIDAndNames(ctx context.Context, orgID valuer.UUID, names []string) ([]*authtypes.Role, error) {return provider.store.ListByOrgIDAndNames(ctx, orgID, names)}diff --git a/pkg/signoz/signoz.go b/pkg/signoz/signoz.goindex 8e80795f2b..4fbe42377b 100644--- a/pkg/signoz/signoz.go+++ b/pkg/signoz/signoz.go@@ -501,6 +501,7 @@ func New(modules.LogsPipeline,modules.InfraMonitoring,querier,+ authz,}// Initialize the stats aggregator (always-on, independent of whether reporting is enabled)diff --git a/pkg/types/authtypes/role.go b/pkg/types/authtypes/role.goindex e005a07027..eb99fa619f 100644--- a/pkg/types/authtypes/role.go+++ b/pkg/types/authtypes/role.go@@ -135,6 +135,20 @@ func NewManagedRoles(orgID valuer.UUID) []*Role {}+func NewStatsFromRoles(roles []*Role) map[string]any {+ stats := make(map[string]any)+ for _, role := range roles {+ key := "role." + role.Type.StringValue() + ".count"+ if value, ok := stats[key]; ok {+ stats[key] = value.(int64) + 1+ } else {+ stats[key] = int64(1)+ }+ }+ stats["role.count"] = int64(len(roles))+ return stats+}+func (role *Role) PatchMetadata(description string) error {err := role.ErrIfManaged()if err != nil {