-
Notifications
You must be signed in to change notification settings - Fork 128
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
populate time fields for connectors on return #2922
base: main
Are you sure you want to change the base?
Conversation
fixes opensearch-project#2890 Currently any class that extends the AbstractConnector class has the fields createdTime and lastUpdatedTime set to null. The solution was instantiating the fields in the constructor of the AbstractConnector class, as well updating it within the HTTPConnector class whenever an update happens. Many tests were modified to catch the time fields being populated as such there will be many differences on the string in order to get around the timing issue when doing tests. Signed-off-by: Brian Flores <[email protected]>
Let's add more details in the description like how did you test? Let's create a connector and invoke the get connector api to get the connector details to show the create and update timestamp After that update the connector and then show the change of updated timestamp. |
Hey @dhrubo-os Thanks for the feedback I updated my post based on your feedback. I uploaded a video that you can click on to see a visual of the written steps (2 mins) Its on the heading Changes I also did a test on a cluster and the change works as well. (Amazonians can see this video as proof) |
common/src/main/java/org/opensearch/ml/common/connector/AbstractConnector.java
Outdated
Show resolved
Hide resolved
common/src/test/java/org/opensearch/ml/common/transport/model/MLUpdateModelInputTest.java
Outdated
Show resolved
Hide resolved
common/src/main/java/org/opensearch/ml/common/connector/AbstractConnector.java
Outdated
Show resolved
Hide resolved
common/src/main/java/org/opensearch/ml/common/connector/AbstractConnector.java
Show resolved
Hide resolved
fixes opensearch-project#2890 when applying a code change like this previous connectors would have a weird bug where upon calling GET on them would change the timestamp. In this commit, it remains the old connectors without time fields while new ones have time fields, newer connectors will have correct and updated Timestamp. Manual testing was done on a local cluster and two unit tests were done to inspect the time changes on creation and update Signed-off-by: Brian Flores <[email protected]>
97f6eda
to
8c006de
Compare
Originally this commit was cherry picked from the 2.x branch and as such code changes affected the new build that werent caught on the previous commit 8c006de. Reformatted tests that were failing as the behavior implemented in previous commits was to not display time fields if a connector does not have them in the first place. gradlew build was done to assure the tests passed Signed-off-by: Brian Flores <[email protected]>
…change When creating a code change to the connector it propagated the new change of the object that affected many UTs, but after changing the logic of indexing the new connector, change the old changes for the unit test involving models with connectors had to be reverted back. UTs specifically for the indexed connectors have been created in UpdateConnectorTransportActionTests were done to capture this Signed-off-by: Brian Flores <[email protected]>
@@ -93,6 +95,11 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Update | |||
if (Boolean.TRUE.equals(hasPermission)) { | |||
connector.update(mlUpdateConnectorAction.getUpdateContent(), mlEngine::encrypt); | |||
connector.validateConnectorURL(trustedConnectorEndpointsRegex); | |||
|
|||
if (connector instanceof HttpConnector && ((HttpConnector) connector).getLastUpdateTime() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only HttpConnector? Can't we just check connector.getLastUpdateTime() != null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to bloat the connector interface with a getter as it already has two getters. Also AbstractConnector has the time fields not the connector interface
Description
Currently any class that extends the AbstractConnector class has the fields createdTime and lastUpdatedTime set to null. The solution was creating setters on the connector interface and implementing on the abstract connector. Now on Indexing new connectors (Via the create API) the time fields will be instantiated. Two unit tests in
UpdateConnectorTransportActionTests
namedUpdateConnectorTransportActionTests
andtestUpdateConnectorUpdatesHttpConnectorTimeFields
Related Issues
fixes #2890 Created Time and Last Updated Time are not implemented on Connector
Check List
--signoff
.Changes (Amazon team can view this demo )
created_time,last_updated_time
a. creating a connector
Note how when updating the connector using the Update Connector API and then calling get it changes the the last updated time and leaves the created time the same
a. Update the connector
curl -XPUT "http://localhost:9200/_plugins/_ml/connectors/lkf-3JEBz83ApvP3YOPy" -H "Content-Type: application/json' -d' { "description": "The new description of Brians chatGpt model" }"
b. get the connector again and note the new time
curl -XGET "http://localhost:9200/_plugins/_ml/connectors/lkf-3JEBz83ApvP3YOPy"
which yields"created_time": 1725989544074, "last_updated_time": 1725989544074
and after the update its"created_time": 1725989544074, "last_updated_time": 1725989603171
. You can see how it changed but the created_time stayed the same.Testing
./gradlew assemble
to pack the code change into a zip filecommand: bash -c "bin/opensearch-plugin remove opensearch-skills; bin/opensearch-plugin remove opensearch-ml; bin/opensearch-plugin install --batch file:///<Path to the zip>/opensearch-ml-X.X.X.X-SNAPSHOT.zip; ./opensearch-docker-entrypoint.sh opensearch"
UpdateConnectorTransportActionTests
namedtestUpdateConnectorDoesNotUpdateHttpConnectorTimeFields
checks that when creating a connector time fields arent populated we test this because we want to make sure that connectors dont get this field populated instead we want to make sure that the Transport layer sets this additionally when these fields are null we need to make sure the transport layer does not set the updated time on a update.testUpdateConnectorUpdatesHttpConnectorTimeFields
Checks that time fields are instantiated and that after a update the updated time is bigger than the created time.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.