Do not query repo ID if metrics are disabled (#2803)

This skips the call to `getRepoModel` if metrics are disabled and the repository ID is not required.

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #2802 

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Vaibhav Kamra 2023-03-15 06:12:28 -07:00 committed by GitHub
parent 18606773b2
commit 3d96507719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -209,12 +209,17 @@ func Connect(
return nil, errors.Wrap(err, "constructing event bus")
}
rm, err := getRepoModel(ctx, ms)
rm := &repositoryModel{}
// Do not query repo ID if metrics are disabled
if !opts.DisableMetrics {
rm, err = getRepoModel(ctx, ms)
if err != nil {
return nil, errors.New("retrieving repo info")
}
bus.SetRepoID(string(rm.ID))
}
complete <- struct{}{}

View File

@ -219,3 +219,22 @@ func (suite *RepositoryIntegrationSuite) TestNewRestore() {
require.NoError(t, err)
require.NotNil(t, ro)
}
func (suite *RepositoryIntegrationSuite) TestConnect_DisableMetrics() {
ctx, flush := tester.NewContext()
defer flush()
t := suite.T()
// need to initialize the repository before we can test connecting to it.
st := tester.NewPrefixedS3Storage(t)
_, err := repository.Initialize(ctx, account.Account{}, st, control.Options{})
require.NoError(t, err)
// now re-connect
r, err := repository.Connect(ctx, account.Account{}, st, control.Options{DisableMetrics: true})
assert.NoError(t, err)
assert.Equal(t, "", r.GetID())
}