org

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: AGPL-3.0 Imports: 48 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AchievConfigureTracing    = "configure-tracing"
	AchievConfigureMetrics    = "configure-metrics"
	AchievInstallCollector    = "install-collector"
	AchievCreateMetricMonitor = "create-metric-monitor"
)
View Source
const (
	AttrEqual    = "="
	AttrNotEqual = "!="
)

Variables

View Source
var (
	ErrUnauthorized    = httperror.Unauthorized("please log in")
	ErrAccessDenied    = httperror.Forbidden("access denied")
	ErrProjectNotFound = httperror.NotFound("project not found")
)
View Source
var CreateErrorAlertTask = taskq.NewTask("create-error-alert")

Functions

func BuildDSN

func BuildDSN(conf *bunconf.Config, token string) string

func BuildFacetMap

func BuildFacetMap(items []*FacetItem) map[string]*Facet

func CompareAttrs

func CompareAttrs(a, b string) int

func ContextWithAnnotation

func ContextWithAnnotation(ctx context.Context, ann *Annotation) context.Context

func ContextWithProject

func ContextWithProject(ctx context.Context, project *Project) context.Context

func ContextWithUser

func ContextWithUser(ctx context.Context, user *User) context.Context

func CreateAchievementOnce

func CreateAchievementOnce(
	ctx context.Context,
	app *bunapp.App,
	achievement *Achievement,
)

func DSNFromMetadata

func DSNFromMetadata(ctx context.Context) (string, error)

func DSNFromRequest

func DSNFromRequest(req bunrouter.Request, extraHeaders ...string) (string, error)

func GetOrCreateUser

func GetOrCreateUser(ctx context.Context, app *bunapp.App, user *User) error

func GroupingInterval

func GroupingInterval(f *TimeFilter) (tableResolution, groupingInterval time.Duration)

func GroupingIntervalLarge

func GroupingIntervalLarge(gte, lt time.Time) time.Duration

func GroupingIntervalSmall

func GroupingIntervalSmall(gte, lt time.Time) time.Duration

func Init

func Init(ctx context.Context, app *bunapp.App)

func InsertAlert

func InsertAlert(ctx context.Context, app *bunapp.App, db bun.IDB, alert Alert) (bool, error)

func InsertAlertEvent

func InsertAlertEvent(ctx context.Context, db bun.IDB, event AlertEvent) error

func InsertMonitor

func InsertMonitor(ctx context.Context, db bun.IDB, monitor Monitor) error

func PauseMonitor

func PauseMonitor(ctx context.Context, app *bunapp.App, monitorID uint64) error

func SelectPinnedFacetMap

func SelectPinnedFacetMap(
	ctx context.Context, app *bunapp.App, userID uint64,
) (map[string]bool, error)

func SelectPinnedFacets

func SelectPinnedFacets(ctx context.Context, app *bunapp.App, userID uint64) ([]string, error)

func TableWhereResolution

func TableWhereResolution(f *TimeFilter) time.Duration

func UpdateMonitorState

func UpdateMonitorState(
	ctx context.Context, app *bunapp.App, monitorID uint64, fromState, toState MonitorState,
) error

func UpsertAchievement

func UpsertAchievement(
	ctx context.Context, app *bunapp.App, achievement *Achievement,
) error

Types

type Achievement

type Achievement struct {
	bun.BaseModel `bun:"achievements,alias:a"`

	ID        uint64 `json:"id" bun:",pk,autoincrement"`
	UserID    uint64 `json:"-" bun:",nullzero"`
	ProjectID uint32 `json:"-" bun:",nullzero"`
	Name      string `json:"name"`
}

func SelectAchievements

func SelectAchievements(
	ctx context.Context, app *bunapp.App, userID uint64, projectID uint32,
) ([]*Achievement, error)

type AchievementHandler

type AchievementHandler struct {
	*bunapp.App
}

func NewAchievementHandler

func NewAchievementHandler(app *bunapp.App) *AchievementHandler

func (*AchievementHandler) List

type Alert

type Alert interface {
	Base() *BaseAlert
	GetEvent() AlertEvent
	SetEvent(event AlertEvent)
	URL() string
	Muted() bool
}

type AlertEvent

type AlertEvent interface {
	Validate() error
	Base() *BaseAlertEvent
	Clone() AlertEvent
}

type AlertEventName

type AlertEventName string
const (
	AlertEventCreated       AlertEventName = "created"
	AlertEventStatusChanged AlertEventName = "status-changed"
	AlertEventRecurring     AlertEventName = "recurring"
)

type AlertStatus

type AlertStatus string
const (
	AlertStatusOpen   AlertStatus = "open"
	AlertStatusClosed AlertStatus = "closed"
)

type AlertType

type AlertType string
const (
	AlertError  AlertType = "error"
	AlertMetric AlertType = "metric"
)

type Annotation

type Annotation struct {
	bun.BaseModel `bun:"alias:e"`

	ID        uint64 `json:"id" bun:",pk,autoincrement"`
	ProjectID uint32 `json:"projectId"`
	Hash      uint64 `json:"-" bun:",nullzero"`

	Name        string            `json:"name"`
	Description string            `json:"description"`
	Color       string            `json:"color"`
	Attrs       map[string]string `json:"attrs"`
	CreatedAt   time.Time         `json:"createdAt" bun:",nullzero"`
}

func AnnotationFromContext

func AnnotationFromContext(ctx context.Context) *Annotation

type AnnotationFilter

type AnnotationFilter struct {
	ProjectID uint32 `urlstruct:"-"`
	TimeFilter
	urlstruct.Pager
	OrderByMixin
}

func (*AnnotationFilter) UnmarshalValues

func (f *AnnotationFilter) UnmarshalValues(ctx context.Context, values url.Values) error

func (*AnnotationFilter) WhereClause

func (f *AnnotationFilter) WhereClause(q *bun.SelectQuery) *bun.SelectQuery

type AnnotationHandler

type AnnotationHandler struct {
	*bunapp.App
}

func NewAnnotationHandler

func NewAnnotationHandler(app *bunapp.App) *AnnotationHandler

func (*AnnotationHandler) AnnotationMiddleware

func (h *AnnotationHandler) AnnotationMiddleware(next bunrouter.HandlerFunc) bunrouter.HandlerFunc

func (*AnnotationHandler) Create

func (*AnnotationHandler) CreatePublic

func (h *AnnotationHandler) CreatePublic(w http.ResponseWriter, req bunrouter.Request) error

func (*AnnotationHandler) Delete

func (*AnnotationHandler) List

func (*AnnotationHandler) Show

func (*AnnotationHandler) Update

type AnnotationIn

type AnnotationIn struct {
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Fingerprint string            `json:"fingerprint"`
	Color       string            `json:"color"`
	Attrs       map[string]string `json:"attrs"`
	Time        time.Time         `json:"time"`
}

func (*AnnotationIn) Validate

func (in *AnnotationIn) Validate(ann *Annotation) error

type AttrMatcher

type AttrMatcher struct {
	Attr  string        `json:"attr"`
	Op    AttrMatcherOp `json:"op"`
	Value string        `json:"value"`
}

func (*AttrMatcher) Matches

func (m *AttrMatcher) Matches(attrs map[string]any) bool

type AttrMatcherOp

type AttrMatcherOp string

type BaseAlert

type BaseAlert struct {
	bun.BaseModel `bun:"alerts,alias:a"`

	ID        uint64 `json:"id" bun:",pk,autoincrement"`
	ProjectID uint32 `json:"projectId"`

	EventID uint64          `json:"-" bun:",nullzero"`
	Event   *BaseAlertEvent `json:"-" bun:"rel:belongs-to,join:event_id=id"`

	Name      string            `json:"name"`
	Attrs     map[string]string `json:"attrs"`
	AttrsHash uint64            `json:"-"`

	Type AlertType `json:"type"`

	SpanGroupID uint64 `json:"spanGroupId,string" bun:",nullzero"`
	MonitorID   uint64 `json:"monitorId" bun:",nullzero"`

	CreatedAt  time.Time `json:"createdAt" bun:",nullzero"`
	MutedUntil time.Time `json:"mutedUntil" bun:",nullzero"`
}

func NewBaseAlert

func NewBaseAlert(alertType AlertType) *BaseAlert

func (*BaseAlert) MarshalJSON

func (a *BaseAlert) MarshalJSON() ([]byte, error)

func (*BaseAlert) Muted added in v1.7.0

func (a *BaseAlert) Muted() bool

func (*BaseAlert) URL

func (a *BaseAlert) URL() string

type BaseAlertEvent added in v1.7.0

type BaseAlertEvent struct {
	bun.BaseModel `bun:"alert_events,alias:e"`

	ID uint64 `bun:",pk,autoincrement"`

	UserID uint64 `bun:",nullzero"`
	User   *User  `bun:"rel:belongs-to,join:user_id=id"`

	ProjectID uint32
	AlertID   uint64
	Alert     *BaseAlert `bun:"rel:belongs-to,join:alert_id=id"`

	Name   AlertEventName
	Status AlertStatus
	Params bunutil.Params `bun:"type:jsonb,nullzero"` // immutable

	Time      time.Time `bun:",nullzero"`
	CreatedAt time.Time `bun:",nullzero"`
}

func (*BaseAlertEvent) Validate added in v1.7.0

func (e *BaseAlertEvent) Validate() error

type BaseMonitor

type BaseMonitor struct {
	bun.BaseModel `bun:"monitors,alias:m"`

	ID        uint64 `json:"id,string" bun:",pk,autoincrement"`
	ProjectID uint32 `json:"projectId"`

	Name  string       `json:"name"`
	State MonitorState `json:"state"`

	NotifyEveryoneByEmail bool `json:"notifyEveryoneByEmail"`

	Type   MonitorType    `json:"type"`
	Params bunutil.Params `json:"params"`

	CreatedAt time.Time    `json:"createdAt" bun:",nullzero"`
	UpdatedAt bun.NullTime `json:"updatedAt"`

	ChannelIDs []uint64 `json:"channelIds" bun:"-"`
	AlertCount int      `json:"alertCount" bun:"-"`
}

func SelectBaseMonitor

func SelectBaseMonitor(ctx context.Context, app *bunapp.App, id uint64) (*BaseMonitor, error)

func (*BaseMonitor) Validate

func (m *BaseMonitor) Validate() error

type CloudflareProvider

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

Adapted from https://developers.cloudflare.com/cloudflare-one/identity/authorization-cookie/validating-json/

func NewCloudflareProvider

func NewCloudflareProvider(conf *bunconf.CloudflareProvider) *CloudflareProvider

func (*CloudflareProvider) Auth

func (p *CloudflareProvider) Auth(req bunrouter.Request) (*User, error)

type DSN

type DSN struct {
	Scheme string
	Host   string
	Token  string
	// contains filtered or unexported fields
}

func ParseDSN

func ParseDSN(dsnStr string) (*DSN, error)

func (*DSN) String

func (dsn *DSN) String() string

type ErrorAlertParams

type ErrorAlertParams struct {
	TraceID   idgen.TraceID `json:"traceId"`
	SpanID    idgen.SpanID  `json:"spanId"`
	SpanCount int64         `json:"spanCount"`
}

func (*ErrorAlertParams) Clone

func (p *ErrorAlertParams) Clone() *ErrorAlertParams

type ErrorMonitor

type ErrorMonitor struct {
	*BaseMonitor `bun:",inherit"`
	Params       ErrorMonitorParams `json:"params"`
}

func NewErrorMonitor

func NewErrorMonitor() *ErrorMonitor

func (*ErrorMonitor) Base

func (m *ErrorMonitor) Base() *BaseMonitor

func (*ErrorMonitor) Validate

func (m *ErrorMonitor) Validate() error

type ErrorMonitorParams

type ErrorMonitorParams struct {
	NotifyOnNewErrors       bool          `json:"notifyOnNewErrors"`
	NotifyOnRecurringErrors bool          `json:"notifyOnRecurringErrors"`
	Matchers                []AttrMatcher `json:"matchers"`
}

type Facet

type Facet struct {
	Key   string       `json:"key"`
	Items []*FacetItem `json:"items"`
}

func FacetMapToList

func FacetMapToList(m map[string]*Facet) []*Facet

type FacetFilter

type FacetFilter struct {
	Q     string
	Attrs map[string][]string
}

func (*FacetFilter) UnmarshalValues

func (f *FacetFilter) UnmarshalValues(ctx context.Context, values url.Values) error

func (*FacetFilter) WhereClause

func (f *FacetFilter) WhereClause(q *bun.SelectQuery) *bun.SelectQuery

type FacetItem

type FacetItem struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	Count uint32 `json:"count"`
}

type JWTProvider

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

func NewJWTProvider

func NewJWTProvider(app *bunapp.App, secretKey string) *JWTProvider

func (*JWTProvider) Auth

func (p *JWTProvider) Auth(req bunrouter.Request) (*User, error)

type MetricMonitor

type MetricMonitor struct {
	*BaseMonitor `bun:",inherit"`
	Params       MetricMonitorParams `json:"params"`
}

func NewMetricMonitor

func NewMetricMonitor() *MetricMonitor

func (*MetricMonitor) Base

func (m *MetricMonitor) Base() *BaseMonitor

func (*MetricMonitor) MadalarmOptions

func (m *MetricMonitor) MadalarmOptions() ([]madalarm.Option, error)

func (*MetricMonitor) Validate

func (m *MetricMonitor) Validate() error

type MetricMonitorParams

type MetricMonitorParams struct {
	Metrics    []mql.MetricAlias `json:"metrics"`
	Query      string            `json:"query"`
	Column     string            `json:"column"`
	ColumnUnit string            `json:"columnUnit"`

	CheckNumPoint int             `json:"checkNumPoint"`
	TimeOffset    unixtime.Millis `json:"timeOffset"`

	MinAllowedValue bunutil.NullFloat64 `json:"minAllowedValue"`
	MaxAllowedValue bunutil.NullFloat64 `json:"maxAllowedValue"`
}

type Middleware

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

func NewMiddleware

func NewMiddleware(app *bunapp.App) *Middleware

func (*Middleware) User

func (*Middleware) UserAndProject

func (m *Middleware) UserAndProject(next bunrouter.HandlerFunc) bunrouter.HandlerFunc

type Monitor

type Monitor interface {
	Base() *BaseMonitor
}

func DecodeMonitor

func DecodeMonitor(base *BaseMonitor) (Monitor, error)

func SelectMonitor

func SelectMonitor(ctx context.Context, app *bunapp.App, id uint64) (Monitor, error)

type MonitorChannel

type MonitorChannel struct {
	MonitorID uint64
	ChannelID uint64
}

type MonitorState

type MonitorState string
const (
	MonitorActive MonitorState = "active"
	MonitorPaused MonitorState = "paused"
	MonitorFiring MonitorState = "firing"
	MonitorNoData MonitorState = "no-data"
	MonitorFailed MonitorState = "failed"
)

type MonitorType

type MonitorType string
const (
	MonitorMetric MonitorType = "metric"
	MonitorError  MonitorType = "error"
)

type OrderByMixin

type OrderByMixin struct {
	SortBy   string
	SortDesc bool
}

func (*OrderByMixin) CHOrder

func (f *OrderByMixin) CHOrder(q *ch.SelectQuery) *ch.SelectQuery

func (OrderByMixin) MarshalJSON

func (f OrderByMixin) MarshalJSON() ([]byte, error)

func (*OrderByMixin) PGOrder

func (f *OrderByMixin) PGOrder(q *bun.SelectQuery) *bun.SelectQuery

func (*OrderByMixin) Reset

func (f *OrderByMixin) Reset()

func (OrderByMixin) SortDir

func (f OrderByMixin) SortDir() string

func (*OrderByMixin) UnmarshalValues

func (f *OrderByMixin) UnmarshalValues(ctx context.Context, values url.Values) error

type PinnedFacet

type PinnedFacet struct {
	bun.BaseModel `bun:"pinned_facets,alias:f"`

	UserID   uint64 `json:"userId"`
	Attr     string `json:"attr"`
	Unpinned bool   `json:"-"`
}

type PinnedFacetHandler

type PinnedFacetHandler struct {
	*bunapp.App
}

func NewPinnedFacetHandler

func NewPinnedFacetHandler(app *bunapp.App) *PinnedFacetHandler

func (*PinnedFacetHandler) Add

func (*PinnedFacetHandler) List

func (*PinnedFacetHandler) Remove

type Project

type Project struct {
	bun.BaseModel `bun:"projects,alias:p"`

	ID    uint32 `json:"id" bun:",pk,autoincrement"`
	Name  string `json:"name" bun:",nullzero"`
	Token string `json:"token" bun:",nullzero"`

	PinnedAttrs         []string `json:"pinnedAttrs" bun:",array"`
	GroupByEnv          bool     `json:"groupByEnv"`
	GroupFuncsByService bool     `json:"groupFuncsByService"`
	PromCompat          bool     `json:"promCompat"`
	ForceSpanName       []string `json:"forceSpanName" bun:",array"`

	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

func ProjectFromContext

func ProjectFromContext(ctx context.Context) *Project

func ProjectFromRequest

func ProjectFromRequest(app *bunapp.App, req bunrouter.Request) (*Project, error)

func SelectProject

func SelectProject(
	ctx context.Context, app *bunapp.App, projectID uint32,
) (*Project, error)

func SelectProjectByDSN

func SelectProjectByDSN(
	ctx context.Context, app *bunapp.App, dsnStr string,
) (*Project, error)

func SelectProjectByToken

func SelectProjectByToken(
	ctx context.Context, app *bunapp.App, token string,
) (*Project, error)

func SelectProjects

func SelectProjects(ctx context.Context, app *bunapp.App) ([]*Project, error)

func (*Project) DSN

func (p *Project) DSN(conf *bunconf.Config) string

func (*Project) EmailSettingsURL

func (p *Project) EmailSettingsURL() string

func (*Project) Init

func (p *Project) Init() error

func (*Project) SettingsURL

func (p *Project) SettingsURL() string

type ProjectHandler

type ProjectHandler struct {
	*bunapp.App
}

func NewProjectHandler

func NewProjectHandler(app *bunapp.App) *ProjectHandler

func (*ProjectHandler) Show

type SSOHandler

type SSOHandler struct {
	*bunapp.App
	// contains filtered or unexported fields
}

func NewSSOHandler

func NewSSOHandler(app *bunapp.App, router *bunrouter.Group) *SSOHandler

func (*SSOHandler) ListMethods

func (h *SSOHandler) ListMethods(w http.ResponseWriter, req bunrouter.Request) error

type SSOMethod

type SSOMethod struct {
	ID          string `json:"id"`
	DisplayName string `json:"name"`
	RedirectURL string `json:"url"`
}

type SSOMethodHandler

type SSOMethodHandler struct {
	*bunapp.App
	// contains filtered or unexported fields
}

func NewSSOMethodHandler

func NewSSOMethodHandler(
	app *bunapp.App, conf *bunconf.OIDCProvider,
) (*SSOMethodHandler, error)

func (*SSOMethodHandler) Callback

func (*SSOMethodHandler) Start

type TimeFilter

type TimeFilter struct {
	TimeGTE    time.Time
	TimeLT     time.Time
	TimeOffset unixtime.Millis

	Interval    unixtime.Millis
	MinInterval unixtime.Millis
}

func (*TimeFilter) Duration

func (f *TimeFilter) Duration() time.Duration

func (*TimeFilter) GroupingInterval

func (f *TimeFilter) GroupingInterval() time.Duration

func (*TimeFilter) IsZero

func (f *TimeFilter) IsZero() bool

func (*TimeFilter) Round

func (f *TimeFilter) Round(d time.Duration)

func (*TimeFilter) UnmarshalValues

func (f *TimeFilter) UnmarshalValues(ctx context.Context, values url.Values) error

type TrackableModel

type TrackableModel string
const (
	ModelUser      TrackableModel = "User"
	ModelProject   TrackableModel = "Project"
	ModelSpan      TrackableModel = "Span"
	ModelSpanGroup TrackableModel = "SpanGroup"
)

type Usage added in v1.7.0

type Usage struct {
	Spans      []uint64    `json:"spans"`
	Bytes      []uint64    `json:"bytes"`
	Timeseries []uint64    `json:"timeseries"`
	Time       []time.Time `json:"time"`
}

type Usage2 added in v1.7.0

type Usage2 struct {
	Datapoints []uint64
	Time       []time.Time
	Minutes    []uint64
}

type UsageHandler added in v1.7.0

type UsageHandler struct {
	*bunapp.App
}

func NewUsageHandler added in v1.7.0

func NewUsageHandler(app *bunapp.App) *UsageHandler

func (*UsageHandler) Show added in v1.7.0

type User

type User struct {
	bun.BaseModel `bun:"users,alias:u"`

	ID uint64 `json:"id" bun:",pk,autoincrement"`

	Email    string `json:"email" bun:",nullzero"`
	Password string `json:"-" bun:"-"`

	Name   string `json:"name" bun:",nullzero"`
	Avatar string `json:"avatar" bun:",nullzero"`

	NotifyByEmail bool   `json:"notifyByEmail"`
	AuthToken     string `json:"authToken"`

	CreatedAt time.Time `json:"createdAt" bun:",nullzero"`
	UpdatedAt time.Time `json:"updatedAt" bun:",nullzero"`
}

func NewUserFromConfig

func NewUserFromConfig(src *bunconf.User) (*User, error)

func SelectUser

func SelectUser(ctx context.Context, app *bunapp.App, id uint64) (*User, error)

func SelectUserByEmail

func SelectUserByEmail(ctx context.Context, app *bunapp.App, email string) (*User, error)

func SelectUserByToken added in v1.7.0

func SelectUserByToken(ctx context.Context, app *bunapp.App, token string) (*User, error)

func UserFromContext

func UserFromContext(ctx context.Context) *User

func (*User) SetPassword

func (u *User) SetPassword(pass string) error

func (*User) Username

func (u *User) Username() string

func (*User) Validate added in v1.7.0

func (u *User) Validate() error

type UserHandler

type UserHandler struct {
	*bunapp.App
}

func NewUserHandler

func NewUserHandler(app *bunapp.App) *UserHandler

func (*UserHandler) Current

func (*UserHandler) Login

func (*UserHandler) Logout

type UserProjectData

type UserProjectData struct {
	bun.BaseModel `bun:"user_project_data,alias:d"`

	UserID    uint64 `json:"-"`
	ProjectID uint32 `json:"-"`

	NotifyOnMetrics         bool `json:"notifyOnMetrics"`
	NotifyOnNewErrors       bool `json:"notifyOnNewErrors"`
	NotifyOnRecurringErrors bool `json:"notifyOnRecurringErrors"`
}

type UserProvider

type UserProvider interface {
	Auth(req bunrouter.Request) (*User, error)
}

Jump to

Keyboard shortcuts

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