Skip to content

Commit

Permalink
Adds lastUpdateTime to Old Connectors
Browse files Browse the repository at this point in the history
Previoulsy we didnt consider the old connectors to have time fields at all, But given offline discussion if we add time fields to old connectors users could get more information moving forward without breaking any backward features. The solution to this was setting the last updated time in the update connector api; now moving forward any connector gets attached a last updated time field. I updated the testUpdateConnectorDoesNotUpdateHTTPCOnnectorTimeFields method to check that lastUpdateTime has a timestamp but that createdTime has no time field.

Signed-off-by: Brian Flores <iflorbri@amazon.com>
  • Loading branch information
brianf-aws committed Sep 26, 2024
1 parent 7f06d73 commit 481f5c2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ private void indexConnector(Connector connector, ActionListener<MLCreateConnecto
listener.onResponse(response);
}, listener::onFailure);

IndexRequest indexRequest = new IndexRequest(ML_CONNECTOR_INDEX);

Instant currentTime = Instant.now();
connector.setCreatedTime(currentTime);
connector.setLastUpdateTime(currentTime);

IndexRequest indexRequest = new IndexRequest(ML_CONNECTOR_INDEX);
indexRequest.source(connector.toXContent(XContentBuilder.builder(XContentType.JSON.xContent()), ToXContent.EMPTY_PARAMS));
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
client.index(indexRequest, ActionListener.runBefore(indexResponseListener, context::restore));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.ml.common.MLModel;
import org.opensearch.ml.common.connector.HttpConnector;
import org.opensearch.ml.common.transport.connector.MLUpdateConnectorAction;
import org.opensearch.ml.common.transport.connector.MLUpdateConnectorRequest;
import org.opensearch.ml.engine.MLEngine;
Expand Down Expand Up @@ -96,9 +95,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Update
connector.update(mlUpdateConnectorAction.getUpdateContent(), mlEngine::encrypt);
connector.validateConnectorURL(trustedConnectorEndpointsRegex);

if (connector instanceof HttpConnector && ((HttpConnector) connector).getLastUpdateTime() != null) {
connector.setLastUpdateTime(Instant.now());
}
connector.setLastUpdateTime(Instant.now());

UpdateRequest updateRequest = new UpdateRequest(ML_CONNECTOR_INDEX, connectorId);
updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ public void testUpdateConnectorDoesNotUpdateHttpConnectorTimeFields() {

updateConnectorTransportAction.doExecute(task, updateRequest, actionListener);

assertNull(connector.getLastUpdateTime());
assertNull(connector.getCreatedTime());
assertNotNull(connector.getLastUpdateTime());
}

@Test
Expand Down

0 comments on commit 481f5c2

Please sign in to comment.