/
project.go
179 lines (139 loc) · 6.23 KB
/
project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package config
import (
"github.com/creasty/defaults"
)
// ProjectParameters for the fetching configuration of Projects and Wildcards.
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"`
}
// ProjectPull ..
type ProjectPull struct {
Environments ProjectPullEnvironments `yaml:"environments"`
Refs ProjectPullRefs `yaml:"refs"`
Pipeline ProjectPullPipeline `yaml:"pipeline"`
}
// 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"`
}
// 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"`
}
// 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"`
}
// 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"`
}
// 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"`
}
// ProjectPullPipeline ..
type ProjectPullPipeline struct {
Jobs ProjectPullPipelineJobs `yaml:"jobs"`
Variables ProjectPullPipelineVariables `yaml:"variables"`
TestReports ProjectPullPipelineTestReports `yaml:"test_reports"`
}
// 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"`
}
// ProjectPullPipelineJobsFromChildPipelines ..
type ProjectPullPipelineJobsFromChildPipelines struct {
// Enabled set to true will pull pipeline jobs from child/downstream pipelines related metrics.
Enabled bool `default:"true" yaml:"enabled"`
}
// 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"`
}
// 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"`
}
// ProjectPullPipelineTestReports ..
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"`
}
// ProjectPullPipelineJobsFromChildPipelines ..
type ProjectPullPipelineTestReportsFromChildPipelines struct {
// Enabled set to true will pull pipeline jobs from child/downstream pipelines related metrics.
Enabled bool `default:"false" yaml:"enabled"`
}
// ProjectPullPipelineTestCases ..
type ProjectPullPipelineTestReportsTestCases struct {
// Enabled set to true will attempt to retrieve the test report included in the pipeline.
Enabled bool `default:"false" yaml:"enabled"`
}
// Project holds information about a GitLab 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"`
}
// Projects ..
type Projects []Project
// NewProject returns a new project composed with the default parameters.
func NewProject(name string) (p Project) {
defaults.MustSet(&p)
p.Name = name
return
}