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

chore(dot): transform telemetry into an injectable interface #2113

Merged
merged 171 commits into from
Jan 13, 2022

Conversation

EclesioMeloJunior
Copy link
Member

@EclesioMeloJunior EclesioMeloJunior commented Dec 13, 2021

Changes

  • Remove mockery as mock generator and use mockgen
  • Adjust all tests with new EXPECTs
  • Create the telemetry.Telemetry interface
  • Update all services that uses telemetry to receive the telemetry.Telemetry interface as argument
  • Split the dot.createStateService in dot.dot.createStateService and dot.startStateService. This is necessary because the state.Start() function needs the telemetry and the telemetry needs the state initialization of the database, so I decoupled the database initialization from the state service start function.

Tests

go test github.com/ChainSafe/gossamer/dot/network -short
go test github.com/ChainSafe/gossamer/dot/telemetry -race

Issues

Primary Reviewer

EclesioMeloJunior and others added 30 commits December 6, 2021 09:54
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
dot/network/utils_test.go Outdated Show resolved Hide resolved
dot/network/utils_test.go Outdated Show resolved Hide resolved
dot/network/utils_test.go Outdated Show resolved Hide resolved
dot/network/utils_test.go Show resolved Hide resolved
@@ -666,15 +666,14 @@ func (ps *PeerSet) disconnect(setIdx int, reason DropReason, peers ...peer.ID) e
}

// start handles all the action for the peerSet.
func (ps *PeerSet) start(aq chan action, stopCh chan struct{}) {
func (ps *PeerSet) start(ctx context.Context, aq chan action) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename aq to actionQueue please; also maybe restrict to a read only / write only channel if you can

Copy link
Member Author

Choose a reason for hiding this comment

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

the PeerSet.actionQueue already is a <-chan action (read only channel)

Copy link
Contributor

Choose a reason for hiding this comment

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

So you could restrict the argument to be actionQueue chan<- action too 😉

dot/peerset/test_helpers.go Outdated Show resolved Hide resolved
dot/peerset/peerstate.go Outdated Show resolved Hide resolved
dot/peerset/peerstate.go Outdated Show resolved Hide resolved
}
}

func msgToJSON(message Message) ([]byte, error) {
Copy link
Contributor

@timwu20 timwu20 Jan 11, 2022

Choose a reason for hiding this comment

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

Add a MarshalJSON() method to the Message interface and implement them for all message types. You wouldn't have to do a marshal, then an unmarshal into a map[string]interface{}, and then another marshal.

Copy link
Member Author

Choose a reason for hiding this comment

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

@timwu20 implemented!

dot/telemetry/mailer.go Outdated Show resolved Hide resolved
dot/telemetry/mailer.go Outdated Show resolved Hide resolved
@@ -31,4 +31,5 @@ type Client interface {
// Message interface for Message functions
type Message interface {
messageType() string
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be private still?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, changed to Type()

@EclesioMeloJunior EclesioMeloJunior merged commit feeabff into development Jan 13, 2022
@EclesioMeloJunior EclesioMeloJunior deleted the eclesio/remove-mockery-network branch January 13, 2022 23:58
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.

test(dot/telemetry): improve telemetry tests and add t.Parallel() and remove race conditions
4 participants