mongo

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package mongo provides a MongoDB implementation of the store.Store interface.

MongoDB is a document database that stores data as flexible BSON documents. This implementation uses the official MongoDB Go driver v2 and maps each domain entity type to a dedicated collection with appropriate indexes. It is suitable for production deployments requiring horizontal scalability and flexible schema evolution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	URI         string        `env:"CP_MONGO_URI"  json:"uri"`
	Database    string        `default:"ctrlplane" env:"CP_MONGO_DATABASE"      json:"database"`
	MaxPoolSize uint64        `default:"100"       env:"CP_MONGO_MAX_POOL_SIZE" json:"max_pool_size"`
	MinPoolSize uint64        `default:"10"        env:"CP_MONGO_MIN_POOL_SIZE" json:"min_pool_size"`
	Timeout     time.Duration `default:"10s"       env:"CP_MONGO_TIMEOUT"       json:"timeout"`
}

Config holds the configuration for the MongoDB store.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a MongoDB-backed implementation of store.Store.

func New

func New(cfg Config) (*Store, error)

New creates a new MongoDB store and establishes a connection.

func (*Store) Close

func (s *Store) Close() error

Close disconnects from MongoDB.

func (*Store) CountByTenant

func (s *Store) CountByTenant(ctx context.Context, tenantID string) (int, error)

CountByTenant returns the total number of instances for a tenant.

func (*Store) CountDomainsByTenant

func (s *Store) CountDomainsByTenant(ctx context.Context, tenantID string) (int, error)

CountDomainsByTenant returns the number of domains for a tenant.

func (*Store) CountSecretsByTenant

func (s *Store) CountSecretsByTenant(ctx context.Context, tenantID string) (int, error)

CountSecretsByTenant returns the number of secrets for a tenant.

func (*Store) CountTenants

func (s *Store) CountTenants(ctx context.Context) (int, error)

CountTenants returns the total number of tenants.

func (*Store) CountTenantsByStatus

func (s *Store) CountTenantsByStatus(ctx context.Context, status admin.TenantStatus) (int, error)

CountTenantsByStatus returns the number of tenants in a given status.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, tenantID string, instanceID id.ID) error

Delete removes an instance from the store.

func (*Store) DeleteCertificate

func (s *Store) DeleteCertificate(ctx context.Context, tenantID string, certID id.ID) error

DeleteCertificate removes a certificate.

func (*Store) DeleteCheck

func (s *Store) DeleteCheck(ctx context.Context, tenantID string, checkID id.ID) error

DeleteCheck removes a health check.

func (*Store) DeleteDomain

func (s *Store) DeleteDomain(ctx context.Context, tenantID string, domainID id.ID) error

DeleteDomain removes a domain.

func (*Store) DeleteRoute

func (s *Store) DeleteRoute(ctx context.Context, tenantID string, routeID id.ID) error

DeleteRoute removes a route.

func (*Store) DeleteSecret

func (s *Store) DeleteSecret(ctx context.Context, tenantID string, instanceID id.ID, key string) error

DeleteSecret removes a secret by instance ID and key.

func (*Store) DeleteTenant

func (s *Store) DeleteTenant(ctx context.Context, tenantID string) error

DeleteTenant removes a tenant.

func (*Store) GetByID

func (s *Store) GetByID(ctx context.Context, tenantID string, instanceID id.ID) (*instance.Instance, error)

GetByID retrieves an instance by its ID within a tenant.

func (*Store) GetBySlug

func (s *Store) GetBySlug(ctx context.Context, tenantID string, slug string) (*instance.Instance, error)

GetBySlug retrieves an instance by its slug within a tenant.

func (*Store) GetCertificate

func (s *Store) GetCertificate(ctx context.Context, tenantID string, certID id.ID) (*network.Certificate, error)

GetCertificate retrieves a certificate by ID.

func (*Store) GetCheck

func (s *Store) GetCheck(ctx context.Context, tenantID string, checkID id.ID) (*health.HealthCheck, error)

GetCheck retrieves a health check by ID.

func (*Store) GetDeployment

func (s *Store) GetDeployment(ctx context.Context, tenantID string, deployID id.ID) (*deploy.Deployment, error)

GetDeployment retrieves a deployment by ID within a tenant.

func (*Store) GetDomain

func (s *Store) GetDomain(ctx context.Context, tenantID string, domainID id.ID) (*network.Domain, error)

GetDomain retrieves a domain by ID.

func (*Store) GetDomainByHostname

func (s *Store) GetDomainByHostname(ctx context.Context, hostname string) (*network.Domain, error)

GetDomainByHostname retrieves a domain by its hostname.

func (*Store) GetLatestResourceSnapshot

func (s *Store) GetLatestResourceSnapshot(ctx context.Context, tenantID string, instanceID id.ID) (*telemetry.ResourceSnapshot, error)

GetLatestResourceSnapshot returns the most recent snapshot for an instance.

func (*Store) GetLatestResult

func (s *Store) GetLatestResult(ctx context.Context, tenantID string, checkID id.ID) (*health.HealthResult, error)

GetLatestResult returns the most recent result for a check.

func (*Store) GetRelease

func (s *Store) GetRelease(ctx context.Context, tenantID string, releaseID id.ID) (*deploy.Release, error)

GetRelease retrieves a release by ID within a tenant.

func (*Store) GetRoute

func (s *Store) GetRoute(ctx context.Context, tenantID string, routeID id.ID) (*network.Route, error)

GetRoute retrieves a route by ID.

func (*Store) GetSecretByKey

func (s *Store) GetSecretByKey(ctx context.Context, tenantID string, instanceID id.ID, key string) (*secrets.Secret, error)

GetSecretByKey retrieves a secret by instance ID and key.

func (*Store) GetTenant

func (s *Store) GetTenant(ctx context.Context, tenantID string) (*admin.Tenant, error)

GetTenant retrieves a tenant by ID.

func (*Store) GetTenantBySlug

func (s *Store) GetTenantBySlug(ctx context.Context, slug string) (*admin.Tenant, error)

GetTenantBySlug retrieves a tenant by slug.

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, inst *instance.Instance) error

Insert persists a new instance.

func (*Store) InsertAuditEntry

func (s *Store) InsertAuditEntry(ctx context.Context, entry *admin.AuditEntry) error

InsertAuditEntry persists an audit log entry.

func (*Store) InsertCertificate

func (s *Store) InsertCertificate(ctx context.Context, cert *network.Certificate) error

InsertCertificate persists a new certificate.

func (*Store) InsertCheck

func (s *Store) InsertCheck(ctx context.Context, check *health.HealthCheck) error

InsertCheck persists a new health check configuration.

func (*Store) InsertDeployment

func (s *Store) InsertDeployment(ctx context.Context, d *deploy.Deployment) error

InsertDeployment persists a new deployment.

func (*Store) InsertDomain

func (s *Store) InsertDomain(ctx context.Context, domain *network.Domain) error

InsertDomain persists a new domain.

func (*Store) InsertLogs

func (s *Store) InsertLogs(ctx context.Context, logs []telemetry.LogEntry) error

InsertLogs persists log entries.

func (*Store) InsertMetrics

func (s *Store) InsertMetrics(ctx context.Context, metrics []telemetry.Metric) error

InsertMetrics persists metric data points.

func (*Store) InsertRelease

func (s *Store) InsertRelease(ctx context.Context, r *deploy.Release) error

InsertRelease persists a new release.

func (*Store) InsertResourceSnapshot

func (s *Store) InsertResourceSnapshot(ctx context.Context, snap *telemetry.ResourceSnapshot) error

InsertResourceSnapshot persists a resource snapshot.

func (*Store) InsertResult

func (s *Store) InsertResult(ctx context.Context, result *health.HealthResult) error

InsertResult persists a health check result.

func (*Store) InsertRoute

func (s *Store) InsertRoute(ctx context.Context, route *network.Route) error

InsertRoute persists a new route.

func (*Store) InsertSecret

func (s *Store) InsertSecret(ctx context.Context, secret *secrets.Secret) error

InsertSecret persists a new secret.

func (*Store) InsertTenant

func (s *Store) InsertTenant(ctx context.Context, tenant *admin.Tenant) error

InsertTenant persists a new tenant.

func (*Store) InsertTraces

func (s *Store) InsertTraces(ctx context.Context, traces []telemetry.Trace) error

InsertTraces persists trace spans.

func (*Store) List

func (s *Store) List(ctx context.Context, tenantID string, opts instance.ListOptions) (*instance.ListResult, error)

List returns a filtered, paginated list of instances for a tenant.

func (*Store) ListCertificates

func (s *Store) ListCertificates(ctx context.Context, tenantID string, instanceID id.ID) ([]network.Certificate, error)

ListCertificates returns all certificates for an instance. It looks up domains owned by the instance, then finds certificates by domain IDs.

func (*Store) ListChecks

func (s *Store) ListChecks(ctx context.Context, tenantID string, instanceID id.ID) ([]health.HealthCheck, error)

ListChecks returns all health checks for an instance.

func (*Store) ListDeployments

func (s *Store) ListDeployments(ctx context.Context, tenantID string, instanceID id.ID, opts deploy.ListOptions) (*deploy.DeployListResult, error)

ListDeployments returns a filtered, paginated list of deployments for an instance.

func (*Store) ListDomains

func (s *Store) ListDomains(ctx context.Context, tenantID string, instanceID id.ID) ([]network.Domain, error)

ListDomains returns all domains for an instance.

func (*Store) ListReleases

func (s *Store) ListReleases(ctx context.Context, tenantID string, instanceID id.ID, opts deploy.ListOptions) (*deploy.ReleaseListResult, error)

ListReleases returns a filtered, paginated list of releases for an instance.

func (*Store) ListResourceSnapshots

func (s *Store) ListResourceSnapshots(ctx context.Context, tenantID string, instanceID id.ID, opts telemetry.TimeRange) ([]telemetry.ResourceSnapshot, error)

ListResourceSnapshots returns snapshots for an instance within a time range.

func (*Store) ListResults

func (s *Store) ListResults(ctx context.Context, tenantID string, checkID id.ID, opts health.HistoryOptions) ([]health.HealthResult, error)

ListResults returns health results for a check within a time range.

func (*Store) ListRoutes

func (s *Store) ListRoutes(ctx context.Context, tenantID string, instanceID id.ID) ([]network.Route, error)

ListRoutes returns all routes for an instance.

func (*Store) ListSecrets

func (s *Store) ListSecrets(ctx context.Context, tenantID string, instanceID id.ID) ([]secrets.Secret, error)

ListSecrets returns all secrets for an instance (values omitted).

func (*Store) ListTenants

func (s *Store) ListTenants(ctx context.Context, opts admin.ListTenantsOptions) (*admin.TenantListResult, error)

ListTenants returns tenants with optional filtering.

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Migrate creates collections and indexes.

func (*Store) NextReleaseVersion

func (s *Store) NextReleaseVersion(ctx context.Context, tenantID string, instanceID id.ID) (int, error)

NextReleaseVersion returns the next auto-incrementing version number for an instance.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks database connectivity.

func (*Store) QueryAuditLog

func (s *Store) QueryAuditLog(ctx context.Context, opts admin.AuditQuery) (*admin.AuditResult, error)

QueryAuditLog returns audit entries matching the query.

func (*Store) QueryLogs

func (s *Store) QueryLogs(ctx context.Context, q telemetry.LogQuery) ([]telemetry.LogEntry, error)

QueryLogs returns log entries matching the query parameters.

func (*Store) QueryMetrics

func (s *Store) QueryMetrics(ctx context.Context, q telemetry.MetricQuery) ([]telemetry.Metric, error)

QueryMetrics returns metrics matching the query parameters.

func (*Store) QueryTraces

func (s *Store) QueryTraces(ctx context.Context, q telemetry.TraceQuery) ([]telemetry.Trace, error)

QueryTraces returns traces matching the query parameters.

func (*Store) Update

func (s *Store) Update(ctx context.Context, inst *instance.Instance) error

Update persists changes to an existing instance.

func (*Store) UpdateCertificate

func (s *Store) UpdateCertificate(ctx context.Context, cert *network.Certificate) error

UpdateCertificate persists changes to a certificate.

func (*Store) UpdateCheck

func (s *Store) UpdateCheck(ctx context.Context, check *health.HealthCheck) error

UpdateCheck persists changes to a health check.

func (*Store) UpdateDeployment

func (s *Store) UpdateDeployment(ctx context.Context, d *deploy.Deployment) error

UpdateDeployment persists changes to an existing deployment.

func (*Store) UpdateDomain

func (s *Store) UpdateDomain(ctx context.Context, domain *network.Domain) error

UpdateDomain persists changes to a domain.

func (*Store) UpdateRoute

func (s *Store) UpdateRoute(ctx context.Context, route *network.Route) error

UpdateRoute persists changes to a route.

func (*Store) UpdateSecret

func (s *Store) UpdateSecret(ctx context.Context, secret *secrets.Secret) error

UpdateSecret persists changes to a secret.

func (*Store) UpdateTenant

func (s *Store) UpdateTenant(ctx context.Context, tenant *admin.Tenant) error

UpdateTenant persists changes to a tenant.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL