-
Notifications
You must be signed in to change notification settings - Fork 8
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
[RelayMiner]: add proxy.Ping(...)
capability to test connectivity between relay servers and backend URLs
#744
base: main
Are you sure you want to change the base?
Changes from all commits
3fadb58
d5296fc
8de32ac
5067825
8ad5896
1e9236d
a48b247
4108c06
92fc293
d4f886c
c588ca1
d3bb424
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here as above. |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,6 +23,7 @@ You can find a fully featured example configuration at [relayminer_config_full_e | |||||||||||||||||
- [`smt_store_path`](#smt_store_path) | ||||||||||||||||||
- [`metrics`](#metrics) | ||||||||||||||||||
- [`pprof`](#pprof) | ||||||||||||||||||
- [`ping`](#ping) | ||||||||||||||||||
- [Pocket node connectivity](#pocket-node-connectivity) | ||||||||||||||||||
- [`query_node_rpc_url`](#query_node_rpc_url) | ||||||||||||||||||
- [`query_node_grpc_url`](#query_node_grpc_url) | ||||||||||||||||||
|
@@ -173,6 +174,21 @@ pprof: | |||||||||||||||||
|
||||||||||||||||||
You can learn how to use that endpoint on the [Performance Troubleshooting](../../develop/developer_guide/performance_troubleshooting.md) page. | ||||||||||||||||||
|
||||||||||||||||||
### `ping` | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very cool. 😎 |
||||||||||||||||||
|
||||||||||||||||||
Configures a `ping` server to test the connectivity of every backend URLs. If | ||||||||||||||||||
all the backend URLs are reachable, the endpoint returns a 200 HTTP | ||||||||||||||||||
Code. Otherwise, if one or more backend URLs aren't reachable, the service | ||||||||||||||||||
returns an 500 HTTP Internal server error. | ||||||||||||||||||
Comment on lines
+179
to
+182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered using 204 No Content for the success and 503 Service Unavailable for the error status codes? I think they could be more appropriate than 200 and 500.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
Example configuration: | ||||||||||||||||||
|
||||||||||||||||||
```yaml | ||||||||||||||||||
ping: | ||||||||||||||||||
enabled: true | ||||||||||||||||||
addr: localhost:8081 | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
## Pocket node connectivity | ||||||||||||||||||
|
||||||||||||||||||
```yaml | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentional diff? Same goes for all files in the loalnet/kubernetes directory. One simple way to revert these would be to do something like: git fetch origin
git checkout origin/main -- localnet/kubernetes
git add localnet/kubernetes
git commit |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
config: | ||
suppliers: | ||
- service_id: anvil | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://anvil:8547/ | ||
publicly_exposed_endpoints: | ||
- relayminer1 | ||
- service_id: rest | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://rest:10000/ | ||
publicly_exposed_endpoints: | ||
- relayminer1 | ||
- service_id: ollama | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://ollama:11434/ | ||
publicly_exposed_endpoints: | ||
- relayminer1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
config: | ||
suppliers: | ||
- service_id: anvil | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://anvil:8547/ | ||
publicly_exposed_endpoints: | ||
- relayminer1 | ||
- service_id: ollama | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://ollama:11434/ | ||
publicly_exposed_endpoints: | ||
- relayminer1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
config: | ||
suppliers: | ||
- service_id: anvil | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://anvil:8547/ | ||
publicly_exposed_endpoints: | ||
- relayminer1 | ||
- service_id: rest | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://rest:10000/ | ||
publicly_exposed_endpoints: | ||
- relayminer1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
config: | ||
suppliers: | ||
- service_id: anvil | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://anvil:8547/ | ||
publicly_exposed_endpoints: | ||
- relayminer2 | ||
- service_id: ollama | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://ollama:11434/ | ||
publicly_exposed_endpoints: | ||
- relayminer2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
config: | ||
suppliers: | ||
- service_id: anvil | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://anvil:8547/ | ||
publicly_exposed_endpoints: | ||
- relayminer3 | ||
- service_id: ollama | ||
listen_url: http://0.0.0.0:8545 | ||
service_config: | ||
backend_url: http://ollama:11434/ | ||
publicly_exposed_endpoints: | ||
- relayminer3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ config: | |
pprof: | ||
enabled: true | ||
addr: localhost:6060 | ||
ping: | ||
enabled: true | ||
addr: localhost:8081 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to add something to the deployment and/or service, and port forwards in tilt to expose this locally? cc @okdas There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this file used? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,6 @@ suppliers: | |
pprof: | ||
enabled: false | ||
addr: localhost:6060 | ||
ping: | ||
enabled: false | ||
addr: localhost:8082 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,6 @@ suppliers: | |
pprof: | ||
enabled: false | ||
addr: localhost:6070 | ||
ping: | ||
enabled: false | ||
addr: localhost:8081 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
|
@@ -134,6 +135,17 @@ func runRelayer(cmd *cobra.Command, _ []string) error { | |
} | ||
} | ||
|
||
if relayMinerConfig.Ping.Enabled { | ||
eddyzags marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ln, err := net.Listen("tcp", relayMinerConfig.Ping.Addr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any kind of validation on the address? What's the UX like if it's invalid? |
||
if err != nil { | ||
return fmt.Errorf("failed to listen ping server: %w", err) | ||
} | ||
|
||
if err := relayMiner.ServePing(ctx, ln); err != nil { | ||
return fmt.Errorf("failed to start ping server: %w", err) | ||
} | ||
Comment on lines
+139
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we extract this to a function please? |
||
} | ||
|
||
// Start the relay miner | ||
logger.Info().Msg("Starting relay miner...") | ||
if err := relayMiner.Start(ctx); err != nil && !errors.Is(err, http.ErrServerClosed) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,11 @@ func ParseRelayMinerConfigs(configContent []byte) (*RelayMinerConfig, error) { | |
Addr: yamlRelayMinerConfig.Pprof.Addr, | ||
} | ||
|
||
relayMinerConfig.Ping = &RelayMinerPingConfig{ | ||
Enabled: yamlRelayMinerConfig.Ping.Enabled, | ||
Addr: yamlRelayMinerConfig.Ping.Addr, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wdyt about doing something like |
||
} | ||
|
||
// Hydrate the pocket node urls | ||
if err := relayMinerConfig.HydratePocketNodeUrls(&yamlRelayMinerConfig.PocketNode); err != nil { | ||
return nil, err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,13 @@ type YAMLRelayMinerConfig struct { | |
Pprof YAMLRelayMinerPprofConfig `yaml:"pprof"` | ||
SmtStorePath string `yaml:"smt_store_path"` | ||
Suppliers []YAMLRelayMinerSupplierConfig `yaml:"suppliers"` | ||
Ping YAMLRelayMinerPingConfig `yaml:"ping"` | ||
} | ||
|
||
// YAMLRelayMinerPingConfig represents the configuration to expose a ping server. | ||
type YAMLRelayMinerPingConfig struct { | ||
Enabled bool `yaml:"enabled"` | ||
Addr string `yaml:"addr"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add a godoc-style comment that includes the expected format for the address (e.g. |
||
} | ||
|
||
// YAMLRelayMinerPocketNodeConfig is the structure used to unmarshal the pocket | ||
|
@@ -83,6 +90,14 @@ type RelayMinerConfig struct { | |
Pprof *RelayMinerPprofConfig | ||
Servers map[string]*RelayMinerServerConfig | ||
SmtStorePath string | ||
Ping *RelayMinerPingConfig | ||
} | ||
|
||
// RelayMinerPingConfig is the structure resulting from parsing the ping | ||
// server configuration. | ||
type RelayMinerPingConfig struct { | ||
eddyzags marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Enabled bool | ||
Addr string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, copypasta plz. |
||
} | ||
|
||
// RelayMinerPocketNodeConfig is the structure resulting from parsing the pocket | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -139,14 +139,20 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
if err := rp.BuildProvidedServices(ctx); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Is there a reason to remove this line; otherwise, please revert. |
||||||||||||||||||||||||||||||||||||||||||||||||||
// Start the ring cache. | ||||||||||||||||||||||||||||||||||||||||||||||||||
rp.ringCache.Start(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
startGroup, ctx := errgroup.WithContext(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
for _, relayServer := range rp.servers { | ||||||||||||||||||||||||||||||||||||||||||||||||||
server := relayServer // create a new variable scoped to the anonymous function | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// Ensure that each backing data node responds to a ping request | ||||||||||||||||||||||||||||||||||||||||||||||||||
// (at least) before continuing operation. | ||||||||||||||||||||||||||||||||||||||||||||||||||
if err := server.Ping(ctx); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
eddyzags marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
startGroup.Go(func() error { return server.Start(ctx) }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -187,3 +193,22 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// PingAll tests the connectivity between all the managed relay servers and their respective backend URLs. | ||||||||||||||||||||||||||||||||||||||||||||||||||
func (rp *relayerProxy) PingAll(ctx context.Context) []error { | ||||||||||||||||||||||||||||||||||||||||||||||||||
var errs []error | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
for _, srv := range rp.servers { | ||||||||||||||||||||||||||||||||||||||||||||||||||
if err := srv.Ping(ctx); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
rp.logger.Error().Err(err). | ||||||||||||||||||||||||||||||||||||||||||||||||||
Msg("an unexpected error occured while pinging backend URL") | ||||||||||||||||||||||||||||||||||||||||||||||||||
errs = append(errs, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
if len(errs) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return errs | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+199
to
+213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about something like this using
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also wondering if we really need to log the error in addition to returning it. Could you please double-check whether and where the returned error is printed? If, for example, the supplier sees the ping error when starting the relayminer binary, then I don't think we need to log the error. |
||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -152,6 +152,11 @@ func TestRelayerProxy_StartAndStop(t *testing.T) { | |||||||||||||
// Block so relayerProxy has sufficient time to start | ||||||||||||||
time.Sleep(100 * time.Millisecond) | ||||||||||||||
|
||||||||||||||
errs := rp.PingAll(ctx) | ||||||||||||||
for _, err := range errs { | ||||||||||||||
require.NoError(t, err) | ||||||||||||||
} | ||||||||||||||
Comment on lines
+155
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then this would reduce to:
Suggested change
|
||||||||||||||
|
||||||||||||||
// Test that RelayerProxy is handling requests (ignoring the actual response content) | ||||||||||||||
res, err := http.DefaultClient.Get(fmt.Sprintf("http://%s/", servicesConfigMap[defaultRelayMinerServer].ListenAddress)) | ||||||||||||||
require.NoError(t, err) | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were any of the makefile changes intentional? Otherwise, let's revert. I split the makefile up in #816.