Skip to content

Commit ef227a4

Browse files
lukemassaWebOfNakedFancies
authored andcommitted
fix: Close metric scope after tests finish (runatlantis#5889)
Signed-off-by: Luke Massa <[email protected]> Signed-off-by: WebOfNakedFancies <[email protected]>
1 parent bba8251 commit ef227a4

10 files changed

+68
-47
lines changed

server/controllers/api_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/runatlantis/atlantis/server/events/models"
1919
. "github.com/runatlantis/atlantis/server/events/vcs/mocks"
2020
"github.com/runatlantis/atlantis/server/logging"
21-
"github.com/runatlantis/atlantis/server/metrics"
21+
"github.com/runatlantis/atlantis/server/metrics/metricstest"
2222
. "github.com/runatlantis/atlantis/testing"
2323
)
2424

@@ -262,7 +262,7 @@ func setup(t *testing.T) (controllers.APIController, *MockProjectCommandBuilder,
262262
logger := logging.NewNoopLogger(t)
263263
parser := NewMockEventParsing()
264264
repoAllowlistChecker, err := events.NewRepoAllowlistChecker("*")
265-
scope, _, _ := metrics.NewLoggingScope(logger, "null")
265+
scope := metricstest.NewLoggingScope(t, logger, "null")
266266
vcsClient := NewMockClient()
267267
workingDir := NewMockWorkingDir()
268268
Ok(t, err)

server/controllers/events/events_controller_e2e_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"github.com/runatlantis/atlantis/server/events/webhooks"
4040
jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks"
4141
"github.com/runatlantis/atlantis/server/logging"
42-
"github.com/runatlantis/atlantis/server/metrics"
42+
"github.com/runatlantis/atlantis/server/metrics/metricstest"
4343
. "github.com/runatlantis/atlantis/testing"
4444
)
4545

@@ -1427,7 +1427,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
14271427
CommitStatusUpdater: commitStatusUpdater,
14281428
Router: postWorkflowHookURLGenerator,
14291429
}
1430-
statsScope, _, _ := metrics.NewLoggingScope(logger, "atlantis")
1430+
statsScope := metricstest.NewLoggingScope(t, logger, "atlantis")
14311431

14321432
projectCommandBuilder := events.NewProjectCommandBuilder(
14331433
userConfig.EnablePolicyChecksFlag,

server/controllers/events/events_controller_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/runatlantis/atlantis/server/events/models"
3737
vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks"
3838
"github.com/runatlantis/atlantis/server/logging"
39-
"github.com/runatlantis/atlantis/server/metrics"
39+
"github.com/runatlantis/atlantis/server/metrics/metricstest"
4040
. "github.com/runatlantis/atlantis/testing"
4141
gitlab "gitlab.com/gitlab-org/api/client-go"
4242
)
@@ -228,7 +228,7 @@ func TestPost_GitlabCommentNotAllowlisted(t *testing.T) {
228228
RegisterMockTestingT(t)
229229
vcsClient := vcsmocks.NewMockClient()
230230
logger := logging.NewNoopLogger(t)
231-
scope, _, _ := metrics.NewLoggingScope(logger, "null")
231+
scope := metricstest.NewLoggingScope(t, logger, "null")
232232
e := events_controllers.VCSEventsController{
233233
Logger: logger,
234234
Scope: scope,
@@ -262,7 +262,7 @@ func TestPost_GitlabCommentNotAllowlistedWithSilenceErrors(t *testing.T) {
262262
RegisterMockTestingT(t)
263263
vcsClient := vcsmocks.NewMockClient()
264264
logger := logging.NewNoopLogger(t)
265-
scope, _, _ := metrics.NewLoggingScope(logger, "null")
265+
scope := metricstest.NewLoggingScope(t, logger, "null")
266266
e := events_controllers.VCSEventsController{
267267
Logger: logger,
268268
Scope: scope,
@@ -296,7 +296,7 @@ func TestPost_GithubCommentNotAllowlisted(t *testing.T) {
296296
RegisterMockTestingT(t)
297297
vcsClient := vcsmocks.NewMockClient()
298298
logger := logging.NewNoopLogger(t)
299-
scope, _, _ := metrics.NewLoggingScope(logger, "null")
299+
scope := metricstest.NewLoggingScope(t, logger, "null")
300300
e := events_controllers.VCSEventsController{
301301
Logger: logger,
302302
Scope: scope,
@@ -331,7 +331,7 @@ func TestPost_GithubCommentNotAllowlistedWithSilenceErrors(t *testing.T) {
331331
RegisterMockTestingT(t)
332332
vcsClient := vcsmocks.NewMockClient()
333333
logger := logging.NewNoopLogger(t)
334-
scope, _, _ := metrics.NewLoggingScope(logger, "null")
334+
scope := metricstest.NewLoggingScope(t, logger, "null")
335335
e := events_controllers.VCSEventsController{
336336
Logger: logger,
337337
Scope: scope,
@@ -868,7 +868,7 @@ func TestPost_BBServerPullClosed(t *testing.T) {
868868
allowlist, err := events.NewRepoAllowlistChecker("*")
869869
Ok(t, err)
870870
logger := logging.NewNoopLogger(t)
871-
scope, _, _ := metrics.NewLoggingScope(logger, "null")
871+
scope := metricstest.NewLoggingScope(t, logger, "null")
872872
ec := &events_controllers.VCSEventsController{
873873
PullCleaner: pullCleaner,
874874
Parser: &events.EventParser{
@@ -1002,7 +1002,7 @@ func setup(t *testing.T) (events_controllers.VCSEventsController, *mocks.MockGit
10021002
repoAllowlistChecker, err := events.NewRepoAllowlistChecker("*")
10031003
Ok(t, err)
10041004
logger := logging.NewNoopLogger(t)
1005-
scope, _, _ := metrics.NewLoggingScope(logger, "null")
1005+
scope := metricstest.NewLoggingScope(t, logger, "null")
10061006
e := events_controllers.VCSEventsController{
10071007
ExecutableName: "atlantis",
10081008
EmojiReaction: "eyes",

server/events/apply_command_runner_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/runatlantis/atlantis/server/events/models"
1414
"github.com/runatlantis/atlantis/server/events/models/testdata"
1515
"github.com/runatlantis/atlantis/server/logging"
16-
"github.com/runatlantis/atlantis/server/metrics"
16+
"github.com/runatlantis/atlantis/server/metrics/metricstest"
1717
. "github.com/runatlantis/atlantis/testing"
1818
"github.com/stretchr/testify/require"
1919
)
@@ -52,7 +52,7 @@ func TestApplyCommandRunner_IsLocked(t *testing.T) {
5252
t.Run(c.Description, func(t *testing.T) {
5353
vcsClient := setup(t)
5454

55-
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")
55+
scopeNull := metricstest.NewLoggingScope(t, logger, "atlantis")
5656

5757
pull := &github.PullRequest{
5858
State: github.Ptr("open"),
@@ -152,7 +152,7 @@ func TestApplyCommandRunner_IsSilenced(t *testing.T) {
152152
tc.database = db
153153
})
154154

155-
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")
155+
scopeNull := metricstest.NewLoggingScope(t, logger, "atlantis")
156156
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
157157

158158
cmd := &events.CommentCommand{Name: command.Apply}
@@ -514,7 +514,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) {
514514
t.Run(c.Description, func(t *testing.T) {
515515
vcsClient := setup(t)
516516

517-
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")
517+
scopeNull := metricstest.NewLoggingScope(t, logger, "atlantis")
518518

519519
pull := &github.PullRequest{
520520
State: github.Ptr("open"),

server/events/command_runner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/runatlantis/atlantis/server/core/db"
2626
"github.com/runatlantis/atlantis/server/events/command"
2727
"github.com/runatlantis/atlantis/server/logging"
28-
"github.com/runatlantis/atlantis/server/metrics"
28+
"github.com/runatlantis/atlantis/server/metrics/metricstest"
2929

3030
"github.com/google/go-github/v71/github"
3131
. "github.com/petergtz/pegomock/v4"
@@ -239,7 +239,7 @@ func setup(t *testing.T, options ...func(testConfig *TestConfig)) *vcsmocks.Mock
239239
When(postWorkflowHooksCommandRunner.RunPostHooks(Any[*command.Context](), Any[*events.CommentCommand]())).ThenReturn(nil)
240240

241241
globalCfg := valid.NewGlobalCfgFromArgs(valid.GlobalCfgArgs{})
242-
scope, _, _ := metrics.NewLoggingScope(logger, "atlantis")
242+
scope := metricstest.NewLoggingScope(t, logger, "atlantis")
243243

244244
ch = events.DefaultCommandRunner{
245245
VCSClient: vcsClient,

server/events/import_command_runner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/runatlantis/atlantis/server/events/models"
1010
"github.com/runatlantis/atlantis/server/events/models/testdata"
1111
"github.com/runatlantis/atlantis/server/logging"
12-
"github.com/runatlantis/atlantis/server/metrics"
12+
"github.com/runatlantis/atlantis/server/metrics/metricstest"
1313
. "github.com/runatlantis/atlantis/testing"
1414
)
1515

@@ -60,7 +60,7 @@ func TestImportCommandRunner_Run(t *testing.T) {
6060
tc.SilenceNoProjects = tt.silenced
6161
})
6262

63-
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")
63+
scopeNull := metricstest.NewLoggingScope(t, logger, "atlantis")
6464
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
6565
ctx := &command.Context{
6666
User: testdata.User,

server/events/plan_command_runner_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/runatlantis/atlantis/server/events/models"
1313
"github.com/runatlantis/atlantis/server/events/models/testdata"
1414
"github.com/runatlantis/atlantis/server/logging"
15-
"github.com/runatlantis/atlantis/server/metrics"
15+
"github.com/runatlantis/atlantis/server/metrics/metricstest"
1616
. "github.com/runatlantis/atlantis/testing"
1717
"github.com/stretchr/testify/require"
1818
)
@@ -90,7 +90,7 @@ func TestPlanCommandRunner_IsSilenced(t *testing.T) {
9090
tc.database = db
9191
})
9292

93-
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")
93+
scopeNull := metricstest.NewLoggingScope(t, logger, "atlantis")
9494
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
9595

9696
cmd := &events.CommentCommand{Name: command.Plan}
@@ -518,7 +518,7 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) {
518518
tc.database = db
519519
})
520520

521-
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")
521+
scopeNull := metricstest.NewLoggingScope(t, logger, "atlantis")
522522

523523
pull := &github.PullRequest{
524524
State: github.Ptr("open"),
@@ -760,7 +760,7 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) {
760760
tc.database = db
761761
})
762762

763-
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")
763+
scopeNull := metricstest.NewLoggingScope(t, logger, "atlantis")
764764
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
765765

766766
cmd := &events.CommentCommand{Name: command.Plan}
@@ -849,7 +849,7 @@ func TestPlanCommandRunner_SilenceFlagsClearsPendingStatus(t *testing.T) {
849849
})
850850

851851
modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num}
852-
scopeNull, _, _ := metrics.NewLoggingScope(logging.NewNoopLogger(t), "atlantis")
852+
scopeNull := metricstest.NewLoggingScope(t, logging.NewNoopLogger(t), "atlantis")
853853

854854
ctx := &command.Context{
855855
User: testdata.User,
@@ -1001,7 +1001,7 @@ func TestPlanCommandRunner_PendingApplyStatus(t *testing.T) {
10011001
tc.PendingApplyStatus = c.PendingApplyFlag
10021002
})
10031003

1004-
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis")
1004+
scopeNull := metricstest.NewLoggingScope(t, logger, "atlantis")
10051005

10061006
// Create repo with the appropriate VCS type
10071007
repo := testdata.GithubRepo

server/events/project_command_builder_internal_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"github.com/runatlantis/atlantis/server/events/models"
1515
vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks"
1616
"github.com/runatlantis/atlantis/server/logging"
17-
"github.com/runatlantis/atlantis/server/metrics"
17+
"github.com/runatlantis/atlantis/server/metrics/metricstest"
1818
. "github.com/runatlantis/atlantis/testing"
1919
)
2020

2121
// Test different permutations of global and repo config.
2222
func TestBuildProjectCmdCtx(t *testing.T) {
2323
logger := logging.NewNoopLogger(t)
24-
statsScope, _, _ := metrics.NewLoggingScope(logging.NewNoopLogger(t), "atlantis")
24+
statsScope := metricstest.NewLoggingScope(t, logging.NewNoopLogger(t), "atlantis")
2525
emptyPolicySets := valid.PolicySets{
2626
Version: nil,
2727
PolicySets: []valid.PolicySet{},
@@ -733,7 +733,7 @@ projects:
733733
}
734734

735735
func TestBuildProjectCmdCtx_WithRegExpCmdEnabled(t *testing.T) {
736-
statsScope, _, _ := metrics.NewLoggingScope(logging.NewNoopLogger(t), "atlantis")
736+
statsScope := metricstest.NewLoggingScope(t, logging.NewNoopLogger(t), "atlantis")
737737
emptyPolicySets := valid.PolicySets{
738738
Version: nil,
739739
PolicySets: []valid.PolicySet{},
@@ -863,7 +863,7 @@ projects:
863863
Ok(t, os.WriteFile(filepath.Join(tmp, "atlantis.yaml"), []byte(c.repoCfg), 0600))
864864
}
865865

866-
statsScope, _, _ := metrics.NewLoggingScope(logging.NewNoopLogger(t), "atlantis")
866+
statsScope := metricstest.NewLoggingScope(t, logging.NewNoopLogger(t), "atlantis")
867867

868868
terraformClient := tfclientmocks.NewMockClient()
869869

@@ -952,7 +952,7 @@ projects:
952952

953953
func TestBuildProjectCmdCtx_WithPolicCheckEnabled(t *testing.T) {
954954
logger := logging.NewNoopLogger(t)
955-
statsScope, _, _ := metrics.NewLoggingScope(logging.NewNoopLogger(t), "atlantis")
955+
statsScope := metricstest.NewLoggingScope(t, logging.NewNoopLogger(t), "atlantis")
956956
emptyPolicySets := valid.PolicySets{
957957
Version: nil,
958958
PolicySets: []valid.PolicySet{},
@@ -1110,7 +1110,7 @@ workflows:
11101110
if c.repoCfg != "" {
11111111
Ok(t, os.WriteFile(filepath.Join(tmp, "atlantis.yaml"), []byte(c.repoCfg), 0600))
11121112
}
1113-
statsScope, _, _ := metrics.NewLoggingScope(logging.NewNoopLogger(t), "atlantis")
1113+
statsScope := metricstest.NewLoggingScope(t, logging.NewNoopLogger(t), "atlantis")
11141114

11151115
terraformClient := tfclientmocks.NewMockClient()
11161116

@@ -1262,7 +1262,7 @@ projects:
12621262
if c.repoCfg != "" {
12631263
Ok(t, os.WriteFile(filepath.Join(tmp, "atlantis.yaml"), []byte(c.repoCfg), 0600))
12641264
}
1265-
statsScope, _, _ := metrics.NewLoggingScope(logging.NewNoopLogger(t), "atlantis")
1265+
statsScope := metricstest.NewLoggingScope(t, logging.NewNoopLogger(t), "atlantis")
12661266

12671267
terraformClient := tfclientmocks.NewMockClient()
12681268

@@ -1484,7 +1484,7 @@ autodiscover:
14841484
if c.repoCfg != "" {
14851485
Ok(t, os.WriteFile(filepath.Join(tmp, "atlantis.yaml"), []byte(c.repoCfg), 0600))
14861486
}
1487-
statsScope, _, _ := metrics.NewLoggingScope(logging.NewNoopLogger(t), "atlantis")
1487+
statsScope := metricstest.NewLoggingScope(t, logging.NewNoopLogger(t), "atlantis")
14881488

14891489
terraformClient := tfclientmocks.NewMockClient()
14901490

0 commit comments

Comments
 (0)