database

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	URIEnvVariableName string = "UDASH_DB_URI"
)

Variables

View Source
var ErrSummaryRangeTooWide = errors.New("requested time range is too wide")

ErrSummaryRangeTooWide is returned when the requested time range spans more days than the caller allows. Callers are expected to turn it into a client error.

View Source
var ErrSummaryTooManyBuckets = errors.New("requested time range produces too many buckets")

ErrSummaryTooManyBuckets is returned when the requested time range and granularity would produce more buckets than the caller allows. Callers are expected to turn it into a client error.

Functions

func Connect

func Connect(o Options) error

func DeleteConfigResource added in v0.10.0

func DeleteConfigResource(ctx context.Context, resourceType string, id string) error

DeleteConfigResource deletes a resource configuration from the database.

func DeleteReport added in v0.10.0

func DeleteReport(ctx context.Context, id string) error

DeleteReport deletes a report from the database.

func GetConditionConfigs added in v0.10.0

func GetConditionConfigs(ctx context.Context, kind, id, config string, limit, page int) ([]model.ConfigCondition, int, error)

GetConditionConfigs returns a list of resource configurations from the database.

func GetConfigKind added in v0.10.0

func GetConfigKind(ctx context.Context, resourceType string) ([]string, error)

GetConfigKind returns a list of resource configurations from the database filtered by kind.

func GetLabelKeyOnlyRecords added in v0.14.0

func GetLabelKeyOnlyRecords(ctx context.Context, startTime, endTime string, limit, page int) ([]string, int, error)

GetLabelKeyOnlyRecords returns a list of labels from the labels database table.

func GetLabelRecords added in v0.14.0

func GetLabelRecords(ctx context.Context, id, key, value, startTime, endTime string, limit, page int) ([]model.Label, int, error)

GetLabelRecords returns a list of labels from the labels database table.

func GetSCM added in v0.10.0

func GetSCM(ctx context.Context, params GetSCMParams) ([]model.SCM, int, error)

GetSCM returns a list of scms from the scm database table.

func GetSourceConfigs added in v0.10.0

func GetSourceConfigs(ctx context.Context, kind, id, config string, limit, page int) ([]model.ConfigSource, int, error)

GetSourceConfigs returns a list of resource configurations from the database.

func GetTargetConfigs added in v0.10.0

func GetTargetConfigs(ctx context.Context, kind, id, config string, limit, page int) ([]model.ConfigTarget, int, error)

GetTargetConfigs returns a list of resource configurations from the database.

func InitLabels added in v0.14.0

func InitLabels(ctx context.Context, labels map[string]string) ([]uuid.UUID, error)

InitLabels takes a map of labels and ensures that they exist in the database, creating them if necessary.

func InsertConfigResource added in v0.10.0

func InsertConfigResource(ctx context.Context, resourceType, resourceKind string, resourceConfig interface{}) (string, error)

InsertConfigResource inserts a new resource configuration into the database.

func InsertLabel added in v0.14.0

func InsertLabel(ctx context.Context, key, value string) (string, error)

InsertLabel creates a new label and inserts it into the database.

It returns the ID of the newly created label.

func InsertReport added in v0.10.0

func InsertReport(ctx context.Context, report reports.Report) (string, error)

InsertReport inserts a new report into the database.

func InsertSCM added in v0.10.0

func InsertSCM(ctx context.Context, url, branch string) (string, error)

InsertSCM creates a new SCM and inserts it into the database. It returns the ID of the newly created SCM.

func RunMigrationUp

func RunMigrationUp() error

func SearchLatestReportByPipelineID added in v0.10.0

func SearchLatestReportByPipelineID(ctx context.Context, id string) (*model.PipelineReport, error)

SearchLatestReportByPipelineID searches the latest report for a specific pipeline id.

func SearchNumberOfReportsByPipelineID added in v0.10.0

func SearchNumberOfReportsByPipelineID(ctx context.Context, id string) (int, error)

SearchNumberOfReportsByPipelineID searches the number of reports for a specific pipeline id.

func SearchReport added in v0.10.0

func SearchReport(ctx context.Context, id string) (*model.PipelineReport, error)

SearchReport searches a report by its database record id.

Types

type GetSCMParams added in v0.16.0

type GetSCMParams struct {
	// ID restricts the lookup to a specific scm.
	ID string
	// URL restricts the lookup to the scms of a repository.
	URL string
	// Branch restricts the lookup to the scms of a branch.
	Branch string
	// StartTime and EndTime restrict the lookup to the scms a report was published for
	// within that range. Both must be provided, an empty range does not filter anything
	// out.
	StartTime string
	EndTime   string
	// Limit is the maximum number of scms to return, a value lower than one returns
	// them all. Page is one based.
	Limit int
	Page  int
}

GetSCMParams contains the filters used to look up scms.

type GetSCMSummaryParams added in v0.14.0

type GetSCMSummaryParams struct {
	MonitoringDurationDays int
	StartTime              string
	EndTime                string
	Labels                 map[string]string
	// Results restricts the summary to the reports whose pipeline result is one of
	// them. An empty list does not filter anything out.
	Results []string
	// OpenAction restricts the summary to the pipelines which carry an open action, such as
	// a pull request still waiting to be merged, or to the ones which do not. A nil value
	// does not filter anything out.
	OpenAction   *bool
	TotalCount   int
	TotalActions int
	Ctx          context.Context
	ScmRows      []model.SCM
}

type Options

type Options struct {
	// URI defines the DB URI
	URI               string
	MigrationDisabled bool
}

type ReportResultSummaryEntry added in v0.16.0

type ReportResultSummaryEntry struct {
	// Date is the start of the bucket, in UTC, formatted as RFC3339.
	Date string `json:"date"`
	// Results contains the number of reports per Updatecli result for that bucket.
	Results map[string]int `json:"results"`
	// OpenActions contains, for each Updatecli result, how many of the reports counted in
	// Results also carry an open action, such as a pull request still waiting to be merged.
	// It is a breakdown of Results, not an addition to it, so its counts are always lower
	// than or equal to the matching ones in Results.
	//
	// The interesting one is the count reported under the success result: those pipelines
	// ran fine and had nothing to change only because the change is already waiting in a
	// pull request.
	OpenActions map[string]int `json:"open_actions"`
	// Total is the number of reports for that bucket, all results combined.
	Total int `json:"total"`
}

ReportResultSummaryEntry contains the number of reports per result for a single time bucket.

func SearchReportsSummary added in v0.16.0

func SearchReportsSummary(params ReportSummaryParams) ([]ReportResultSummaryEntry, int, error)

SearchReportsSummary returns the number of reports per result for each time bucket of the requested time range. Buckets without any report are reported with a zeroed entry so that the returned dataset always covers the whole time range.

The summary always covers whole buckets: an explicit time range is widened to the buckets it overlaps, otherwise a partial bucket would be reported as a drop of activity.

type ReportSearchOptions added in v0.10.0

type ReportSearchOptions struct {
	// Days is the how far to look back for reports from today.
	Days int
}

ReportSearchOptions contains options for searching reports.

type ReportSummaryParams added in v0.16.0

type ReportSummaryParams struct {
	Ctx context.Context
	// Days is how far back to look for reports, in days.
	// It is ignored when Hours, or StartTime and EndTime, are provided.
	Days int
	// Hours is how far back to look for reports, in hours. It takes precedence over
	// Days and is ignored when StartTime and EndTime are provided.
	Hours int
	// Granularity is the size of the time buckets, it defaults to a day.
	Granularity SummaryGranularity
	// MaxDays is the widest time range accepted, in days. A value lower than one
	// does not enforce any limit.
	MaxDays int
	// MaxBuckets is the largest number of buckets a summary may return. A value lower
	// than one does not enforce any limit.
	MaxBuckets int
	// StartTime and EndTime define an explicit time range, both must be provided.
	StartTime string
	EndTime   string
	// ScmID restricts the summary to the reports of a specific scm.
	ScmID string
	// Labels restricts the summary to the reports matching those labels.
	Labels map[string]string
	// Results restricts the summary to the reports whose pipeline result is one of
	// them. An empty list does not filter anything out.
	Results []string
	// OpenAction restricts the summary to the reports which carry an open action, such as
	// a pull request still waiting to be merged, or to the ones which do not. A nil value
	// does not filter anything out.
	OpenAction *bool
}

ReportSummaryParams contains the parameters used to summarize reports per time bucket.

type SCMBranchDataset added in v0.10.0

type SCMBranchDataset map[string]ScmSummaryData

SCMBranchDataset represents a map of branches and their summary data for a single SCM URL.

type SCMDataset added in v0.10.0

type SCMDataset struct {
	Data map[string]SCMBranchDataset `json:"data"`
}

SCMDataset represents the response for the FindSCMSummary endpoint.

func GetSCMSummary added in v0.10.0

func GetSCMSummary(params GetSCMSummaryParams) (*SCMDataset, error)

GetSCMSummary returns a list of scms summary from the scm database table.

type ScmSummaryData added in v0.10.0

type ScmSummaryData struct {
	// ID is the unique identifier of the SCM.
	ID string `json:"id"`
	// TotalResultByType is a map of result types and their counts.
	TotalResultByType map[string]int `json:"total_result_by_type"`
	// TotalResult is the total number of results for this SCM.
	TotalResult int `json:"total_result"`
	// TotalActionURLs is the total number of unique action URLs for this SCM.
	TotalActionURLs int `json:"total_action_urls"`
	// TotalOpenActionByResult is a map of result types to the number of pipelines in that
	// result which also carry an open action, such as a pull request still waiting to be
	// merged. It is a breakdown of TotalResultByType, so its counts are always lower than
	// or equal to the matching ones there.
	//
	// Unlike TotalActionURLs, which counts distinct action URLs, this counts pipelines: a
	// single pull request grouping the changes of several pipelines is counted once there
	// and once per pipeline here.
	TotalOpenActionByResult map[string]int `json:"total_open_action_by_result"`
}

ScmSummaryData represents the summary data for a single SCM.

type SearchLatestReportData added in v0.10.0

type SearchLatestReportData struct {
	// ID represents the unique identifier of the report.
	ID string
	// Name represents the name of the report.
	Name string
	// Result represents the result of the report.
	Result string
	// Report contains the report data.
	Report reports.Report
	// FilteredResourceID contains the resource config ID that was filtered
	// It allows to identify in the report which resource was used to filter the report.
	FilteredResourceID string
	// CreatedAt represents the creation date of the report.
	CreatedAt string
	// UpdatedAt represents the last update date of the report.
	UpdatedAt string
	// TargetConfigIDs contains the config target IDs associated with the report.
	TargetConfigIDs pgtype.Hstore
	// ConditionConfigIDs contains the config condition IDs associated with the report.
	ConditionConfigIDs pgtype.Hstore
	// SourceConfigIDs contains the config source IDs associated with the report.
	SourceConfigIDs pgtype.Hstore
}

SearchLatestReportData represents a report.

func SearchLatestReports added in v0.13.0

func SearchLatestReports(params SearchLatestReportsParams) ([]SearchLatestReportData, int, error)

SearchLatestReports searches the latest reports according some parameters.

type SearchLatestReportsParams added in v0.14.0

type SearchLatestReportsParams struct {
	Ctx         context.Context
	ScmID       string
	SourceID    string
	ConditionID string
	TargetID    string
	Options     ReportSearchOptions
	StartTime   string
	EndTime     string
	Limit       int
	Page        int
	Latest      bool
	Labels      map[string]string
	// Results restricts the search to the reports whose pipeline result is one of
	// them. An empty list does not filter anything out.
	Results []string
	// OpenAction restricts the search to the reports which carry an open action, such as
	// a pull request still waiting to be merged, or to the ones which do not. A nil value
	// does not filter anything out.
	OpenAction *bool
}

type SummaryGranularity added in v0.16.0

type SummaryGranularity string

SummaryGranularity is the size of the time buckets a reports summary is grouped by.

const (
	// SummaryGranularityHour groups the reports per UTC hour.
	SummaryGranularityHour SummaryGranularity = "hour"
	// SummaryGranularityDay groups the reports per UTC day.
	SummaryGranularityDay SummaryGranularity = "day"
	// SummaryGranularityWeek groups the reports per ISO week, starting on monday.
	SummaryGranularityWeek SummaryGranularity = "week"
	// SummaryGranularityMonth groups the reports per calendar month.
	SummaryGranularityMonth SummaryGranularity = "month"
)

func (SummaryGranularity) IsValid added in v0.16.0

func (g SummaryGranularity) IsValid() bool

IsValid reports whether the granularity is one this package knows how to bucket.

Jump to

Keyboard shortcuts

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