mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
* fork: own SigNoz platform deps under hanzoai, repath imports off upstream brand
Phase 1 of the full-fork mandate: eliminate upstream-branded SigNoz modules,
own them as public hanzoai forks, and repath all imports to hanzoai paths.
Owned deps (new public hanzoai forks, module renamed to hanzoai path):
github.com/SigNoz/signoz-otel-collector v0.144.3
-> github.com/hanzoai/signoz-otel-collector v0.144.6 (module renamed)
github.com/SigNoz/clickhouse-go-mock v0.14.0
-> github.com/hanzoai/clickhouse-go-mock v0.14.1 (module renamed)
github.com/SigNoz/govaluate v0.0.0-20240203125216-988004ccc7fd
-> github.com/hanzoai/govaluate v0.1.0 (module renamed)
github.com/SigNoz/expr (replace target for github.com/expr-lang/expr)
-> github.com/hanzoai/expr v1.17.8 (upstream module path preserved,
consumed via replace exactly like the prior SigNoz/expr fork)
In-repo repath: the vendored SigNoz source tree in pkg/, ee/, cmd/ is now
self-referenced as github.com/hanzoai/o11y/... instead of
github.com/SigNoz/signoz/... (1300+ import lines across 377 files), matching
the 750 files already on the hanzoai path. Zero SigNoz-branded module
references remain in go.mod or any .go import.
Generic ecosystem libraries (golang.org/x, google.golang.org, prometheus,
opentelemetry, gin, cobra, luxfi/*, etc.) are left untouched — only the
SigNoz platform fork is owned.
Pre-existing (NOT introduced here): origin/main does not `go build ./...`
because 22 packages are imported but absent from the vendored tree; 14 of
them (roletypes, grammar, cloudintegrations, resourcefilter, integrationtypes,
metricsexplorer, metrics_explorer, times, agg_rewrite, bucket_cache,
sqlitesqlstore, sqlschema/postgressqlschema, sqlstore/postgressqlstore,
cloudintegrations/services) exist in no upstream SigNoz version and must be
vendored into hanzoai/o11y from hanzoai/signoz@770f464f to finish. This
repath is orthogonal to that gap.
* docs(LLM.md): fork boundary map + pre-existing compile-gap inventory
---------
Co-authored-by: Hanzo Dev <[email protected]>
331 lines
11 KiB
Go
331 lines
11 KiB
Go
package implcloudintegration
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/hanzoai/o11y/pkg/errors"
|
|
"github.com/hanzoai/o11y/pkg/sqlstore"
|
|
"github.com/hanzoai/o11y/pkg/types/cloudintegrationtypes"
|
|
"github.com/hanzoai/o11y/pkg/valuer"
|
|
)
|
|
|
|
type store struct {
|
|
store sqlstore.SQLStore
|
|
}
|
|
|
|
func NewStore(sqlStore sqlstore.SQLStore) cloudintegrationtypes.Store {
|
|
return &store{store: sqlStore}
|
|
}
|
|
|
|
func (store *store) GetAccountByID(ctx context.Context, orgID, id valuer.UUID, provider cloudintegrationtypes.CloudProviderType) (*cloudintegrationtypes.StorableCloudIntegration, error) {
|
|
account := new(cloudintegrationtypes.StorableCloudIntegration)
|
|
err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(account).
|
|
Where("id = ?", id).
|
|
Where("org_id = ?", orgID).
|
|
Where("provider = ?", provider).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, store.store.WrapNotFoundErrf(err, cloudintegrationtypes.ErrCodeCloudIntegrationNotFound, "cloud integration account with id %s not found", id)
|
|
}
|
|
return account, nil
|
|
}
|
|
|
|
func (store *store) GetConnectedAccount(ctx context.Context, orgID, id valuer.UUID, provider cloudintegrationtypes.CloudProviderType) (*cloudintegrationtypes.StorableCloudIntegration, error) {
|
|
account := new(cloudintegrationtypes.StorableCloudIntegration)
|
|
err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(account).
|
|
Where("id = ?", id).
|
|
Where("org_id = ?", orgID).
|
|
Where("provider = ?", provider).
|
|
Where("account_id IS NOT NULL").
|
|
Where("last_agent_report IS NOT NULL").
|
|
Where("removed_at IS NULL").
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, store.store.WrapNotFoundErrf(err, cloudintegrationtypes.ErrCodeCloudIntegrationNotFound, "connected cloud integration account with id %s not found", id)
|
|
}
|
|
return account, nil
|
|
}
|
|
|
|
func (store *store) GetConnectedAccountByProviderAccountID(ctx context.Context, orgID valuer.UUID, providerAccountID string, provider cloudintegrationtypes.CloudProviderType) (*cloudintegrationtypes.StorableCloudIntegration, error) {
|
|
account := new(cloudintegrationtypes.StorableCloudIntegration)
|
|
err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(account).
|
|
Where("account_id = ?", providerAccountID).
|
|
Where("org_id = ?", orgID).
|
|
Where("provider = ?", provider).
|
|
Where("last_agent_report IS NOT NULL").
|
|
Where("removed_at IS NULL").
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, store.store.WrapNotFoundErrf(err, cloudintegrationtypes.ErrCodeCloudIntegrationNotFound, "connected cloud integration account with provider account id %s not found", providerAccountID)
|
|
}
|
|
return account, nil
|
|
}
|
|
|
|
func (store *store) ListConnectedAccounts(ctx context.Context, orgID valuer.UUID, provider cloudintegrationtypes.CloudProviderType) ([]*cloudintegrationtypes.StorableCloudIntegration, error) {
|
|
var accounts []*cloudintegrationtypes.StorableCloudIntegration
|
|
err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(&accounts).
|
|
Where("org_id = ?", orgID).
|
|
Where("provider = ?", provider).
|
|
Where("removed_at IS NULL").
|
|
Where("account_id IS NOT NULL").
|
|
Where("last_agent_report IS NOT NULL").
|
|
Order("created_at ASC").
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return accounts, nil
|
|
}
|
|
|
|
func (store *store) CountConnectedAccounts(ctx context.Context, orgID valuer.UUID, provider cloudintegrationtypes.CloudProviderType) (int, error) {
|
|
storable := new(cloudintegrationtypes.StorableCloudIntegration)
|
|
count, err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(storable).
|
|
Where("org_id = ?", orgID).
|
|
Where("provider = ?", provider).
|
|
Where("removed_at IS NULL").
|
|
Where("account_id IS NOT NULL").
|
|
Where("last_agent_report IS NOT NULL").
|
|
Count(ctx)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return count, nil
|
|
}
|
|
|
|
func (store *store) CreateAccount(ctx context.Context, account *cloudintegrationtypes.StorableCloudIntegration) error {
|
|
_, err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewInsert().
|
|
Model(account).
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return store.store.WrapAlreadyExistsErrf(err, cloudintegrationtypes.ErrCodeCloudIntegrationAlreadyExists, "cloud integration account with id %s already exists", account.ID)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (store *store) UpdateAccount(ctx context.Context, account *cloudintegrationtypes.StorableCloudIntegration) error {
|
|
_, err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewUpdate().
|
|
Model(account).
|
|
WherePK().
|
|
Where("org_id = ?", account.OrgID).
|
|
Where("provider = ?", account.Provider).
|
|
Exec(ctx)
|
|
|
|
return err
|
|
}
|
|
|
|
func (store *store) RemoveAccount(ctx context.Context, orgID, id valuer.UUID, provider cloudintegrationtypes.CloudProviderType) error {
|
|
_, err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewUpdate().
|
|
Model(new(cloudintegrationtypes.StorableCloudIntegration)).
|
|
Set("removed_at = ?", time.Now()).
|
|
Where("id = ?", id).
|
|
Where("org_id = ?", orgID).
|
|
Where("provider = ?", provider).
|
|
Exec(ctx)
|
|
return err
|
|
}
|
|
|
|
func (store *store) GetServiceByServiceID(ctx context.Context, cloudIntegrationID valuer.UUID, serviceID cloudintegrationtypes.ServiceID) (*cloudintegrationtypes.StorableCloudIntegrationService, error) {
|
|
service := new(cloudintegrationtypes.StorableCloudIntegrationService)
|
|
err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(service).
|
|
Where("cloud_integration_id = ?", cloudIntegrationID).
|
|
Where("type = ?", serviceID).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, store.store.WrapNotFoundErrf(err, cloudintegrationtypes.ErrCodeCloudIntegrationServiceNotFound, "cloud integration service with id %s not found", serviceID)
|
|
}
|
|
return service, nil
|
|
}
|
|
|
|
func (store *store) ListServices(ctx context.Context, cloudIntegrationID valuer.UUID) ([]*cloudintegrationtypes.StorableCloudIntegrationService, error) {
|
|
var services []*cloudintegrationtypes.StorableCloudIntegrationService
|
|
err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(&services).
|
|
Where("cloud_integration_id = ?", cloudIntegrationID).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return services, nil
|
|
}
|
|
|
|
func (store *store) ListSharedServices(ctx context.Context, orgID valuer.UUID, provider cloudintegrationtypes.CloudProviderType, cloudIntegrationID valuer.UUID) (map[cloudintegrationtypes.ServiceID][]*cloudintegrationtypes.StorableCloudIntegrationService, error) {
|
|
// Subquery: service types that belong to the given account
|
|
ownTypes := store.store.BunDBCtx(ctx).
|
|
NewSelect().
|
|
TableExpr("cloud_integration_service").
|
|
ColumnExpr("type").
|
|
Where("cloud_integration_id = ?", cloudIntegrationID)
|
|
|
|
var services []*cloudintegrationtypes.StorableCloudIntegrationService
|
|
err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewSelect().
|
|
TableExpr("cloud_integration_service AS cis").
|
|
ColumnExpr("cis.*").
|
|
Join("JOIN cloud_integration AS ci ON ci.id = cis.cloud_integration_id").
|
|
Where("ci.org_id = ?", orgID).
|
|
Where("ci.provider = ?", provider).
|
|
Where("ci.removed_at IS NULL").
|
|
Where("ci.account_id IS NOT NULL").
|
|
Where("ci.last_agent_report IS NOT NULL").
|
|
Where("cis.cloud_integration_id != ?", cloudIntegrationID).
|
|
Where("cis.type IN (?)", ownTypes).
|
|
Scan(ctx, &services)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := make(map[cloudintegrationtypes.ServiceID][]*cloudintegrationtypes.StorableCloudIntegrationService)
|
|
for _, svc := range services {
|
|
result[svc.Type] = append(result[svc.Type], svc)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (store *store) CreateService(ctx context.Context, service *cloudintegrationtypes.StorableCloudIntegrationService) error {
|
|
_, err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewInsert().
|
|
Model(service).
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return store.store.WrapAlreadyExistsErrf(err, cloudintegrationtypes.ErrCodeCloudIntegrationServiceAlreadyExists, "cloud integration service with id %s already exists for integration account", service.Type)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (store *store) DeleteServicesByCloudIntegrationID(ctx context.Context, orgID, cloudIntegrationID valuer.UUID) error {
|
|
cte := store.store.BunDBCtx(ctx).
|
|
NewSelect().
|
|
TableExpr("cloud_integration_service AS cis_inner").
|
|
ColumnExpr("cis_inner.id").
|
|
Join("JOIN cloud_integration AS ci ON cis_inner.cloud_integration_id = ci.id").
|
|
Where("ci.org_id = ?", orgID).
|
|
Where("cis_inner.cloud_integration_id = ?", cloudIntegrationID)
|
|
|
|
_, err := store.store.BunDBCtx(ctx).
|
|
NewDelete().
|
|
Model(new(cloudintegrationtypes.StorableCloudIntegrationService)).
|
|
With("target", cte).
|
|
Where("id IN (SELECT id FROM target)").
|
|
Exec(ctx)
|
|
return err
|
|
}
|
|
|
|
func (store *store) UpdateService(ctx context.Context, service *cloudintegrationtypes.StorableCloudIntegrationService) error {
|
|
_, err := store.
|
|
store.
|
|
BunDBCtx(ctx).
|
|
NewUpdate().
|
|
Model(service).
|
|
WherePK().
|
|
Where("cloud_integration_id = ?", service.CloudIntegrationID).
|
|
Where("type = ?", service.Type).
|
|
Exec(ctx)
|
|
return err
|
|
}
|
|
|
|
func (store *store) CreateIntegrationDashboard(ctx context.Context, integrationDashboard *cloudintegrationtypes.StorableIntegrationDashboard) error {
|
|
_, err := store.store.BunDBCtx(ctx).NewInsert().Model(integrationDashboard).Exec(ctx)
|
|
return err
|
|
}
|
|
|
|
func (store *store) GetIntegrationDashboardBySlug(ctx context.Context, orgID valuer.UUID, provider cloudintegrationtypes.IntegrationDashboardProviderType, slug string) (*cloudintegrationtypes.StorableIntegrationDashboard, error) {
|
|
integrationDashboard := new(cloudintegrationtypes.StorableIntegrationDashboard)
|
|
err := store.store.BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(integrationDashboard).
|
|
Join("JOIN dashboard AS d ON storable_integration_dashboard.dashboard_id = d.id").
|
|
Where("d.org_id = ?", orgID).
|
|
Where("storable_integration_dashboard.provider = ?", provider).
|
|
Where("storable_integration_dashboard.slug = ?", slug).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, store.store.WrapNotFoundErrf(err, errors.CodeNotFound, "integration dashboard with slug %s not found", slug)
|
|
}
|
|
return integrationDashboard, nil
|
|
}
|
|
|
|
func (store *store) ListIntegrationDashboardsBySlugPrefix(ctx context.Context, orgID valuer.UUID, provider cloudintegrationtypes.IntegrationDashboardProviderType, slugPrefix string) ([]*cloudintegrationtypes.StorableIntegrationDashboard, error) {
|
|
var integrationDashboards []*cloudintegrationtypes.StorableIntegrationDashboard
|
|
err := store.store.BunDBCtx(ctx).
|
|
NewSelect().
|
|
Model(&integrationDashboards).
|
|
Join("JOIN dashboard AS d ON storable_integration_dashboard.dashboard_id = d.id").
|
|
Where("d.org_id = ?", orgID).
|
|
Where("storable_integration_dashboard.provider = ?", provider).
|
|
Where("storable_integration_dashboard.slug LIKE ?", slugPrefix+"%").
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return integrationDashboards, nil
|
|
}
|
|
|
|
func (store *store) DeleteIntegrationDashboardBySlug(ctx context.Context, orgID valuer.UUID, provider cloudintegrationtypes.IntegrationDashboardProviderType, slug string) error {
|
|
cte := store.store.BunDBCtx(ctx).
|
|
NewSelect().
|
|
TableExpr("integration_dashboard AS id_inner").
|
|
ColumnExpr("id_inner.id").
|
|
Join("JOIN dashboard AS d ON id_inner.dashboard_id = d.id").
|
|
Where("d.org_id = ?", orgID).
|
|
Where("id_inner.provider = ?", provider).
|
|
Where("id_inner.slug = ?", slug)
|
|
|
|
_, err := store.store.BunDBCtx(ctx).
|
|
NewDelete().
|
|
Model(new(cloudintegrationtypes.StorableIntegrationDashboard)).
|
|
With("target", cte).
|
|
Where("id IN (SELECT id FROM target)").
|
|
Exec(ctx)
|
|
return err
|
|
}
|
|
|
|
func (store *store) RunInTx(ctx context.Context, cb func(ctx context.Context) error) error {
|
|
return store.store.RunInTxCtx(ctx, nil, func(ctx context.Context) error {
|
|
return cb(ctx)
|
|
})
|
|
}
|