mirror of
https://github.com/SigNoz/signoz.git
synced 2026-09-22 03:10:41 +01:00
<!--A few plain bullets saying what changed and why, for a reviewer skimming it - not a wall of text, not a restatement of the diff, not generated boilerplate.--> #### Description Until now every org started with no span mapper groups and we had to create `llm`, `agent` and `tool` by hand. This PR ships them as defaults. - The three groups live as JSON in the binary. On startup and when a new org is created, they get seeded. When we change a definition and bump its version, the next release updates the org's copy in place. - Anything SigNoz ships is marked `origin: system` and can only be switched on or off. Users can't rename or delete these groups and mappers, and can't take their names. Anything the user adds is theirs to edit or remove, including new mappers in a shipped group or new sources on a shipped mapper. - Upgrades keep the user's on/off choices and never touch their items. - Condition substrings and sources now carry `enabled` and `origin`, so a substring is an object instead of a plain string. Disabled ones are left out of the collector config. - - Migration 127 only adds the `origin` and `version` columns. Stored JSON is not rewritten because these tables are empty on every instance. - Fixes creating a group or mapper with `enabled: false` being saved as true (the bun `default:true` tag turned false into SQL `DEFAULT`) Frontend: no UI changes. Generated client regenerated; drafts carry `enabled` and `origin` so saves from the existing screens round-trip shipped items intact. <!--Reference issues using `Closes #issue-number` to enable automatic closure on merge. --> #### Issues closed by this PR Closes https://github.com/SigNoz/engineering-pod/issues/5329 <!--Anything reviewers should keep in mind while reviewing --> #### Additional Information * Frontend follow-up: toggles for sources and substrings, "Default" badge and read-only rows for shipped items, hide rename/delete on system groups and mappers. * Deferred: per-group upgrade changelog ( will come back to this later) --------- Co-authored-by: Gaurav Tewari <gauravtewari111@gmail.com> Co-authored-by: Gaurav Tewari <tewarig@users.noreply.github.com>
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package implspanmapper
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"github.com/SigNoz/signoz/pkg/errors"
|
|
"github.com/SigNoz/signoz/pkg/factory"
|
|
"github.com/SigNoz/signoz/pkg/modules/organization"
|
|
"github.com/SigNoz/signoz/pkg/modules/spanmapper"
|
|
)
|
|
|
|
const reconcileRetryInterval = 30 * time.Second
|
|
|
|
type service struct {
|
|
settings factory.ScopedProviderSettings
|
|
module spanmapper.Module
|
|
orgGetter organization.Getter
|
|
stopC chan struct{}
|
|
healthyC chan struct{}
|
|
}
|
|
|
|
// NewService reconciles every org's default mapping groups once at startup.
|
|
// Orgs created later are reconciled by the organization setter instead.
|
|
func NewService(providerSettings factory.ProviderSettings, module spanmapper.Module, orgGetter organization.Getter) factory.Service {
|
|
return &service{
|
|
settings: factory.NewScopedProviderSettings(providerSettings, "github.com/SigNoz/signoz/pkg/modules/spanmapper/implspanmapper"),
|
|
module: module,
|
|
orgGetter: orgGetter,
|
|
stopC: make(chan struct{}),
|
|
healthyC: make(chan struct{}),
|
|
}
|
|
}
|
|
|
|
func (service *service) Start(ctx context.Context) error {
|
|
ticker := time.NewTicker(reconcileRetryInterval)
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
err := service.reconcile(ctx)
|
|
if err == nil {
|
|
close(service.healthyC)
|
|
<-service.stopC
|
|
return nil
|
|
}
|
|
|
|
service.settings.Logger().WarnContext(ctx, "default span mapper group reconciliation failed, retrying", errors.Attr(err))
|
|
|
|
select {
|
|
case <-service.stopC:
|
|
return nil
|
|
case <-ticker.C:
|
|
}
|
|
}
|
|
}
|
|
|
|
func (service *service) Healthy() <-chan struct{} {
|
|
return service.healthyC
|
|
}
|
|
|
|
func (service *service) Stop(_ context.Context) error {
|
|
close(service.stopC)
|
|
return nil
|
|
}
|
|
|
|
func (service *service) reconcile(ctx context.Context) error {
|
|
orgs, err := service.orgGetter.ListByOwnedKeyRange(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, org := range orgs {
|
|
if err := service.module.ReconcileSystemGroups(ctx, org.ID); err != nil {
|
|
return errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, "couldn't reconcile default span mapper groups for org %s", org.ID.StringValue())
|
|
}
|
|
}
|
|
|
|
service.settings.Logger().InfoContext(ctx, "default span mapper group reconciliation completed", slog.Int("orgs", len(orgs)))
|
|
return nil
|
|
}
|