Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream restart bug fix by introducing manager #412

Merged
merged 12 commits into from Sep 1, 2022

Conversation

sakshi-goyal-razorpay
Copy link
Contributor

@sakshi-goyal-razorpay sakshi-goyal-razorpay commented Aug 23, 2022

Description

Stream restart was not working because same ctx was used due to which we were not able to restart it. Have moved all the stream manager code to separate module, and also, re-initialised stream before restarting.

Fixes https://razorpay.atlassian.net/browse/METRO-127

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Tested existing functionality of worker
  • Tested restart functionality via unit tests
  • Tested stop functionality by deleting subscription

Is it a breaking change?

No, only the restart and stop functionality will be affected in case something is broken
Can this change be tested effectively via canary? No, as it only affects worker component, and canary is not done for worker yet

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works (if applicable)
  • I have added integration tests for the new feature (if applicable)
  • I have manually tested my code to the best of my abilities.

subscriberCoreMock := mocks2.NewMockICore(ctrl)
workerID := uuid.New().String()
httpConfig := &httpclient.Config{}
subModel := getMockSubModel("")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
undeclared name: getMockSubModel (typecheck)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is defined in same test package but a different file but golang cli linting is not checking all the files.
golangci/golangci-lint#1574
Seems like we need to change some configs

subModel := getMockSubModel("")

if wantErr {
subscriptionCoreMock.EXPECT().Get(gomock.Any(), subName).AnyTimes().Return(nil, fmt.Errorf("Something went wrong"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
undeclared name: subName (typecheck)

if wantErr {
subscriptionCoreMock.EXPECT().Get(gomock.Any(), subName).AnyTimes().Return(nil, fmt.Errorf("Something went wrong"))
} else {
subscriptionCoreMock.EXPECT().Get(gomock.Any(), subName).AnyTimes().Return(getMockSubModel(""), nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
undeclared name: subName (typecheck)

defaultMaxOuttandingBytes,
gomock.AssignableToTypeOf(make(chan *subscriber.PullRequest)),
gomock.AssignableToTypeOf(make(chan *subscriber.AckMessage)),
gomock.AssignableToTypeOf(make(chan *subscriber.ModAckMessage))).AnyTimes().Return(getMockSubscriber(ctx, ctrl), nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
undeclared name: getMockSubscriber (typecheck)

gomock.AssignableToTypeOf(make(chan *subscriber.PullRequest)),
gomock.AssignableToTypeOf(make(chan *subscriber.AckMessage)),
gomock.AssignableToTypeOf(make(chan *subscriber.ModAckMessage))).AnyTimes().Return(getMockSubscriber(ctx, ctrl), nil)
return NewPushStreamManager(ctx, workerID, subName, subscriptionCoreMock, subscriberCoreMock, httpConfig)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
undeclared name: subName (typecheck)

internal/tasks/subscriptiontask.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Merging #412 (3ebd7bc) into master (60aa181) will increase coverage by 0.36%.
The diff coverage is 82.50%.

@@            Coverage Diff             @@
##           master     #412      +/-   ##
==========================================
+ Coverage   59.17%   59.54%   +0.36%     
==========================================
  Files         124      125       +1     
  Lines        9570     9580      +10     
==========================================
+ Hits         5663     5704      +41     
+ Misses       3546     3515      -31     
  Partials      361      361              
Flag Coverage Δ
integration 44.52% <ø> (ø)
unittests 57.24% <82.50%> (+0.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
internal/tasks/subscriptiontask.go 75.46% <54.54%> (+0.31%) ⬆️
internal/stream/stream.go 82.26% <60.00%> (+8.34%) ⬆️
internal/stream/manager.go 89.06% <89.06%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

got, err := NewPushStreamManager(
ctx,
uuid.New().String(),
subName,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
undeclared name: subName (typecheck)

psm, err := NewPushStreamManager(
ctx,
uuid.New().String(),
subName,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
undeclared name: subName (typecheck)

psm, err := NewPushStreamManager(
ctx,
uuid.New().String(),
subName,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
undeclared name: subName (typecheck)

@sakshi-goyal-razorpay sakshi-goyal-razorpay requested review from a team, vnktram and sumitkrzp and removed request for a team August 24, 2022 06:26
Copy link
Contributor

@sumitkrzp sumitkrzp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but please resolve the comments by reviewdog.

@sakshi-goyal-razorpay
Copy link
Contributor Author

Looks good to me but please resolve the comments by reviewdog.

this is defined in same test package but a different file but golang cli linting is not checking all the files.
golangci/golangci-lint#1574
Seems like we need to change some configs, but will not be part of this PR

Copy link
Contributor

@sumitkrzp sumitkrzp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

internal/stream/manager.go Show resolved Hide resolved
}

func (psm *PushStreamManager) restartPushStream() {
psm.ps.Stop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap this under a semaphore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also let's verify if stop returns an error before we start a new one.

Suggested change
psm.ps.Stop()
err := psm.ps.Stop()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vnktram Why we want to wrap this inside a semaphore. This is called from the select for loop, and at a time, it will be executed by one go routine

@sakshi-goyal-razorpay sakshi-goyal-razorpay merged commit 408b950 into master Sep 1, 2022
@sakshi-goyal-razorpay sakshi-goyal-razorpay deleted the METRO-127-stream-restart-bug branch September 1, 2022 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants