mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
Re-sync the entire SigNoz-derived Go tree to a clean fork of latest SigNoz main (upstream 3e6339019), eliminating the version-skew that broke `go build ./...` (mixed-era packages, ~14 imported-but-absent packages, partial signoz->o11y / clickhouse->datastore rebrands, self-import cycle, duplicate package decls). - pkg/ + cmd/ wholesale replaced with latest SigNoz; imports rewritten github.com/SigNoz/signoz/ -> github.com/hanzoai/o11y/. - Adopt SigNoz's CURRENT structure (resourcefilter->telemetryresourcefilter, integrationtypes->cloudintegrationtypes, roletypes/grammar/times folded in upstream); old paths dropped. - Fork deps repathed to hanzoai + bumped: signoz-otel-collector v0.144.6, clickhouse-go-mock v0.14.1, govaluate v0.1.0; expr-lang/expr => hanzoai/expr v1.17.8 (replace). go.mod reconciled from latest SigNoz; go.sum re-tidied. - ee/ + cmd/enterprise stripped — o11y stays MIT-only; community edition imports no ee packages. - Preserved o11y additions: module path github.com/hanzoai/o11y, mount.go (cloud.Register/zip mount adapter, HIP-0106), NOTICE + LICENSE (SigNoz §4c attribution retained; upstream pkg files are headerless per SigNoz convention). - Reverted o11y cosmetic renames (o11y*/datastore*) and experimental originals (authz/iamauthz, billing, zapreceiver, zapmetricreceiver) to SigNoz canonical to kill the skew; snapshots retained in git history for re-layering. go build ./... = exit 0. go vet clean except benign "unreachable code" in generated ANTLR parser files (inherited from upstream).
170 lines
5.2 KiB
Go
170 lines
5.2 KiB
Go
package implspanmapper
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/hanzoai/o11y/pkg/flagger"
|
|
"github.com/hanzoai/o11y/pkg/modules/spanmapper"
|
|
"github.com/hanzoai/o11y/pkg/query-service/agentConf"
|
|
"github.com/hanzoai/o11y/pkg/types/featuretypes"
|
|
"github.com/hanzoai/o11y/pkg/types/opamptypes"
|
|
"github.com/hanzoai/o11y/pkg/types/spantypes"
|
|
"github.com/hanzoai/o11y/pkg/valuer"
|
|
)
|
|
|
|
type module struct {
|
|
store spantypes.SpanMapperStore
|
|
flagger flagger.Flagger
|
|
}
|
|
|
|
func NewModule(store spantypes.SpanMapperStore, flagger flagger.Flagger) spanmapper.Module {
|
|
return &module{store: store, flagger: flagger}
|
|
}
|
|
|
|
func (module *module) ListGroups(ctx context.Context, orgID valuer.UUID, q *spantypes.ListSpanMapperGroupsQuery) ([]*spantypes.SpanMapperGroup, error) {
|
|
return module.store.ListGroups(ctx, orgID, q)
|
|
}
|
|
|
|
func (module *module) GetGroup(ctx context.Context, orgID, id valuer.UUID) (*spantypes.SpanMapperGroup, error) {
|
|
return module.store.GetGroup(ctx, orgID, id)
|
|
}
|
|
|
|
func (module *module) CreateGroup(ctx context.Context, orgID valuer.UUID, group *spantypes.SpanMapperGroup) error {
|
|
return module.store.CreateGroup(ctx, group)
|
|
}
|
|
|
|
func (module *module) UpdateGroup(ctx context.Context, orgID, id valuer.UUID, name *string, condition *spantypes.SpanMapperGroupCondition, enabled *bool, updatedBy string) error {
|
|
group, err := module.store.GetGroup(ctx, orgID, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
group.Update(name, condition, enabled, updatedBy)
|
|
|
|
err = module.store.UpdateGroup(ctx, group)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
agentConf.NotifyConfigUpdate(ctx)
|
|
return nil
|
|
}
|
|
|
|
func (module *module) DeleteGroup(ctx context.Context, orgID, id valuer.UUID) error {
|
|
err := module.store.DeleteGroup(ctx, orgID, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
agentConf.NotifyConfigUpdate(ctx)
|
|
return nil
|
|
}
|
|
|
|
func (module *module) ListMappers(ctx context.Context, orgID, groupID valuer.UUID) ([]*spantypes.SpanMapper, error) {
|
|
return module.store.ListMappers(ctx, orgID, groupID)
|
|
}
|
|
|
|
func (module *module) GetMapper(ctx context.Context, orgID, groupID, id valuer.UUID) (*spantypes.SpanMapper, error) {
|
|
return module.store.GetMapper(ctx, orgID, groupID, id)
|
|
}
|
|
|
|
func (module *module) CreateMapper(ctx context.Context, orgID, groupID valuer.UUID, mapper *spantypes.SpanMapper) error {
|
|
// Ensure the group belongs to the org before inserting the child row.
|
|
if _, err := module.store.GetGroup(ctx, orgID, groupID); err != nil {
|
|
return err
|
|
}
|
|
err := module.store.CreateMapper(ctx, mapper)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
agentConf.NotifyConfigUpdate(ctx)
|
|
return nil
|
|
}
|
|
|
|
func (module *module) UpdateMapper(ctx context.Context, orgID, groupID, id valuer.UUID, fieldContext spantypes.FieldContext, config *spantypes.SpanMapperConfig, enabled *bool, updatedBy string) error {
|
|
if _, err := module.store.GetGroup(ctx, orgID, groupID); err != nil {
|
|
return err
|
|
}
|
|
mapper, err := module.store.GetMapper(ctx, orgID, groupID, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
mapper.Update(fieldContext, config, enabled, updatedBy)
|
|
err = module.store.UpdateMapper(ctx, mapper)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
agentConf.NotifyConfigUpdate(ctx)
|
|
return nil
|
|
}
|
|
|
|
func (module *module) DeleteMapper(ctx context.Context, orgID, groupID, id valuer.UUID) error {
|
|
err := module.store.DeleteMapper(ctx, orgID, groupID, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
agentConf.NotifyConfigUpdate(ctx)
|
|
return nil
|
|
}
|
|
|
|
func (module *module) AgentFeatureType() agentConf.AgentFeatureType {
|
|
return spantypes.SpanAttrMappingFeatureType
|
|
}
|
|
|
|
func (module *module) RecommendAgentConfig(orgID valuer.UUID, currentConfYaml []byte, configVersion *opamptypes.AgentConfigVersion) ([]byte, string, error) {
|
|
ctx := context.Background()
|
|
|
|
// Skip the llm pricing processor unless AI observability is enabled for the org.
|
|
evalCtx := featuretypes.NewFlaggerEvaluationContext(orgID)
|
|
enabled, err := module.flagger.Boolean(ctx, flagger.FeatureEnableAIObservability, evalCtx)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
if !enabled {
|
|
return currentConfYaml, "", nil
|
|
}
|
|
|
|
enabledMappers, err := module.listEnabledGroupsWithMappers(ctx, orgID)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
|
|
updatedConf, err := spantypes.GenerateCollectorConfigWithSpanMapperProcessor(currentConfYaml, enabledMappers)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
|
|
serialized, err := json.Marshal(enabled)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
|
|
return updatedConf, string(serialized), nil
|
|
}
|
|
|
|
// listEnabledGroupsWithMappers returns groups with their mappers.
|
|
func (module *module) listEnabledGroupsWithMappers(ctx context.Context, orgID valuer.UUID) ([]*spantypes.SpanMapperGroupWithMappers, error) {
|
|
enabled := true
|
|
groups, err := module.store.ListGroups(ctx, orgID, &spantypes.ListSpanMapperGroupsQuery{Enabled: &enabled})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out := make([]*spantypes.SpanMapperGroupWithMappers, 0, len(groups))
|
|
for _, g := range groups {
|
|
mappers, err := module.store.ListMappers(ctx, orgID, g.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
enabledMappers := make([]*spantypes.SpanMapper, 0, len(mappers))
|
|
for _, m := range mappers {
|
|
if m.Enabled {
|
|
enabledMappers = append(enabledMappers, m)
|
|
}
|
|
}
|
|
if len(enabledMappers) == 0 {
|
|
continue
|
|
}
|
|
out = append(out, &spantypes.SpanMapperGroupWithMappers{Group: g, Mappers: enabledMappers})
|
|
}
|
|
return out, nil
|
|
}
|