Skip to content

Conversation

@tobio
Copy link
Member

@tobio tobio commented Dec 17, 2025

Fixes #1557
Fixes #1561

This PR:

  • Correctly sets the start time to unknown if the datafeed state if transitioning from stopped -> started
  • Persists any user specified timezones in the start and end times to avoid a state consistency issue when the user supplied timezone does not match the ES server timezone.
  • Fixes a bug where the start and end times were being set as Unix second values when the API was expecting Unix milli-second values.

We were supplying a Unix seconds value where ES expected a Unix millseconds value, using a human friendly time string is more explicit in this case anyway
@tobio tobio requested a review from dimuon December 17, 2025 02:18
@tobio tobio self-assigned this Dec 17, 2025
Copilot AI review requested due to automatic review settings December 17, 2025 02:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes state consistency issues with ML datafeed start and end times by correcting timezone handling, time unit conversion, and state transition logic.

Key Changes:

  • Fixed time conversion from Unix seconds to milliseconds for API calls
  • Preserved user-specified timezones to prevent state inconsistency
  • Set start time to unknown during stopped→started transitions to allow server-side default

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/elasticsearch/ml/datafeed_state/update.go Simplified time retrieval by directly accessing string values instead of converting through helper methods
internal/elasticsearch/ml/datafeed_state/models.go Added timezone preservation logic and proper handling of unknown start/end values
internal/elasticsearch/ml/datafeed_state/read.go Removed conditional check that prevented reading start/end times for started datafeeds
internal/elasticsearch/ml/datafeed_state/schema.go Added plan modifier to set start time to unknown when state changes
internal/elasticsearch/ml/datafeed_state/set_unknown_if_state_has_changes.go Implemented custom plan modifier for conditional unknown value setting
internal/elasticsearch/ml/datafeed_state/acc_test.go Added comprehensive multi-step acceptance test covering state transitions and timezone handling
Test configuration files (5 files) Added test scenarios for various datafeed state transitions

Comment on lines +53 to +61
start, diags := timeInSameLocation(datafeedStats.RunningState.SearchInterval.StartMS, d.Start)
if diags.HasError() {
return diags
}

end, diags := timeInSameLocation(datafeedStats.RunningState.SearchInterval.EndMS, d.End)
if diags.HasError() {
return diags
}
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The variable diags is reused for both start and end conversions, shadowing the outer diags variable declared at line 44. This makes it unclear which diagnostics are being accumulated. Use distinct variable names like startDiags and endDiags to avoid confusion.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants