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

[Connector API] Add metadata to sync job stats endpoint #109927

Merged

Conversation

jedrazb
Copy link
Member

@jedrazb jedrazb commented Jun 19, 2024

Changes

Extends existing set sync stats api with optional request body parameter metadata.

Connector-specific metadata should be updated along with sync stats, see: connector service reference code.

Endpoint documentation is updated.

Validation

  • unit tests
  • e2e yaml tests
  • manual test locally

Copy link

Documentation preview:

@jedrazb jedrazb marked this pull request as ready for review June 19, 2024 13:42
@elasticsearchmachine elasticsearchmachine added the Team:SearchOrg Meta label for the Search Org (Enterprise Search) label Jun 19, 2024
@elasticsearchmachine
Copy link
Collaborator

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

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.

Looks good! Left some questions about testing

@@ -184,6 +184,36 @@ setup:
- match: { indexed_document_volume: 1000 }
- match: { last_seen: 2023-12-04T08:45:50.567149Z }

---
"Update the ingestion stats for a connector sync job - with optional metadata":
Copy link
Contributor

@navarone-feekery navarone-feekery Jun 20, 2024

Choose a reason for hiding this comment

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

Should we also have a test for when metadata is in an unexpected type? (like a string or int)
I don't know if this is necessary but I am curious what happens if we give the wrong value type

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, added tests. For str or int we would return 400 as a parsing exception (parser expects an obejct)

@jedrazb
Copy link
Member Author

jedrazb commented Jun 20, 2024

@elasticmachine merge upstream

Copy link
Member

@seanstory seanstory left a comment

Choose a reason for hiding this comment

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

I notice that new test cases were added only for the YAML tests, but not for any of the unit tests. Any need for unit tests, or is the YAML sufficient?

@@ -57,6 +57,7 @@ public static class Request extends ConnectorSyncJobActionRequest implements ToX
private final Long indexedDocumentVolume;
private final Long totalDocumentCount;
private final Instant lastSeen;
private final Object metadata;
Copy link
Member

Choose a reason for hiding this comment

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

Is using Object a standard thing to do in our APIs for "JSON Objects?" Feels too generic, since Object is the base class of all things Java. I would have expected Map<String, String> or JsonObject or something less vague. But that might just be me not being familiar with established ES patterns.

Copy link
Member Author

@jedrazb jedrazb Jun 24, 2024

Choose a reason for hiding this comment

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

Defining metadata type as Map<String, String> would be too strict as it doesn't allow for nested maps, which in theory should be allowed by the connector protocol. The connector protocol vaguely defines metadata as a mapping, so agreed we could reasonably represent it as Map<String, Object>.

I used Object since initially I though metadata could be anything (map, int, string) but later on it was clarified to be a map. Will adapt that 👍

@@ -66,6 +67,7 @@ public Request(StreamInput in) throws IOException {
this.indexedDocumentVolume = in.readLong();
this.totalDocumentCount = in.readOptionalLong();
this.lastSeen = in.readOptionalInstant();
this.metadata = in.readGenericValue();
Copy link
Member

Choose a reason for hiding this comment

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

A lot of the usages I see for in.readGenericValue() us casting. Like

this.metadata = (Map<String, Object>) in.readGenericValue();

Copy link
Member Author

Choose a reason for hiding this comment

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

or even better in.readGenericMap()!

@jedrazb
Copy link
Member Author

jedrazb commented Jun 24, 2024

@elasticmachine merge upstream

@jedrazb
Copy link
Member Author

jedrazb commented Jun 24, 2024

I notice that new test cases were added only for the YAML tests, but not for any of the unit tests. Any need for unit tests, or is the YAML sufficient?

They should test the same path - parsing of the request payload. Yes, we could add explicit parsing tests as unit tests as well 👍 I like defining those bad_request tests as YAML tests, you can define the full api payload that should fail and treat ES as a black box.

@jedrazb jedrazb requested a review from seanstory June 24, 2024 13:51
@jedrazb
Copy link
Member Author

jedrazb commented Jun 24, 2024

@seanstory I adapted the PR, have a look! As an example I added unit tests that can test the parsing logic, took me a while so IMO we are fine using just YAML tests for that

@jedrazb
Copy link
Member Author

jedrazb commented Jun 24, 2024

@elasticmachine merge upstream

Copy link
Member

@seanstory seanstory left a comment

Choose a reason for hiding this comment

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

🎉 awesome

@jedrazb jedrazb merged commit a257fed into elastic:main Jun 25, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :SearchOrg/Extract&Transform Label for the Search E&T team Team:Search - Extract & Transform Team:SearchOrg Meta label for the Search Org (Enterprise Search) v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants