db

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRefreshInterval = 30
)
View Source
const (
	DeploymentsLastN = 100
)

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
	ErrConflict = errors.New("conflict")
)

Functions

This section is empty.

Types

type ApplicationCategorySettings

type ApplicationCategorySettings struct {
	NotifyOfDeployments bool `json:"notify_of_deployments"`
}

type ApplicationDeployment

type ApplicationDeployment model.ApplicationDeployment

func (*ApplicationDeployment) Migrate

func (ad *ApplicationDeployment) Migrate(m *Migrator) error

type ApplicationSettings

type ApplicationSettings struct {
	Profiling *ApplicationSettingsProfiling `json:"profiling,omitempty"`
	Tracing   *ApplicationSettingsTracing   `json:"tracing,omitempty"`
	Logs      *ApplicationSettingsLogs      `json:"logs,omitempty"`
}

func (*ApplicationSettings) Migrate

func (s *ApplicationSettings) Migrate(m *Migrator) error

type ApplicationSettingsLogs added in v0.20.0

type ApplicationSettingsLogs struct {
	Service string `json:"service"`
}

type ApplicationSettingsProfiling added in v0.27.0

type ApplicationSettingsProfiling struct {
	Service string `json:"service"`
}

type ApplicationSettingsTracing

type ApplicationSettingsTracing struct {
	Service string `json:"service"`
}

type CheckConfigs

type CheckConfigs struct{}

func (*CheckConfigs) Migrate

func (cc *CheckConfigs) Migrate(m *Migrator) error

type DB

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

func NewDB

func NewDB(typ Type, db *sql.DB) *DB

func Open

func Open(dataDir string, pgConnString string) (*DB, error)

func (*DB) CreateOrUpdateIncident

func (db *DB) CreateOrUpdateIncident(projectId ProjectId, appId model.ApplicationId, now timeseries.Time, severity model.Status) (*model.ApplicationIncident, error)

func (*DB) DB

func (db *DB) DB() *sql.DB

func (*DB) DeleteProject

func (db *DB) DeleteProject(id ProjectId) error

func (*DB) GetApplicationDeployments

func (db *DB) GetApplicationDeployments(projectId ProjectId) (map[model.ApplicationId][]*model.ApplicationDeployment, error)

func (*DB) GetApplicationIncidents

func (db *DB) GetApplicationIncidents(projectId ProjectId, from, to timeseries.Time) (map[model.ApplicationId][]*model.ApplicationIncident, error)

func (*DB) GetApplicationSettings

func (db *DB) GetApplicationSettings(projectId ProjectId, appId model.ApplicationId) (*ApplicationSettings, error)

func (*DB) GetCheckConfigs

func (db *DB) GetCheckConfigs(projectId ProjectId) (model.CheckConfigs, error)

func (*DB) GetIncidentByKey

func (db *DB) GetIncidentByKey(projectId ProjectId, key string) (*model.ApplicationIncident, error)

func (*DB) GetNotSentIncidentNotifications

func (db *DB) GetNotSentIncidentNotifications(from timeseries.Time) ([]IncidentNotification, error)

func (*DB) GetPreviousIncidentNotifications

func (db *DB) GetPreviousIncidentNotifications(n IncidentNotification) ([]IncidentNotification, error)

func (*DB) GetProject

func (db *DB) GetProject(id ProjectId) (*Project, error)

func (*DB) GetProjectNames

func (db *DB) GetProjectNames() (map[ProjectId]string, error)

func (*DB) GetProjects

func (db *DB) GetProjects() ([]*Project, error)

func (*DB) GetSentIncidentNotificationsStat

func (db *DB) GetSentIncidentNotificationsStat(from timeseries.Time) map[IntegrationType]int

func (*DB) IsUniqueViolationError

func (db *DB) IsUniqueViolationError(err error) bool

func (*DB) Migrate

func (db *DB) Migrate(tables ...Table) error

func (*DB) MigrateDefault

func (db *DB) MigrateDefault(extraTables ...Table) error

func (*DB) PutIncidentNotification

func (db *DB) PutIncidentNotification(n IncidentNotification)

func (*DB) SaveApplicationCategory

func (db *DB) SaveApplicationCategory(id ProjectId, category, newName model.ApplicationCategory, customPatterns []string, notifyAboutDeployments bool) error

func (*DB) SaveApplicationDeployment

func (db *DB) SaveApplicationDeployment(projectId ProjectId, d *model.ApplicationDeployment) error

func (*DB) SaveApplicationDeploymentMetricsSnapshot

func (db *DB) SaveApplicationDeploymentMetricsSnapshot(projectId ProjectId, d *model.ApplicationDeployment) error

func (*DB) SaveApplicationDeploymentNotifications

func (db *DB) SaveApplicationDeploymentNotifications(projectId ProjectId, d *model.ApplicationDeployment) error

func (*DB) SaveApplicationSetting

func (db *DB) SaveApplicationSetting(projectId ProjectId, appId model.ApplicationId, s any) error

func (*DB) SaveCheckConfig

func (db *DB) SaveCheckConfig(projectId ProjectId, appId model.ApplicationId, checkId model.CheckId, cfg any) error

func (*DB) SaveIntegrationsBaseUrl

func (db *DB) SaveIntegrationsBaseUrl(id ProjectId, baseUrl string) error

func (*DB) SaveProject

func (db *DB) SaveProject(p Project) (ProjectId, error)

func (*DB) SaveProjectIntegration

func (db *DB) SaveProjectIntegration(p *Project, typ IntegrationType) error

func (*DB) ToggleConfigurationHint

func (db *DB) ToggleConfigurationHint(id ProjectId, appType model.ApplicationType, mute bool) error

func (*DB) Type

func (db *DB) Type() Type

func (*DB) UpdateIncidentNotification

func (db *DB) UpdateIncidentNotification(n IncidentNotification) error

type Incident

type Incident model.ApplicationIncident

func (*Incident) Migrate

func (i *Incident) Migrate(m *Migrator) error

type IncidentNotification

type IncidentNotification struct {
	ProjectId     ProjectId
	ApplicationId model.ApplicationId
	IncidentKey   string
	Status        model.Status
	Destination   IntegrationType
	Timestamp     timeseries.Time
	SentAt        timeseries.Time
	ExternalKey   string
	Details       *IncidentNotificationDetails
}

func (*IncidentNotification) Migrate

func (n *IncidentNotification) Migrate(m *Migrator) error

type IncidentNotificationDetails

type IncidentNotificationDetails struct {
	Reports []IncidentNotificationDetailsReport `json:"reports"`
}

type IncidentNotificationDetailsReport

type IncidentNotificationDetailsReport struct {
	Name    model.AuditReportName `json:"name"`
	Check   string                `json:"check"`
	Message string                `json:"message"`
}

type IntegrationClickhouse

type IntegrationClickhouse struct {
	Protocol      string          `json:"protocol"`
	Addr          string          `json:"addr"`
	Auth          utils.BasicAuth `json:"auth"`
	Database      string          `json:"database"`
	TlsEnable     bool            `json:"tls_enable"`
	TlsSkipVerify bool            `json:"tls_skip_verify"`
}

type IntegrationInfo

type IntegrationInfo struct {
	Type        IntegrationType
	Configured  bool
	Incidents   bool
	Deployments bool
	Title       string
	Details     string
}

type IntegrationOpsgenie

type IntegrationOpsgenie struct {
	ApiKey     string `json:"api_key"`
	EUInstance bool   `json:"eu_instance"`
	Incidents  bool   `json:"incidents"`
}

type IntegrationPagerduty

type IntegrationPagerduty struct {
	IntegrationKey string `json:"integration_key"`
	Incidents      bool   `json:"incidents"`
}

type IntegrationSlack

type IntegrationSlack struct {
	Token          string `json:"token"`
	DefaultChannel string `json:"default_channel"`
	Enabled        bool   `json:"enabled"` // deprecated: use Incidents and Deployments
	Incidents      bool   `json:"incidents"`
	Deployments    bool   `json:"deployments"`
}

type IntegrationTeams

type IntegrationTeams struct {
	WebhookUrl  string `json:"webhook_url"`
	Incidents   bool   `json:"incidents"`
	Deployments bool   `json:"deployments"`
}

type IntegrationType

type IntegrationType string
const (
	IntegrationTypePrometheus IntegrationType = "prometheus"
	IntegrationTypeClickhouse IntegrationType = "clickhouse"
	IntegrationTypeSlack      IntegrationType = "slack"
	IntegrationTypePagerduty  IntegrationType = "pagerduty"
	IntegrationTypeTeams      IntegrationType = "teams"
	IntegrationTypeOpsgenie   IntegrationType = "opsgenie"
	IntegrationTypeWebhook    IntegrationType = "webhook"
)

type IntegrationWebhook added in v1.0.0

type IntegrationWebhook struct {
	Url                string           `json:"url"`
	TlsSkipVerify      bool             `json:"tls_skip_verify"`
	BasicAuth          *utils.BasicAuth `json:"basic_auth"`
	CustomHeaders      []utils.Header   `json:"custom_headers"`
	Incidents          bool             `json:"incidents"`
	Deployments        bool             `json:"deployments"`
	IncidentTemplate   string           `json:"incident_template"`
	DeploymentTemplate string           `json:"deployment_template"`
}

type Integrations

type Integrations struct {
	BaseUrl string `json:"base_url"`

	Slack     *IntegrationSlack     `json:"slack,omitempty"`
	Pagerduty *IntegrationPagerduty `json:"pagerduty,omitempty"`
	Teams     *IntegrationTeams     `json:"teams,omitempty"`
	Opsgenie  *IntegrationOpsgenie  `json:"opsgenie,omitempty"`
	Webhook   *IntegrationWebhook   `json:"webhook,omitempty"`

	Clickhouse *IntegrationClickhouse `json:"clickhouse,omitempty"`
}

func (Integrations) GetInfo

func (integrations Integrations) GetInfo() []IntegrationInfo

type IntegrationsPrometheus

type IntegrationsPrometheus struct {
	Url             string              `json:"url"`
	RefreshInterval timeseries.Duration `json:"refresh_interval"`
	TlsSkipVerify   bool                `json:"tls_skip_verify"`
	BasicAuth       *utils.BasicAuth    `json:"basic_auth"`
	ExtraSelector   string              `json:"extra_selector"`
	CustomHeaders   []utils.Header      `json:"custom_headers"`
}

type Migrator

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

func NewMigrator

func NewMigrator(t Type, db *sql.DB) *Migrator

func (*Migrator) AddColumnIfNotExists

func (m *Migrator) AddColumnIfNotExists(table, column, dataType string) error

func (*Migrator) Exec

func (m *Migrator) Exec(query string, args ...any) error

func (*Migrator) Migrate

func (m *Migrator) Migrate(tables ...Table) error

type Project

type Project struct {
	Id   ProjectId
	Name string

	Prometheus IntegrationsPrometheus
	Settings   Settings
}

func (*Project) Migrate

func (p *Project) Migrate(m *Migrator) error

type ProjectId

type ProjectId string

type Settings

type Settings struct {
	ConfigurationHintsMuted     map[model.ApplicationType]bool                            `json:"configuration_hints_muted"`
	ApplicationCategories       map[model.ApplicationCategory][]string                    `json:"application_categories"`
	ApplicationCategorySettings map[model.ApplicationCategory]ApplicationCategorySettings `json:"application_category_settings"`
	Integrations                Integrations                                              `json:"integrations"`
}

type Table

type Table interface {
	Migrate(m *Migrator) error
}

type Type

type Type string
const (
	TypeSqlite   Type = "sqlite"
	TypePostgres Type = "postgres"
)

Jump to

Keyboard shortcuts

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