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

Add Enclave block and Batch health checks #1727

Merged
merged 5 commits into from
Dec 29, 2023
Merged

Conversation

otherview
Copy link
Contributor

@otherview otherview commented Dec 28, 2023

Why this change is needed

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

  • Adds health check for l1 block ( last processed )
  • Adds health check for l2 batch ( last executed)
  • Adds async.Timestamp to avoid concurrent accesses to the timestamp

What changes were made as part of this PR

Please provide a high level list of the changes made

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Dec 28, 2023

Walkthrough

The overall change enhances the system's health check mechanisms by introducing thread-safe timestamp management and incorporating health check methods across various components. The Timestamp type ensures safe concurrent operations, while the HealthCheck methods in different components like batch registry, block processor, and storage ensure that each part of the system is functioning correctly. These changes aim to improve the reliability and maintainability of the system by providing more granular health status information.

Changes

File Path Change Summary
.../async/timestamp.go Added a Timestamp type for thread-safe timestamp operations.
.../components/batch_registry.go,
.../components/block_processor.go,
.../components/interfaces.go
Integrated async.Timestamp, added healthTimeout, lastExecutedBatch, lastIngestedBlock, and implemented HealthCheck.
.../enclave/enclave.go,
.../storage/storage.go
Overhauled HealthCheck in enclave.go to check various component health and modified HealthCheck in storage.go to handle a nil headBatch.
.../txpool/txpool_mock_test.go Added HealthCheck method to mockBatchRegistry type.
.../simulation/simulation.go Added retry mechanism in the checkHealthStatus method.

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.

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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b6444cf and 09e1415.
Files selected for processing (6)
  • go/common/async/timestamp.go (1 hunks)
  • go/enclave/components/batch_registry.go (5 hunks)
  • go/enclave/components/block_processor.go (4 hunks)
  • go/enclave/components/interfaces.go (2 hunks)
  • go/enclave/enclave.go (1 hunks)
  • go/enclave/storage/storage.go (1 hunks)
Additional comments: 17
go/common/async/timestamp.go (4)
  • 8-12: The Timestamp struct is well-defined and thread-safe due to the use of sync.RWMutex.

  • 14-18: The constructor NewAsyncTimestamp correctly initializes the Timestamp struct with the provided lastTimestamp and a new sync.RWMutex.

  • 21-26: The Mark method correctly locks the mutex for writing and updates the lastTimestamp with the current time. The use of defer ensures the mutex is unlocked even if a panic occurs.

  • 28-34: The LastTimestamp method correctly locks the mutex for reading and returns a copy of lastTimestamp. The use of defer is good practice to ensure the mutex is unlocked.

go/enclave/components/interfaces.go (2)
  • 40-40: The HealthCheck method has been added to the L1BlockProcessor interface, which is expected to return a boolean status and an error. This aligns with the PR objectives.

  • 107-107: Similarly, the HealthCheck method has been added to the BatchRegistry interface with the same return signature, which is consistent and expected.

go/enclave/components/block_processor.go (5)
  • 6-6: The import of the time package is necessary for the new timestamp-related functionality.

  • 31-33: New fields healthTimeout and lastIngestedBlock have been added to the l1BlockProcessor struct to support health check functionality.

  • 54-55: The NewBlockProcessor function initializes the new fields healthTimeout and lastIngestedBlock with sensible defaults. The lastIngestedBlock is initialized with a timestamp one minute in the past, which may be a safe assumption to avoid immediate health check failure on startup.

  • 85-85: The Process function now calls Mark on lastIngestedBlock to update the timestamp when a block is processed, which is crucial for the health check mechanism.

  • 89-95: The HealthCheck method correctly compares the current time with the lastIngestedBlockTime plus healthTimeout to determine if the last block ingestion is within the expected time frame. The error message provides useful information about the delay.

go/enclave/components/batch_registry.go (5)
  • 8-8: The import of the time package is necessary for the new timestamp-related functionality.

  • 31-32: New fields healthTimeout and lastExecutedBatch have been added to the batchRegistry struct to support health check functionality.

  • 52-53: The NewBatchRegistry function initializes the new fields healthTimeout and lastExecutedBatch with sensible defaults. The lastExecutedBatch is initialized with a timestamp one minute in the past, which may be a safe assumption to avoid immediate health check failure on startup.

  • 85-85: The OnBatchExecuted method now calls Mark on lastExecutedBatch to update the timestamp when a batch is executed, which is crucial for the health check mechanism.

  • 205-211: The HealthCheck method correctly compares the current time with the lastExecutedBatchTime plus healthTimeout to determine if the last batch execution is within the expected time frame. The error message provides useful information about the delay.

go/enclave/storage/storage.go (1)
  • 266-276: The addition of a nil check for headBatch in the HealthCheck method is a good practice to prevent potential nil pointer dereferences. This change ensures that the method returns an error if the headBatch is nil, which is a clear indication of an unhealthy state.
  if headBatch == nil {
+   return false, fmt.Errorf("head batch is nil")
  }

Comment on lines +1251 to +1267

// todo (#1148) - enclave healthcheck operations
enclaveHealthy := true
return storageHealthy && enclaveHealthy, nil
l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l1 block processor", log.ErrKey, err)
return false, nil
}

l2batchHealthy, err := e.registry.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
return false, nil
}

return storageHealthy && l1blockHealthy && l2batchHealthy, nil
Copy link

Choose a reason for hiding this comment

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

The implementation of the HealthCheck method has been updated to include checks for l1BlockProcessor and registry. Ensure that the error handling and logging are consistent and that the method's behavior aligns with the intended health check logic.

func (e *enclaveImpl) HealthCheck() (bool, common.SystemError) {
	if e.stopControl.IsStopping() {
		return false, responses.ToInternalError(fmt.Errorf("requested HealthCheck with the enclave stopping"))
	}

	// check the storage health
	storageHealthy, err := e.storage.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the enclave storage", log.ErrKey, err)
		return false, nil
	}

	l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the l1 block processor", log.ErrKey, err)
		return false, nil
	}

	l2batchHealthy, err := e.registry.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
		return false, nil
	}

	return storageHealthy && l1blockHealthy && l2batchHealthy, nil
}

Consider enhancing the error handling to provide more detailed information about which component failed the health check. Additionally, the log level for health check failures should be more severe than Info, such as Warn or Error, to reflect the critical nature of health check failures.


Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// todo (#1148) - enclave healthcheck operations
enclaveHealthy := true
return storageHealthy && enclaveHealthy, nil
l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l1 block processor", log.ErrKey, err)
return false, nil
}
l2batchHealthy, err := e.registry.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
return false, nil
}
return storageHealthy && l1blockHealthy && l2batchHealthy, nil
// todo (#1148) - enclave healthcheck operations
if e.stopControl.IsStopping() {
return false, responses.ToInternalError(fmt.Errorf("requested HealthCheck with the enclave stopping"))
}
// check the storage health
storageHealthy, err := e.storage.HealthCheck()
if err != nil {
e.logger.Warn("HealthCheck failed for the enclave storage", log.ErrKey, err)
return false, nil
}
l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
if err != nil {
e.logger.Warn("HealthCheck failed for the l1 block processor", log.ErrKey, err)
return false, nil
}
l2batchHealthy, err := e.registry.HealthCheck()
if err != nil {
e.logger.Warn("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
return false, nil
}
return storageHealthy && l1blockHealthy && l2batchHealthy, nil

Comment on lines 1248 to +1267
e.logger.Info("HealthCheck failed for the enclave storage", log.ErrKey, err)
return false, nil
}

// todo (#1148) - enclave healthcheck operations
enclaveHealthy := true
return storageHealthy && enclaveHealthy, nil
l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l1 block processor", log.ErrKey, err)
return false, nil
}

l2batchHealthy, err := e.registry.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
return false, nil
}

return storageHealthy && l1blockHealthy && l2batchHealthy, nil
Copy link

Choose a reason for hiding this comment

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

The HealthCheck method has been updated to include additional health checks for l1BlockProcessor and registry. Ensure that the error handling and logging are consistent and that the method's behavior aligns with the intended health check logic.

func (e *enclaveImpl) HealthCheck() (bool, common.SystemError) {
	if e.stopControl.IsStopping() {
		return false, responses.ToInternalError(fmt.Errorf("requested HealthCheck with the enclave stopping"))
	}

	// check the storage health
	storageHealthy, err := e.storage.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the enclave storage", log.ErrKey, err)
		return false, nil
	}

	l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the l1 block processor", log.ErrKey, err)
		return false, nil
	}

	l2batchHealthy, err := e.registry.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
		return false, nil
	}

	return storageHealthy && l1blockHealthy && l2batchHealthy, nil
}

Consider enhancing the error handling to provide more detailed information about which component failed the health check. Additionally, the log level for health check failures should be more severe than Info, such as Warn or Error, to reflect the critical nature of health check failures.


Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
e.logger.Info("HealthCheck failed for the enclave storage", log.ErrKey, err)
return false, nil
}
// todo (#1148) - enclave healthcheck operations
enclaveHealthy := true
return storageHealthy && enclaveHealthy, nil
l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l1 block processor", log.ErrKey, err)
return false, nil
}
l2batchHealthy, err := e.registry.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
return false, nil
}
return storageHealthy && l1blockHealthy && l2batchHealthy, nil
e.logger.Warn("HealthCheck failed for the enclave storage", log.ErrKey, err)
return false, responses.ToInternalError(err)
}
// todo (#1148) - enclave healthcheck operations
l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
if err != nil {
e.logger.Warn("HealthCheck failed for the l1 block processor", log.ErrKey, err)
return false, responses.ToInternalError(err)
}
l2batchHealthy, err := e.registry.HealthCheck()
if err != nil {
e.logger.Warn("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
return false, responses.ToInternalError(err)
}
return storageHealthy && l1blockHealthy && l2batchHealthy, nil

The HealthCheck method has been updated to include additional health checks for l1BlockProcessor and registry. Ensure that the error handling and logging are consistent and that the method's behavior aligns with the intended health check logic.

func (e *enclaveImpl) HealthCheck() (bool, common.SystemError) {
	if e.stopControl.IsStopping() {
		return false, responses.ToInternalError(fmt.Errorf("requested HealthCheck with the enclave stopping"))
	}

	// check the storage health
	storageHealthy, err := e.storage.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the enclave storage", log.ErrKey, err)
		return false, nil
	}

	l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the l1 block processor", log.ErrKey, err)
		return false, nil
	}

	l2batchHealthy, err := e.registry.HealthCheck()
	if err != nil {
		e.logger.Info("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
		return false, nil
	}

	return storageHealthy && l1blockHealthy && l2batchHealthy, nil
}

Consider enhancing the error handling to provide more detailed information about which component failed the health check. Additionally, the log level for health check failures should be more severe than Info, such as Warn or Error, to reflect the critical nature of health check failures.


Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
e.logger.Info("HealthCheck failed for the enclave storage", log.ErrKey, err)
return false, nil
}
// todo (#1148) - enclave healthcheck operations
enclaveHealthy := true
return storageHealthy && enclaveHealthy, nil
l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l1 block processor", log.ErrKey, err)
return false, nil
}
l2batchHealthy, err := e.registry.HealthCheck()
if err != nil {
// simplest iteration, log the error and just return that it's not healthy
e.logger.Info("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
return false, nil
}
return storageHealthy && l1blockHealthy && l2batchHealthy, nil
e.logger.Warn("HealthCheck failed for the enclave storage", log.ErrKey, err)
return false, responses.ToInternalError(err)
}
l1blockHealthy, err := e.l1BlockProcessor.HealthCheck()
if err != nil {
e.logger.Warn("HealthCheck failed for the l1 block processor", log.ErrKey, err)
return false, responses.ToInternalError(err)
}
l2batchHealthy, err := e.registry.HealthCheck()
if err != nil {
e.logger.Warn("HealthCheck failed for the l2 batch registry", log.ErrKey, err)
return false, responses.ToInternalError(err)
}
return storageHealthy && l1blockHealthy && l2batchHealthy, nil

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 09e1415 and 76554e7.
Files selected for processing (3)
  • go/enclave/components/batch_registry.go (5 hunks)
  • go/enclave/components/block_processor.go (4 hunks)
  • go/enclave/txpool/txpool_mock_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • go/enclave/components/batch_registry.go
  • go/enclave/components/block_processor.go

Comment on lines +60 to +63
func (m *mockBatchRegistry) HealthCheck() (bool, error) {
// TODO implement me
panic("implement me")
}
Copy link

Choose a reason for hiding this comment

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

The HealthCheck method in mockBatchRegistry is not implemented and will cause a panic if called. Consider implementing the method or updating the TODO comment with more details about the intended implementation.

func (m *mockBatchRegistry) HealthCheck() (bool, error) {
-	// TODO implement me
-	panic("implement me")
+	// TODO: Implement the health check logic or return mock values for testing purposes.
+	// return true, nil // Example mock implementation
}

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (m *mockBatchRegistry) HealthCheck() (bool, error) {
// TODO implement me
panic("implement me")
}
func (m *mockBatchRegistry) HealthCheck() (bool, error) {
// TODO: Implement the health check logic or return mock values for testing purposes.
// return true, nil // Example mock implementation
}

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 76554e7 and 56315ea.
Files selected for processing (1)
  • integration/simulation/simulation.go (2 hunks)
Additional comments: 1
integration/simulation/simulation.go (1)
  • 7-7: The addition of the retry package is consistent with the changes in the checkHealthStatus method to implement a retry mechanism.

Comment on lines +292 to +300
err := retry.Do(func() error {
healthy, err := client.Health()
if !healthy || err != nil {
return fmt.Errorf("client is not healthy: %w", err)
}
return nil
}, retry.NewTimeoutStrategy(30*time.Second, 100*time.Millisecond))
if err != nil {
panic(err)
Copy link

Choose a reason for hiding this comment

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

The implementation of the retry mechanism in checkHealthStatus uses a timeout strategy, which is a good practice for network-related operations that might occasionally fail. However, ensure that the panic does not cause the entire application to crash in a production environment. It might be more appropriate to handle the error gracefully and log it for further investigation.

- panic(err)
+ // Log the error and handle it appropriately without causing a system-wide failure.
+ log.Error("Health check failed", "error", err)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
err := retry.Do(func() error {
healthy, err := client.Health()
if !healthy || err != nil {
return fmt.Errorf("client is not healthy: %w", err)
}
return nil
}, retry.NewTimeoutStrategy(30*time.Second, 100*time.Millisecond))
if err != nil {
panic(err)
err := retry.Do(func() error {
healthy, err := client.Health()
if !healthy || err != nil {
return fmt.Errorf("client is not healthy: %w", err)
}
return nil
}, retry.NewTimeoutStrategy(30*time.Second, 100*time.Millisecond))
if err != nil {
// Log the error and handle it appropriately without causing a system-wide failure.
log.Error("Health check failed", "error", err)

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 56315ea and 15dd266.
Files selected for processing (1)
  • integration/simulation/simulation.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • integration/simulation/simulation.go

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.

Nice work 👏

Minor comments added (mostly about comments), but nothing blocking / major.

go/enclave/enclave.go Show resolved Hide resolved
go/enclave/storage/storage.go Show resolved Hide resolved
go/enclave/components/block_processor.go Show resolved Hide resolved
Copy link
Contributor

@StefanIliev545 StefanIliev545 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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 15dd266 and eee5176.
Files selected for processing (2)
  • go/enclave/components/batch_registry.go (5 hunks)
  • go/enclave/components/block_processor.go (4 hunks)
Additional comments: 8
go/enclave/components/block_processor.go (4)
  • 6-6: The import of the time package is necessary for the new timestamp-related features.

  • 31-33: The addition of healthTimeout and lastIngestedBlock fields to the l1BlockProcessor struct aligns with the PR's objective to enhance health check mechanisms.

  • 54-55: Initialization of healthTimeout to time.Minute and lastIngestedBlock to one minute in the past ensures immediate readiness for health checks post-instantiation.

  • 85-85: The call to lastIngestedBlock.Mark() in the Process function correctly updates the timestamp when a new block is ingested, which is crucial for the health check mechanism.

go/enclave/components/batch_registry.go (4)
  • 8-8: The import of the time package is necessary for the new timestamp-related features.

  • 31-32: The addition of healthTimeout and lastExecutedBatch fields to the batchRegistry struct aligns with the PR's objective to enhance health check mechanisms.

  • 52-53: Initialization of healthTimeout to time.Minute and lastExecutedBatch to one minute in the past ensures immediate readiness for health checks post-instantiation.

  • 85-85: The call to lastExecutedBatch.Mark() in the OnBatchExecuted method correctly updates the timestamp when a batch is executed, which is crucial for the health check mechanism.

Comment on lines +89 to +97
// HealthCheck checks if the last ingested block was more than healthTimeout ago
func (bp *l1BlockProcessor) HealthCheck() (bool, error) {
lastIngestedBlockTime := bp.lastIngestedBlock.LastTimestamp()
if time.Now().After(lastIngestedBlockTime.Add(bp.healthTimeout)) {
return false, fmt.Errorf("last ingested block was %s ago", time.Since(lastIngestedBlockTime))
}

return true, nil
}
Copy link

Choose a reason for hiding this comment

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

The HealthCheck method correctly assesses the health based on the time elapsed since the last ingested block. However, consider adding a comment explaining what constitutes a healthy or unhealthy state, as suggested by a previous reviewer.

+ // HealthCheck determines if the processor is healthy based on the time since the last block ingestion.

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// HealthCheck checks if the last ingested block was more than healthTimeout ago
func (bp *l1BlockProcessor) HealthCheck() (bool, error) {
lastIngestedBlockTime := bp.lastIngestedBlock.LastTimestamp()
if time.Now().After(lastIngestedBlockTime.Add(bp.healthTimeout)) {
return false, fmt.Errorf("last ingested block was %s ago", time.Since(lastIngestedBlockTime))
}
return true, nil
}
// HealthCheck determines if the processor is healthy based on the time since the last block ingestion.
// HealthCheck checks if the last ingested block was more than healthTimeout ago
func (bp *l1BlockProcessor) HealthCheck() (bool, error) {
lastIngestedBlockTime := bp.lastIngestedBlock.LastTimestamp()
if time.Now().After(lastIngestedBlockTime.Add(bp.healthTimeout)) {
return false, fmt.Errorf("last ingested block was %s ago", time.Since(lastIngestedBlockTime))
}
return true, nil
}

Comment on lines +205 to +213
// HealthCheck checks if the last executed batch was more than healthTimeout ago
func (br *batchRegistry) HealthCheck() (bool, error) {
lastExecutedBatchTime := br.lastExecutedBatch.LastTimestamp()
if time.Now().After(lastExecutedBatchTime.Add(br.healthTimeout)) {
return false, fmt.Errorf("last executed batch was %s ago", time.Since(lastExecutedBatchTime))
}

return true, nil
}
Copy link

Choose a reason for hiding this comment

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

The HealthCheck method correctly assesses the health based on the time elapsed since the last executed batch. Consider adding a comment explaining what constitutes a healthy or unhealthy state, similar to the suggestion made in the block_processor.go file.

+ // HealthCheck determines if the registry is healthy based on the time since the last batch execution.

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// HealthCheck checks if the last executed batch was more than healthTimeout ago
func (br *batchRegistry) HealthCheck() (bool, error) {
lastExecutedBatchTime := br.lastExecutedBatch.LastTimestamp()
if time.Now().After(lastExecutedBatchTime.Add(br.healthTimeout)) {
return false, fmt.Errorf("last executed batch was %s ago", time.Since(lastExecutedBatchTime))
}
return true, nil
}
// HealthCheck determines if the registry is healthy based on the time since the last batch execution.
// HealthCheck checks if the last executed batch was more than healthTimeout ago
func (br *batchRegistry) HealthCheck() (bool, error) {
lastExecutedBatchTime := br.lastExecutedBatch.LastTimestamp()
if time.Now().After(lastExecutedBatchTime.Add(br.healthTimeout)) {
return false, fmt.Errorf("last executed batch was %s ago", time.Since(lastExecutedBatchTime))
}
return true, nil
}

@otherview otherview merged commit b2e41d3 into main Dec 29, 2023
2 checks passed
@otherview otherview deleted the pedro/enclave_healthchecks branch December 29, 2023 14:46
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