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

[Connectors API] Unify timestamp field parsing #104416

Merged
merged 4 commits into from
Jan 22, 2024

Conversation

jedrazb
Copy link
Member

@jedrazb jedrazb commented Jan 16, 2024

Changes

  • Unify datetime parsing logic with parseInstant function applied to all datetime fields from user in connectors APIs - user can provide datetime in any ES-compatible format, the API will take care of making it compatible with connectors protocol

@jedrazb jedrazb added >bug :EnterpriseSearch/Application Enterprise Search Team:Enterprise Search Meta label for Enterprise Search team v8.12.1 v8.13.0 labels Jan 16, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @jedrazb, I've created a changelog YAML for you.

@jedrazb jedrazb force-pushed the fix-connectors-api-timestamp-handling branch from bc72114 to f91f0e2 Compare January 17, 2024 09:28
@jedrazb jedrazb marked this pull request as ready for review January 17, 2024 09:39
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ent-search-eng (Team:Enterprise Search)

Copy link
Contributor

@timgrein timgrein left a comment

Choose a reason for hiding this comment

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

From a functional perspective it looks correct, but after rethinking about the solution I'm not 100% sure, if the fix should happen inside the API, but rather in the client (connectors framework). Explained my rationale in the comment.

Still, feel free to merge it, if you think this solution is the right path forward 👍

builder.field(LAST_INCREMENTAL_SYNC_SCHEDULED_AT_FIELD.getPreferredName(), lastIncrementalSyncScheduledAt);
builder.field(
LAST_INCREMENTAL_SYNC_SCHEDULED_AT_FIELD.getPreferredName(),
ConnectorUtils.formatInstantToFrameworkString(lastIncrementalSyncScheduledAt)
Copy link
Contributor

Choose a reason for hiding this comment

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

As I'm seeing now formatInstantToFrameworkString I'm wondering, if we should fix it the other way around. As the Connectors API guards everything around the protocol it feels cleaner, if the clients (like the framework) adapt to the API and not the other way around. In theory the connectors API should also be useable for other clients/schedulers.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that the issue should be fixed at the framework level, and I already filed an enhancement request elastic/connectors#2067 to unify handling (parsing, representing) datetimes in connectors framework.

While this PR doesn't solve the underlying root cause it mitigates the symptoms and allows us move forward with integration. Also, think about the connectors created in older releases, we need to be backward compatible with their representation with timestamps (or prepare a migration). Once the issue is solved in framework we can change the API formatting of timestamps.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation, makes sense!

Copy link
Contributor

@navarone-feekery navarone-feekery left a comment

Choose a reason for hiding this comment

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

LGTM, nice one!

@jedrazb
Copy link
Member Author

jedrazb commented Jan 22, 2024

@timgrein @navarone-feekery After discussing this in the team sync, I'm adapting this PR to just address the issue of datetime parsing. Since it's not a bugfix I'm removing the label and not backporting this. Can you review again?

@jedrazb jedrazb changed the title [Connectors API] Fix bug with connectors api timestamps [Connectors API] Unify timestamp field parsing Jan 22, 2024
Copy link
Contributor

@timgrein timgrein left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for addressing the changes. Looks way cleaner to remove the framework specific logic out of the API 👍

@jedrazb jedrazb merged commit a1d05d5 into elastic:main Jan 22, 2024
15 checks passed
@jedrazb
Copy link
Member Author

jedrazb commented Apr 3, 2024

This change fixes fixing a unit test bug present in initial release (8.12) that causes intermittent build failures due to unit tests failing. The culprit is Instant.ofEpochMilli(randomLong()) that is changed in this PR to randomInstant() that produces instants in reasonable datetime ranges. This is a fix for:

This PR is not adding a feature, it's unifying the logic we use to handle timestamps for connectors, therefore I'm backporting this to 8.12 to address the build failures.

@jedrazb
Copy link
Member Author

jedrazb commented Apr 3, 2024

💚 All backports created successfully

Status Branch Result
8.12

Questions ?

Please refer to the Backport tool documentation

jedrazb added a commit to jedrazb/elasticsearch that referenced this pull request Apr 3, 2024
(cherry picked from commit a1d05d5)

# Conflicts:
#	x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/connector/syncjob/ConnectorSyncJob.java
#	x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/connector/syncjob/action/UpdateConnectorSyncJobIngestionStatsAction.java
jedrazb added a commit that referenced this pull request Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:EnterpriseSearch/Application Enterprise Search >non-issue Team:Enterprise Search Meta label for Enterprise Search team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants