config

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateAtLeastOneProjectOrWildcard

func ValidateAtLeastOneProjectOrWildcard(v validator.FieldLevel) bool

ValidateAtLeastOneProjectOrWildcard implements validator.Func assess that we have at least one projet or wildcard configured.

Types

type Config

type Config struct {
	// Global ..
	Global Global `yaml:",omitempty"`

	// Log configuration for the exporter
	Log Log `yaml:"log"`

	// OpenTelemetry configuration
	OpenTelemetry OpenTelemetry `yaml:"opentelemetry"`

	// Server related configuration
	Server Server `yaml:"server"`

	// GitLab related configuration
	Gitlab Gitlab `yaml:"gitlab"`

	// Redis related configuration
	Redis Redis `yaml:"redis"`

	// Pull configuration
	Pull Pull `yaml:"pull"`

	// GarbageCollect configuration
	GarbageCollect GarbageCollect `yaml:"garbage_collect"`

	// Default parameters which can be overridden at either the Project or Wildcard level
	ProjectDefaults ProjectParameters `yaml:"project_defaults"`

	// List of projects to pull
	Projects []Project `validate:"unique,at-least-1-project-or-wildcard,dive" yaml:"projects"`

	// List of wildcards to search projects from
	Wildcards []Wildcard `validate:"unique,at-least-1-project-or-wildcard,dive" yaml:"wildcards"`
}

Config represents all the parameters required for the app to be configured properly.

func New

func New() (c Config)

New returns a new config with the default parameters.

func Parse

func Parse(f Format, bytes []byte) (cfg Config, err error)

Parse unmarshal provided bytes with given ConfigType into a Config object.

func ParseFile

func ParseFile(filename string) (c Config, err error)

ParseFile reads the content of a file and attempt to unmarshal it into a Config.

func (Config) NewProject

func (c Config) NewProject() (p Project)

NewProject returns a new project with the config default parameters.

func (Config) NewWildcard

func (c Config) NewWildcard() (w Wildcard)

NewWildcard returns a new wildcard with the config default parameters.

func (Config) ToYAML added in v0.5.1

func (c Config) ToYAML() string

ToYAML ..

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(v *yaml.Node) (err error)

UnmarshalYAML allows us to correctly hydrate our configuration using some custom logic.

func (Config) Validate

func (c Config) Validate() error

Validate will throw an error if the Config parameters are whether incomplete or incorrects.

type Format

type Format uint8

Format represents the format of the config file.

const (
	// FormatYAML represents a Config written in yaml format.
	FormatYAML Format = iota
)

func GetTypeFromFileExtension

func GetTypeFromFileExtension(filename string) (f Format, err error)

GetTypeFromFileExtension returns the ConfigType based upon the extension of the file.

type GarbageCollect

type GarbageCollect struct {
	// Projects configuration
	Projects struct {
		OnInit          bool `default:"false" yaml:"on_init"`
		Scheduled       bool `default:"true" yaml:"scheduled"`
		IntervalSeconds int  `default:"14400" validate:"gte=1" yaml:"interval_seconds"`
	} `yaml:"projects"`

	// Environments configuration
	Environments struct {
		OnInit          bool `default:"false" yaml:"on_init"`
		Scheduled       bool `default:"true" yaml:"scheduled"`
		IntervalSeconds int  `default:"14400" validate:"gte=1" yaml:"interval_seconds"`
	} `yaml:"environments"`

	// Refs configuration
	Refs struct {
		OnInit          bool `default:"false" yaml:"on_init"`
		Scheduled       bool `default:"true" yaml:"scheduled"`
		IntervalSeconds int  `default:"1800" validate:"gte=1" yaml:"interval_seconds"`
	} `yaml:"refs"`

	// Metrics configuration
	Metrics struct {
		OnInit          bool `default:"false" yaml:"on_init"`
		Scheduled       bool `default:"true" yaml:"scheduled"`
		IntervalSeconds int  `default:"600" validate:"gte=1" yaml:"interval_seconds"`
	} `yaml:"metrics"`
}

GarbageCollect ..

type Gitlab

type Gitlab struct {
	// The URL of the GitLab server/api
	URL string `default:"https://gitlab.com" validate:"required,url" yaml:"url"`

	// Token to use to authenticate against the API
	Token string `validate:"required" yaml:"token"`

	// The URL of the GitLab server/api health endpoint (default to /users/sign_in which is publicly available on gitlab.com)
	HealthURL string `default:"https://gitlab.com/explore" validate:"required,url" yaml:"health_url"`

	// Whether to validate the service is reachable calling HealthURL
	EnableHealthCheck bool `default:"true" yaml:"enable_health_check"`

	// Whether to skip TLS validation when querying HealthURL
	EnableTLSVerify bool `default:"true" yaml:"enable_tls_verify"`

	// Maximum limit for the GitLab API requests/sec
	MaximumRequestsPerSecond int `default:"1" validate:"gte=1" yaml:"maximum_requests_per_second"`

	// Burstable limit for the GitLab API requests/sec
	BurstableRequestsPerSecond int `default:"5" validate:"gte=1" yaml:"burstable_requests_per_second"`

	// Maximum amount of jobs to keep queue, if this limit is reached
	// newly created ones will get dropped. As a best practice you should not change this value.
	// Workarounds to avoid hitting the limit are:
	// - increase polling intervals
	// - increase API rate limit
	// - reduce the amount of projects, refs, environments or metrics you are looking into
	// - leverage webhooks instead of polling schedules
	//
	MaximumJobsQueueSize int `default:"1000" validate:"gte=10" yaml:"maximum_jobs_queue_size"`
}

Gitlab ..

type Global added in v0.5.1

type Global struct {
	// InternalMonitoringListenerAddress can be used to access
	// some metrics related to the exporter internals
	InternalMonitoringListenerAddress *url.URL
}

Global is used for globally shared exporter config.

type Log

type Log struct {
	// Log level
	Level string `default:"info" validate:"required,oneof=trace debug info warning error fatal panic"`

	// Log format
	Format string `default:"text" validate:"oneof=text json"`
}

Log holds runtime logging configuration.

type OpenTelemetry added in v0.5.4

type OpenTelemetry struct {
	// gRPC endpoint of the opentelemetry collector
	GRPCEndpoint string `yaml:"grpc_endpoint"`
}

OpenTelemetry related configuration.

type Project

type Project struct {
	// ProjectParameters holds parameters specific to this project.
	ProjectParameters `yaml:",inline"`

	// Name is actually what is commonly referred as path_with_namespace on GitLab.
	Name string `yaml:"name"`
}

Project holds information about a GitLab project.

func NewProject

func NewProject(name string) (p Project)

NewProject returns a new project composed with the default parameters.

type ProjectParameters

type ProjectParameters struct {
	// From handles ProjectPullParameters configuration.
	Pull ProjectPull `yaml:"pull"`

	// Whether or not to export all pipeline/job statuses (being 0) or solely the one of the last job (being 1).
	OutputSparseStatusMetrics bool `default:"true" yaml:"output_sparse_status_metrics"`
}

ProjectParameters for the fetching configuration of Projects and Wildcards.

type ProjectPull

type ProjectPull struct {
	Environments ProjectPullEnvironments `yaml:"environments"`
	Refs         ProjectPullRefs         `yaml:"refs"`
	Pipeline     ProjectPullPipeline     `yaml:"pipeline"`
}

ProjectPull ..

type ProjectPullEnvironments

type ProjectPullEnvironments struct {
	// Whether to pull environments/deployments or not for this project
	Enabled bool `default:"false" yaml:"enabled"`

	// Regular expression to filter environments to fetch by their names
	Regexp string `default:".*" yaml:"regexp"`

	// Prevent exporting metrics for stopped environments
	ExcludeStopped bool `default:"true" yaml:"exclude_stopped"`
}

ProjectPullEnvironments ..

type ProjectPullPipeline

type ProjectPullPipeline struct {
	Jobs        ProjectPullPipelineJobs        `yaml:"jobs"`
	Variables   ProjectPullPipelineVariables   `yaml:"variables"`
	TestReports ProjectPullPipelineTestReports `yaml:"test_reports"`
}

ProjectPullPipeline ..

type ProjectPullPipelineJobs

type ProjectPullPipelineJobs struct {
	// Enabled set to true will pull pipeline jobs related metrics.
	Enabled bool `default:"false" yaml:"enabled"`

	// Pull pipeline jobs from child/downstream pipelines.
	FromChildPipelines ProjectPullPipelineJobsFromChildPipelines `yaml:"from_child_pipelines"`

	// Configure the export of the runner description which ran the job.
	RunnerDescription ProjectPullPipelineJobsRunnerDescription `yaml:"runner_description"`
}

ProjectPullPipelineJobs ..

type ProjectPullPipelineJobsFromChildPipelines

type ProjectPullPipelineJobsFromChildPipelines struct {
	// Enabled set to true will pull pipeline jobs from child/downstream pipelines related metrics.
	Enabled bool `default:"true" yaml:"enabled"`
}

ProjectPullPipelineJobsFromChildPipelines ..

type ProjectPullPipelineJobsRunnerDescription

type ProjectPullPipelineJobsRunnerDescription struct {
	// Enabled set to true will export the description of the runner which ran the job.
	Enabled bool `default:"true" yaml:"enabled"`

	// Regular expression to be able to reduce the cardinality of the exported value when necessary.
	AggregationRegexp string `default:"shared-runners-manager-(\\d*)\\.gitlab\\.com" yaml:"aggregation_regexp"`
}

ProjectPullPipelineJobsRunnerDescription ..

type ProjectPullPipelineTestReports added in v0.5.5

type ProjectPullPipelineTestReports struct {
	// Enabled set to true will attempt to retrieve the test report included in the pipeline.
	Enabled            bool                                             `default:"false" yaml:"enabled"`
	FromChildPipelines ProjectPullPipelineTestReportsFromChildPipelines `yaml:"from_child_pipelines"`
	TestCases          ProjectPullPipelineTestReportsTestCases          `yaml:"test_cases"`
}

ProjectPullPipelineTestReports ..

type ProjectPullPipelineTestReportsFromChildPipelines added in v0.5.6

type ProjectPullPipelineTestReportsFromChildPipelines struct {
	// Enabled set to true will pull pipeline jobs from child/downstream pipelines related metrics.
	Enabled bool `default:"false" yaml:"enabled"`
}

ProjectPullPipelineJobsFromChildPipelines ..

type ProjectPullPipelineTestReportsTestCases added in v0.5.6

type ProjectPullPipelineTestReportsTestCases struct {
	// Enabled set to true will attempt to retrieve the test report included in the pipeline.
	Enabled bool `default:"false" yaml:"enabled"`
}

ProjectPullPipelineTestCases ..

type ProjectPullPipelineVariables

type ProjectPullPipelineVariables struct {
	// Enabled set to true will attempt to retrieve variables included in the pipeline.
	Enabled bool `default:"false" yaml:"enabled"`

	// Regexp to filter pipeline variables values to fetch.
	Regexp string `default:".*" yaml:"regexp"`
}

ProjectPullPipelineVariables ..

type ProjectPullRefs

type ProjectPullRefs struct {
	// Configuration for pulling branches
	Branches ProjectPullRefsBranches `yaml:"branches"`

	// Configuration for pulling tags
	Tags ProjectPullRefsTags `yaml:"tags"`

	// Configuration for pulling merge requests
	MergeRequests ProjectPullRefsMergeRequests `yaml:"merge_requests"`
}

ProjectPullRefs ..

type ProjectPullRefsBranches

type ProjectPullRefsBranches struct {
	// Monitor pipelines related to project branches
	Enabled bool `default:"true" yaml:"enabled"`

	// Filter for branches to include
	Regexp string `default:"^(?:main|master)$" yaml:"regexp"`

	// Only keep most 'n' recently updated branches
	MostRecent uint `default:"0" yaml:"most_recent"`

	// If the most recent pipeline for the branch was last updated at
	// time greater than this value the metrics won't be exported
	MaxAgeSeconds uint `default:"0" yaml:"max_age_seconds"`

	// Prevent exporting metrics for deleted branches
	ExcludeDeleted bool `default:"true" yaml:"exclude_deleted"`
}

ProjectPullRefsBranches ..

type ProjectPullRefsMergeRequests

type ProjectPullRefsMergeRequests struct {
	// Monitor pipelines related to project merge requests.
	Enabled bool `yaml:"enabled"`

	// Only keep most 'n' recently updated merge requests.
	MostRecent uint `default:"0" yaml:"most_recent"`

	// If the most recent pipeline for the merge request was last updated at
	// time greater than this value the metrics won't be exported.
	MaxAgeSeconds uint `default:"0" yaml:"max_age_seconds"`
}

ProjectPullRefsMergeRequests ..

type ProjectPullRefsTags

type ProjectPullRefsTags struct {
	// Monitor pipelines related to project tags.
	Enabled bool `default:"true" yaml:"enabled"`

	// Filter for tags to include.
	Regexp string `default:".*" yaml:"regexp"`

	// Only keep most 'n' recently updated tags.
	MostRecent uint `default:"0" yaml:"most_recent"`

	// If the most recent pipeline for the tag was last updated at
	// time greater than this value the metrics won't be exported.
	MaxAgeSeconds uint `default:"0" yaml:"max_age_seconds"`

	// Prevent exporting metrics for deleted tags.
	ExcludeDeleted bool `default:"true" yaml:"exclude_deleted"`
}

ProjectPullRefsTags ..

type Projects

type Projects []Project

Projects ..

type Pull

type Pull struct {
	// ProjectsFromWildcards configuration
	ProjectsFromWildcards struct {
		OnInit          bool `default:"true" yaml:"on_init"`
		Scheduled       bool `default:"true" yaml:"scheduled"`
		IntervalSeconds int  `default:"1800" validate:"gte=1" yaml:"interval_seconds"`
	} `yaml:"projects_from_wildcards"`

	// EnvironmentsFromProjects configuration
	EnvironmentsFromProjects struct {
		OnInit          bool `default:"true" yaml:"on_init"`
		Scheduled       bool `default:"true" yaml:"scheduled"`
		IntervalSeconds int  `default:"1800" validate:"gte=1" yaml:"interval_seconds"`
	} `yaml:"environments_from_projects"`

	// RefsFromProjects configuration
	RefsFromProjects struct {
		OnInit          bool `default:"true" yaml:"on_init"`
		Scheduled       bool `default:"true" yaml:"scheduled"`
		IntervalSeconds int  `default:"300" validate:"gte=1" yaml:"interval_seconds"`
	} `yaml:"refs_from_projects"`

	// Metrics configuration
	Metrics struct {
		OnInit          bool `default:"true" yaml:"on_init"`
		Scheduled       bool `default:"true" yaml:"scheduled"`
		IntervalSeconds int  `default:"30" validate:"gte=1" yaml:"interval_seconds"`
	} `yaml:"metrics"`
}

Pull ..

type Redis

type Redis struct {
	// URL used to connect onto the redis endpoint
	// format: redis[s]://[:password@]host[:port][/db-number][?option=value])
	URL string `yaml:"url"`
}

Redis ..

type SchedulerConfig

type SchedulerConfig struct {
	OnInit          bool
	Scheduled       bool
	IntervalSeconds int
}

SchedulerConfig ..

func (SchedulerConfig) Log

func (sc SchedulerConfig) Log() log.Fields

Log returns some logging fields to showcase the configuration to the enduser.

type Server

type Server struct {
	// Enable profiling pages
	EnablePprof bool `default:"false" yaml:"enable_pprof"`

	// [address:port] to make the process listen upon
	ListenAddress string `default:":8080" yaml:"listen_address"`

	Metrics ServerMetrics `yaml:"metrics"`
	Webhook ServerWebhook `yaml:"webhook"`
}

Server ..

type ServerMetrics

type ServerMetrics struct {
	// Enable /metrics endpoint
	Enabled bool `default:"true" yaml:"enabled"`

	// Enable OpenMetrics content encoding in prometheus HTTP handler
	EnableOpenmetricsEncoding bool `default:"false" yaml:"enable_openmetrics_encoding"`
}

ServerMetrics ..

type ServerWebhook

type ServerWebhook struct {
	// Enable /webhook endpoint to support GitLab requests
	Enabled bool `default:"false" yaml:"enabled"`

	// Secret token to authenticate legitimate webhook requests coming from the GitLab server
	SecretToken string `validate:"required_if=Enabled true" yaml:"secret_token"`
}

ServerWebhook ..

type Wildcard

type Wildcard struct {
	// ProjectParameters holds parameters specific to the projects which
	// will be discovered using this wildcard.
	ProjectParameters `yaml:",inline"`

	Search   string        `yaml:"search"`
	Owner    WildcardOwner `yaml:"owner"`
	Archived bool          `yaml:"archived"`
}

Wildcard is a specific handler to dynamically search projects.

func NewWildcard

func NewWildcard() (w Wildcard)

NewWildcard returns a new wildcard with the default parameters.

type WildcardOwner

type WildcardOwner struct {
	Name             string `yaml:"name"`
	Kind             string `yaml:"kind"`
	IncludeSubgroups bool   `yaml:"include_subgroups"`
}

WildcardOwner ..

type Wildcards

type Wildcards []Wildcard

Wildcards ..

Jump to

Keyboard shortcuts

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