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

Adds Faucet + gateway to launcher #1734

Merged
merged 3 commits into from
Jan 3, 2024
Merged

Conversation

otherview
Copy link
Contributor

Why this change is needed

https://github.com/ten-protocol/ten-internal/issues/2701

  • Adds Faucet + Gateway to the launcher
  • Removes unused Port flags in the faucet
  • Adds health endpoint to the faucet

Copy link

coderabbitai bot commented Jan 3, 2024

Walkthrough

The overall change encompasses a significant update to the configuration and management of the faucet and gateway modules within a testnet environment. The update includes the removal of the Port field from the faucet configuration, the addition of readiness checks, the introduction of new Docker-related functionality, and the removal of faucetPort flags from CLI tools. A new health endpoint has also been added to the faucet web server.

Changes

File Path Change Summary
integration/faucet/faucet_test.go
tools/faucet/cmd/cli.go
tools/faucet/faucet/faucet_config.go
Removed Port configuration from faucet module.
testnet/launcher/docker.go Added imports, module instances, configuration, startup sequences, and readiness checks for faucet and gateway.
testnet/launcher/faucet/config.go
testnet/launcher/gateway/config.go
Introduced Config structs and associated functions for faucet and gateway configurations.
testnet/launcher/faucet/docker.go
testnet/launcher/gateway/docker.go
Added DockerFaucet and DockerGateway types with methods for managing Docker containers and readiness checks.
tools/faucet/webserver/web_server.go Added a new /health endpoint to the web server for faucet health status.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@@ -49,7 +49,6 @@ func TestFaucet(t *testing.T) {
time.Sleep(2 * time.Second)

faucetConfig := &faucet.Config{
Port: startPort,
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 flag was unused and threw me off when hooking up the ports

Comment on lines +175 to +181

// returns the remaining native balance of the faucet
func healthReqHandler() gin.HandlerFunc {
return func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"healthy": true})
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Faucet didn't have a health handler - particularly useful to determine when the container is up and running.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 9

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 986f699 and 6ab3fd2.
Files selected for processing (9)
  • integration/faucet/faucet_test.go (1 hunks)
  • testnet/launcher/docker.go (2 hunks)
  • testnet/launcher/faucet/config.go (1 hunks)
  • testnet/launcher/faucet/docker.go (1 hunks)
  • testnet/launcher/gateway/config.go (1 hunks)
  • testnet/launcher/gateway/docker.go (1 hunks)
  • tools/faucet/cmd/cli.go (3 hunks)
  • tools/faucet/faucet/faucet_config.go (1 hunks)
  • tools/faucet/webserver/web_server.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • tools/faucet/cmd/cli.go
  • tools/faucet/faucet/faucet_config.go
Additional comments: 13
testnet/launcher/faucet/config.go (3)
  • 6-13: The Config struct fields are unexported, which may limit the ability to set them directly from outside the package. Ensure this is intentional and that configuration is only intended to be done via the provided option functions.

  • 15-23: The NewFaucetConfig function correctly applies the functional options pattern to configure the Config object.

  • 25-53: The option functions WithTenNodeHost, WithFaucetPrivKey, WithDockerImage, WithTenNodePort, and WithFaucetPort are correctly implemented following the functional options pattern.

testnet/launcher/gateway/config.go (3)
  • 6-14: The Config struct fields are unexported, which may limit the ability to set them directly from outside the package. Ensure this is intentional and that configuration is only intended to be done via the provided option functions.

  • 16-24: The NewGatewayConfig function correctly applies the functional options pattern to configure the Config object.

  • 26-60: The option functions WithTenNodeHost, WithDockerImage, WithTenNodeHTTPPort, WithTenNodeWSPort, WithGatewayHTTPPort, and WithGatewayWSPort are correctly implemented following the functional options pattern.

testnet/launcher/faucet/docker.go (1)
  • 39-55: The IsReady method correctly implements a retry mechanism to check the readiness of the Docker Faucet service. Ensure that the hardcoded http://127.0.0.1 address is appropriate for the readiness check in all deployment scenarios.
testnet/launcher/gateway/docker.go (1)
  • 41-57: The IsReady method correctly implements a retry mechanism to check the readiness of the Docker Gateway service. Ensure that the hardcoded http://127.0.0.1 address is appropriate for the readiness check in all deployment scenarios.
tools/faucet/webserver/web_server.go (1)
  • 176-181: The healthReqHandler function is added to return the health status of the faucet. Ensure that the health status accurately reflects the operational state of the faucet.
integration/faucet/faucet_test.go (1)
  • 51-54: The Port declaration has been removed from the faucetConfig initialization. Verify that the removal of this field does not affect the test's ability to connect to the correct port for the faucet service.
Verification successful

The output from the shell script shows that the faucetConfig struct in faucet_test.go has been updated to include a ServerPort field, which is used to get the faucet balance and fund the wallet. This suggests that the Port field has been replaced with ServerPort, and the tests are using this new field to connect to the correct port for the faucet service.

Based on this information, it appears that the removal of the Port field does not affect the test's ability to connect to the correct port for the faucet service, as the ServerPort field is being used for this purpose.

  • The Port field has been removed from faucetConfig.
  • A ServerPort field is present and used in the test to connect to the faucet service.

Given these points, the review comment has been addressed in the code, and the test appears to be correctly configured to connect to the faucet service without the Port field.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the faucet service is correctly configured without the Port field.
rg --type go 'faucetConfig' --context 5

Length of output: 3453

testnet/launcher/docker.go (3)
  • 13-14: The addition of import statements for faucet and gateway modules is noted. Ensure that these modules are used appropriately in the subsequent code and that their integration follows best practices.

  • 200-200: The message indicating the readiness of the gateway is clear and reflects the correct port. This is good for user clarity.

  • 202-202: The final message indicates the successful launch of the network. This is a good practice to inform the user of the completion of the process.

testnet/launcher/docker.go Outdated Show resolved Hide resolved
testnet/launcher/docker.go Outdated Show resolved Hide resolved
testnet/launcher/docker.go Show resolved Hide resolved
testnet/launcher/docker.go Show resolved Hide resolved
testnet/launcher/docker.go Outdated Show resolved Hide resolved
testnet/launcher/faucet/docker.go Show resolved Hide resolved
testnet/launcher/faucet/docker.go Show resolved Hide resolved
testnet/launcher/gateway/docker.go Show resolved Hide resolved
testnet/launcher/gateway/docker.go Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6ab3fd2 and a0d5092.
Files selected for processing (1)
  • testnet/launcher/docker.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • testnet/launcher/docker.go

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

LGTM, few minor comments

return fmt.Errorf("unable to wait for faucet to be ready - %w", err)
}

fmt.Println("Faucet ready to be accessed at http://127.0.0.1:99/ ...")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This port number should be read off the config or from constant probably, same with the gateway one below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The configs don't have external reading, but I agree this should be some form of constant. Changed 👍

interval := time.Second

return retry.Do(func() error {
statusCode, _, err := fasthttp.Get(nil, fmt.Sprintf("http://127.0.0.1:%d/health/", n.cfg.faucetPort))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we capture the body in case it has useful error information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No useful info from the health point responses for the faucet and the gw atm, but I guess we can do that in the future.

interval := time.Second

return retry.Do(func() error {
statusCode, _, err := fasthttp.Get(nil, fmt.Sprintf("http://127.0.0.1:%d/health/", n.cfg.gatewayHTTPPort))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again with the body potentially to speed up debugging.

Copy link
Contributor

@zkokelj zkokelj left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a0d5092 and aa5aa71.
Files selected for processing (1)
  • testnet/launcher/docker.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • testnet/launcher/docker.go

@otherview
Copy link
Contributor Author

@otherview otherview merged commit e984af1 into main Jan 3, 2024
2 checks passed
@otherview otherview deleted the pedro/launcher_add_faucet_gateway branch January 3, 2024 16:54
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.

3 participants