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

Node heartbeats #3709

Merged
merged 28 commits into from
Apr 8, 2024
Merged

Node heartbeats #3709

merged 28 commits into from
Apr 8, 2024

Conversation

rossjones
Copy link
Contributor

@rossjones rossjones commented Mar 26, 2024

Implements heartbeats for compute nodes, sending heartbeat messages to the requester node over NATS PubSub. The server, upon receiving a heartbeat updates the map of nodes to include the current server-side timestamp.

Compute nodes using the heartbeat client, will continuously send heartbeat messages every n seconds.

The heartbeat server receiving these heartbeats maintains a priority queue, which dequeues oldest items (lowest timestamp) first. Every 5 seconds any item older than a specific timestamp is dequeued, and its state either set to unhealthy (if it is the first missed heartbeat) or unknown if it is the second. The default for timestamps is

  • 30s since heartbeat - unhealthy
  • 60s since heartbeat - unknown (node may be live but disconnected)

The next heartbeat sent by a unhealthy of unknown node will make it healthy again and ready to receive work.

The current state of the node is added to the nodeinfo during a Get/GetByPrefix/List call to the node info store. This means that the liveness is dynamic and not persisted to the kvstore for node info.

Copy link
Contributor

coderabbitai bot commented Mar 26, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a 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. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rossjones rossjones changed the title Implements compute node heartbeats to requester node(s) Node heartbeats Mar 26, 2024
Copy link
Member

@frrist frrist left a comment

Choose a reason for hiding this comment

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

few drive by comments.

pkg/compute/management_client.go Outdated Show resolved Hide resolved
pkg/node/heartbeat/client.go Show resolved Hide resolved
pkg/node/heartbeat/server.go Outdated Show resolved Hide resolved
Copy link
Member

@frrist frrist left a comment

Choose a reason for hiding this comment

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

Good stuff!

Left a few comment's I'd like addressed/discussed before merging.

pkg/compute/management_client.go Outdated Show resolved Hide resolved
pkg/compute/management_client.go Outdated Show resolved Hide resolved
pkg/compute/management_client.go Show resolved Hide resolved
pkg/models/node_state.go Show resolved Hide resolved
pkg/models/node_state.go Outdated Show resolved Hide resolved
pkg/node/heartbeat/client.go Outdated Show resolved Hide resolved
pkg/node/heartbeat/types.go Outdated Show resolved Hide resolved
pkg/node/node.go Outdated Show resolved Hide resolved
pkg/node/node.go Outdated Show resolved Hide resolved
@rossjones rossjones force-pushed the heartbeats branch 4 times, most recently from 0ec0bfc to 6bf5028 Compare April 3, 2024 09:54
@rossjones rossjones requested a review from a team April 3, 2024 14:55
@rossjones rossjones marked this pull request as ready for review April 3, 2024 15:46
Copy link
Collaborator

@aronchick aronchick left a comment

Choose a reason for hiding this comment

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

LGTM but i think we should go with just a binary classification

@@ -16,15 +16,17 @@ import (

var defaultColumnGroups = []string{"labels", "capacity"}
var orderByFields = []string{"id", "type", "available_cpu", "available_memory", "available_disk", "available_gpu", "status"}
var filterStatusValues = []string{"approved", "pending", "rejected"}
var filterApprovalValues = []string{"approved", "pending", "rejected"}
var filterStatusValues = []string{"healthy", "unhealthy", "unknown"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think it should be binary - "connected" or "unconnected" (we could add something more sophisticated like "unhealthy" when we have more health checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for the filters, or for thenode list as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think the node list as well - "healthy" and "unhealthy" imply something i don't think we know. We only know if it's connected or disconnected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with Connected/Disconnected for now, discussed with Walid and will add another duration in future to mark the point beyond which we don't think the node is coming back.

docs/docs/dev/cli-reference/cli/node/list/index.md Outdated Show resolved Hide resolved
Copy link
Member

@frrist frrist 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, once comments are address :shipit:

nodeCmd.Flags().StringVar(&o.FilterByStatus, "filter-status", o.FilterByStatus,
fmt.Sprintf("Filter nodes by status. One of: %q", filterStatusValues))

return nodeCmd
}

// Run executes node command
func (o *ListOptions) run(cmd *cobra.Command, _ []string) {
func (o *ListOptions) run(cmd *cobra.Command, _ []string) error {
Copy link
Member

@frrist frrist Apr 4, 2024

Choose a reason for hiding this comment

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

Non-blocking: if we are going to return an error from this method can we replace all the util.Fatal calls while we are at it? (be wary this might break some tests that (annoyingly) override the util.Fatal field 😞)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can definitely add a ticket to address this, yeah. There's a mix of approaches atm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added #3764

Comment on lines 78 to 84
return fmt.Errorf("cannot use '%s' as filter approval value, should be one of: %q", o.FilterByApproval, filterApprovalValues)
}
}

if o.FilterByStatus != "" {
if !slices.Contains(filterStatusValues, o.FilterByStatus) {
util.Fatal(cmd, fmt.Errorf("cannot use '%s' as filter status value, should be one of: %q", o.FilterByStatus, filterStatusValues), 1)
return fmt.Errorf("cannot use '%s' as filter status value, should be one of: %q", o.FilterByStatus, filterStatusValues)
Copy link
Member

Choose a reason for hiding this comment

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

consider printing the specific flag name in the error message e.g. filter-status and filter-approval


# Command: `node approve`

The `bacalhau node approve` command offers administrations the ability to approve the cluster membership for a node using its unique identifier.
Copy link
Member

Choose a reason for hiding this comment

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

command offers administrations administrators?
unique identifier being synonymous with name, right?


- `-m message`:

- A message to be attached to the approval action.
Copy link
Member

Choose a reason for hiding this comment

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

makes me wonder if we should also include the ClientID of the user issuing the approval, but that could always be included later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think at the moment something being audited just means it was logged somewhere, and so the client id should be in the request.

sidebar_label: delete
---

# Command: `node approve`
Copy link
Member

Choose a reason for hiding this comment

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

node delete

Comment on lines 13 to 17
// To add a new state,
// * add it to the end of the list in the const below
// * add it to strLivenessArray and typeLivenessMap
// * add it to the livenessContainer and corresponding NodeStates var.
// * add it to the All() method in the livenessContainer
Copy link
Member

Choose a reason for hiding this comment

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

<3

@@ -124,36 +127,62 @@ func (m *ManagementClient) updateResources(ctx context.Context) {
Resources: resources,
})
if err != nil {
log.Ctx(ctx).Error().Err(err).Msg("failed to send resource update to requester node")
Copy link
Member

Choose a reason for hiding this comment

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

While I am thinking about this. Above on line 103 where we call getNodeInfo we do:

nodeInfo := m.getNodeInfo(ctx)
	response, err := m.managementProxy.UpdateInfo(ctx, requests.UpdateInfoRequest{
		Info: nodeInfo,
	})
	if err != nil {
		log.Ctx(ctx).Error().Err(err).Msg("failed to send update info to requester node")
	}
// TODO response will be nil when err != nil and this code will panic (has panicked for me)
	if response.Accepted {
		log.Ctx(ctx).Debug().Msg("update info accepted")
	} else {
		log.Ctx(ctx).Error().Msgf("update info rejected: %s", response.Reason)
	}

Can we address the panic here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I intended this to return after logging the error. Fixed in a96c1b0


go func(ctx context.Context) {
defer func() {
_ = h.subscription.Close(ctx) // We're closing down, not much we can do with an error
Copy link
Member

Choose a reason for hiding this comment

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

we can log it on the line below

}
}

func (n *NodeManager) Start(ctx context.Context) error {
log.Ctx(ctx).Info().Msg("Node manager started")
Copy link
Member

@frrist frrist Apr 4, 2024

Choose a reason for hiding this comment

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

log this after the thing starts, it technically hasn't started yet, and it may not start if n.heartbeats is nil (why do we have this conditional?)

func (n *NodeManager) Start(ctx context.Context) error {
log.Ctx(ctx).Info().Msg("Node manager started")

if n.heartbeats != nil {
Copy link
Member

Choose a reason for hiding this comment

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

when can this condition evaluate to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we're running some tests.

@rossjones rossjones merged commit 6572703 into main Apr 8, 2024
12 checks passed
@rossjones rossjones deleted the heartbeats branch April 8, 2024 15:05
aronchick pushed a commit that referenced this pull request Apr 27, 2024
Implements heartbeats for compute nodes, sending heartbeat messages to
the requester node over NATS PubSub. The server, upon receiving a
heartbeat updates the map of nodes to include the current server-side
timestamp.

Compute nodes using the heartbeat client, will continuously send
heartbeat messages every n seconds.

The heartbeat server receiving these heartbeats maintains a priority
queue, which dequeues oldest items (lowest timestamp) first. Every 5
seconds any item older than a specific timestamp is dequeued, and its
state either set to unhealthy (if it is the first missed heartbeat) or
unknown if it is the second. The default for timestamps is

* 30s since heartbeat - unhealthy
* 60s since heartbeat - unknown (node may be live but disconnected)

The next heartbeat sent by a unhealthy of unknown node will make it
healthy again and ready to receive work.

The current state of the node is added to the nodeinfo during a
Get/GetByPrefix/List call to the node info store. This means that the
liveness is dynamic and not persisted to the kvstore for node info.
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