Skip to content

Commit f06fdff

Browse files
authored
Merge branch 'main' into fix-update-concurrency-group-expression-in-e2e-wor
2 parents d03f05e + 5070934 commit f06fdff

File tree

75 files changed

+730
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+730
-370
lines changed

.github/workflows/e2e.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ jobs:
8080
- uses: ko-build/setup-ko@v0.9
8181

8282
- name: Install gosmee
83-
uses: jaxxstorm/action-install-gh-release@v2.0.0
83+
uses: jaxxstorm/action-install-gh-release@v2.1.0
8484
with:
8585
repo: chmouel/gosmee
8686

87+
- name: Install Snazy
88+
uses: jaxxstorm/action-install-gh-release@v2.0.0
89+
with:
90+
repo: chmouel/snazy
91+
8792
- name: Run gosmee
8893
run: |
8994
nohup gosmee client --saveDir /tmp/gosmee-replay ${{ secrets.PYSMEE_URL }} "http://${CONTROLLER_DOMAIN_URL}" &

docs/content/docs/install/metrics.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ You can configure these exporters by referring to the [observability configurati
1212

1313
| Name | Type | Description |
1414
|------------------------------------------------------|---------|--------------------------------------------------------------------|
15+
| `pipelines_as_code_git_provider_api_request_count` | Counter | Number of API requests submitted to git providers |
1516
| `pipelines_as_code_pipelinerun_count` | Counter | Number of pipelineruns created by pipelines-as-code |
1617
| `pipelines_as_code_pipelinerun_duration_seconds_sum` | Counter | Number of seconds all pipelineruns have taken in pipelines-as-code |
1718
| `pipelines_as_code_running_pipelineruns_count` | Gauge | Number of running pipelineruns in pipelines-as-code |
19+
20+
**Note:** The metric `pipelines_as_code_git_provider_api_request_count`
21+
is emitted by both the Controller and the Watcher, since both services
22+
use Git providers' APIs. When analyzing this metric, you may need to
23+
combine both services' metrics. For example, using PromQL:
24+
25+
- `sum (pac_controller_pipelines_as_code_git_provider_api_request_count or pac_watcher_pipelines_as_code_git_provider_api_request_count)`
26+
- `sum (rate(pac_controller_pipelines_as_code_git_provider_api_request_count[1m]) or rate(pac_watcher_pipelines_as_code_git_provider_api_request_count[1m]))`
27+
28+
![Prometheus query for git provider API usage metrics combined from both the Watcher and the Controller](/images/git-api-usage-metrics-prometheus-query.png)
125 KB
Loading

hack/gh-workflow-ci.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ collect_logs() {
9797
local github_ghe_smee_url="${TEST_GITHUB_SECOND_SMEE_URL}"
9898

9999
mkdir -p /tmp/logs
100+
# Output logs to stdout so we can see via the web interface directly
101+
kubectl logs -n pipelines-as-code -l app.kubernetes.io/part-of=pipelines-as-code \
102+
--all-containers=true --tail=1000 >/tmp/logs/pac-pods.log
103+
if command -v "snazy" >/dev/null 2>&1; then
104+
snazy --skip-line-regexp="^(Reconcile (succeeded|error)|Updating webhook)" /tmp/logs/pac-pods.log
105+
else
106+
# snazy for the poors
107+
python -c "import sys,json,datetime; [print(f'• { (lambda t: datetime.datetime.fromisoformat(t.rstrip(\"Z\")).strftime(\"%H:%M:%S\") if isinstance(t,str) else datetime.datetime.fromtimestamp(t).strftime(\"%H:%M:%S\"))(json.loads(l.strip())[\"ts\"] )} {json.loads(l.strip()).get(\"msg\",\"\")}') if l.strip().startswith('{') else print(l.strip()) for l in sys.stdin]" \
108+
</tmp/logs/pac-pods.log
109+
fi
110+
100111
kind export logs /tmp/logs
101112
[[ -d /tmp/gosmee-replay ]] && cp -a /tmp/gosmee-replay /tmp/logs/
102113

pkg/cli/prompt/prompt.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ package prompt
33
import "github.com/AlecAivazis/survey/v2"
44

55
// SurveyAskOne ask one question to be stubbed later.
6-
var SurveyAskOne = func(p survey.Prompt, response any, opts ...survey.AskOpt) error {
7-
return survey.AskOne(p, response, opts...)
8-
}
6+
var SurveyAskOne func(survey.Prompt, any, ...survey.AskOpt) error = survey.AskOne
97

108
// SurveyAsk ask questions to be stubbed later.
11-
var SurveyAsk = func(qs []*survey.Question, response any, opts ...survey.AskOpt) error {
12-
return survey.Ask(qs, response, opts...)
13-
}
9+
var SurveyAsk func([]*survey.Question, any, ...survey.AskOpt) error = survey.Ask

pkg/matcher/annotation_matcher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,9 +1351,9 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) {
13511351
fakeclient, mux, ghTestServerURL, teardown := ghtesthelper.SetupGH()
13521352
defer teardown()
13531353
vcx := &ghprovider.Provider{
1354-
Client: fakeclient,
1355-
Token: github.Ptr("None"),
1354+
Token: github.Ptr("None"),
13561355
}
1356+
vcx.SetGithubClient(fakeclient)
13571357
if tt.args.runevent.Request == nil {
13581358
tt.args.runevent.Request = &info.Request{Header: http.Header{}, Payload: nil}
13591359
}

pkg/metrics/metrics.go

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ var runningPRCount = stats.Float64("pipelines_as_code_running_pipelineruns_count
3030
"number of running pipelineruns by pipelines as code",
3131
stats.UnitDimensionless)
3232

33+
var gitProviderAPIRequestCount = stats.Int64(
34+
"pipelines_as_code_git_provider_api_request_count",
35+
"number of API requests from pipelines as code to git providers",
36+
stats.UnitDimensionless,
37+
)
38+
3339
// Recorder holds keys for metrics.
3440
type Recorder struct {
3541
initialized bool
@@ -61,36 +67,42 @@ func NewRecorder() (*Recorder, error) {
6167

6268
provider, errRegistering := tag.NewKey("provider")
6369
if errRegistering != nil {
70+
ErrRegistering = errRegistering
6471
return
6572
}
6673
R.provider = provider
6774

6875
eventType, errRegistering := tag.NewKey("event-type")
6976
if errRegistering != nil {
77+
ErrRegistering = errRegistering
7078
return
7179
}
7280
R.eventType = eventType
7381

7482
namespace, errRegistering := tag.NewKey("namespace")
7583
if errRegistering != nil {
84+
ErrRegistering = errRegistering
7685
return
7786
}
7887
R.namespace = namespace
7988

8089
repository, errRegistering := tag.NewKey("repository")
8190
if errRegistering != nil {
91+
ErrRegistering = errRegistering
8292
return
8393
}
8494
R.repository = repository
8595

8696
status, errRegistering := tag.NewKey("status")
8797
if errRegistering != nil {
98+
ErrRegistering = errRegistering
8899
return
89100
}
90101
R.status = status
91102

92103
reason, errRegistering := tag.NewKey("reason")
93104
if errRegistering != nil {
105+
ErrRegistering = errRegistering
94106
return
95107
}
96108
R.reason = reason
@@ -116,11 +128,18 @@ func NewRecorder() (*Recorder, error) {
116128
Aggregation: view.LastValue(),
117129
TagKeys: []tag.Key{R.namespace, R.repository},
118130
}
131+
gitProviderAPIRequestView = &view.View{
132+
Description: gitProviderAPIRequestCount.Description(),
133+
Measure: gitProviderAPIRequestCount,
134+
Aggregation: view.Count(),
135+
TagKeys: []tag.Key{R.provider, R.eventType, R.namespace, R.repository},
136+
}
119137
)
120138

121-
view.Unregister(prCountView, prDurationView, runningPRView)
122-
errRegistering = view.Register(prCountView, prDurationView, runningPRView)
139+
view.Unregister(prCountView, prDurationView, runningPRView, gitProviderAPIRequestView)
140+
errRegistering = view.Register(prCountView, prDurationView, runningPRView, gitProviderAPIRequestView)
123141
if errRegistering != nil {
142+
ErrRegistering = errRegistering
124143
R.initialized = false
125144
return
126145
}
@@ -129,12 +148,19 @@ func NewRecorder() (*Recorder, error) {
129148
return R, ErrRegistering
130149
}
131150

132-
// Count logs number of times a pipelinerun is ran for a provider.
133-
func (r *Recorder) Count(provider, event, namespace, repository string) error {
151+
func (r Recorder) assertInitialized() error {
134152
if !r.initialized {
135153
return fmt.Errorf(
136154
"ignoring the metrics recording for pipelineruns, failed to initialize the metrics recorder")
137155
}
156+
return nil
157+
}
158+
159+
// Count logs number of times a pipelinerun is ran for a provider.
160+
func (r *Recorder) Count(provider, event, namespace, repository string) error {
161+
if err := r.assertInitialized(); err != nil {
162+
return err
163+
}
138164

139165
ctx, err := tag.New(
140166
context.Background(),
@@ -153,9 +179,8 @@ func (r *Recorder) Count(provider, event, namespace, repository string) error {
153179

154180
// CountPRDuration collects duration taken by a pipelinerun in seconds accumulate them in prDurationCount.
155181
func (r *Recorder) CountPRDuration(namespace, repository, status, reason string, duration time.Duration) error {
156-
if !r.initialized {
157-
return fmt.Errorf(
158-
"ignoring the metrics recording for pipelineruns, failed to initialize the metrics recorder")
182+
if err := r.assertInitialized(); err != nil {
183+
return err
159184
}
160185

161186
ctx, err := tag.New(
@@ -175,9 +200,8 @@ func (r *Recorder) CountPRDuration(namespace, repository, status, reason string,
175200

176201
// RunningPipelineRuns emits the number of running PipelineRuns for a repository and namespace.
177202
func (r *Recorder) RunningPipelineRuns(namespace, repository string, runningPRs float64) error {
178-
if !r.initialized {
179-
return fmt.Errorf(
180-
"ignoring the metrics recording for pipelineruns, failed to initialize the metrics recorder")
203+
if err := r.assertInitialized(); err != nil {
204+
return err
181205
}
182206

183207
ctx, err := tag.New(
@@ -266,6 +290,26 @@ func (r *Recorder) ReportRunningPipelineRuns(ctx context.Context, lister listers
266290
}
267291
}
268292

293+
func (r *Recorder) ReportGitProviderAPIUsage(provider, event, namespace, repository string) error {
294+
if err := r.assertInitialized(); err != nil {
295+
return err
296+
}
297+
298+
ctx, err := tag.New(
299+
context.Background(),
300+
tag.Insert(r.provider, provider),
301+
tag.Insert(r.eventType, event),
302+
tag.Insert(r.namespace, namespace),
303+
tag.Insert(r.repository, repository),
304+
)
305+
if err != nil {
306+
return err
307+
}
308+
309+
metrics.Record(ctx, gitProviderAPIRequestCount.M(1))
310+
return nil
311+
}
312+
269313
func ResetRecorder() {
270314
Once = sync.Once{}
271315
R = nil

pkg/pipelineascode/match_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ func TestGetPipelineRunsFromRepo(t *testing.T) {
254254
ConsoleURL: "https://console.url",
255255
}
256256
vcx := &ghprovider.Provider{
257-
Client: fakeclient,
258257
Token: github.Ptr("None"),
259258
Logger: logger,
260259
}
260+
vcx.SetGithubClient(fakeclient)
261261
pacInfo := &info.PacOpts{
262262
Settings: settings.Settings{
263263
ApplicationName: "Pipelines as Code CI",

pkg/pipelineascode/pipelineascode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,11 @@ func TestRun(t *testing.T) {
606606
},
607607
}
608608
vcx := &ghprovider.Provider{
609-
Client: fakeclient,
610609
Run: cs,
611610
Token: github.Ptr("None"),
612611
Logger: logger,
613612
}
613+
vcx.SetGithubClient(fakeclient)
614614
vcx.SetPacInfo(pacInfo)
615615
p := NewPacs(&tt.runevent, vcx, cs, pacInfo, k8int, logger, nil)
616616
err := p.Run(ctx)

pkg/provider/bitbucketcloud/acl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (v *Provider) IsAllowed(ctx context.Context, event *info.Event) (bool, erro
2727
}
2828

2929
func (v *Provider) isWorkspaceMember(event *info.Event) (bool, error) {
30-
members, err := v.Client.Workspaces.Members(event.Organization)
30+
members, err := v.Client().Workspaces.Members(event.Organization)
3131
if err != nil {
3232
return false, err
3333
}
@@ -83,7 +83,7 @@ func (v *Provider) checkMember(ctx context.Context, event *info.Event) (bool, er
8383
}
8484

8585
func (v *Provider) checkOkToTestCommentFromApprovedMember(ctx context.Context, event *info.Event) (bool, error) {
86-
commentsIntf, err := v.Client.Repositories.PullRequests.GetComments(&bitbucket.PullRequestsOptions{
86+
commentsIntf, err := v.Client().Repositories.PullRequests.GetComments(&bitbucket.PullRequestsOptions{
8787
Owner: event.Organization,
8888
RepoSlug: event.Repository,
8989
ID: strconv.Itoa(event.PullRequestNumber),

0 commit comments

Comments
 (0)