opensearch-project / ml-commons

ml-commons provides a set of common machine learning algorithms, e.g. k-means, or linear regression, to help developers build ML related features within OpenSearch.
Apache License 2.0
96 stars 134 forks source link

[BUG] Failure in createConnector should not log API keys. #2915

Closed austintlee closed 2 weeks ago

austintlee commented 2 months ago

What is the bug? It looks like the error message in the CreateConnector failure response contains the API key in the template.

How can one reproduce the bug? Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

What is the expected behavior? A clear and concise description of what you expected to happen.

What is your host/environment?

Do you have any screenshots? If applicable, add screenshots to help explain your problem.

Do you have any additional context? Add any other context about the problem.

austintlee commented 2 months ago

RestMLRemoteInferenceIT > testDeleteConnector FAILED org.opensearch.client.ResponseException: method [POST], host [http://127.0.0.1:55810], URI [/_plugins/_ml/connectors/_create], status line [HTTP/1.1 503 Service Unavailable] {"error":{"root_cause":[{"type":"unavailable_shards_exception","reason":"[.plugins-ml-connector][0] primary shard is not active Timeout: [1m], request: [BulkShardRequest [[.plugins-ml-connector][0]] containing [index {[.plugins-ml-connector][bnO6yZEB1QdOTLrBQkCP], source[{\"name\":\"OpenAI Connector\",\"version\":\"1\",\"description\":\"The connector to public OpenAI model service for GPT 3.5\",\"protocol\":\"http\",\"parameters\":{\"endpoint\":\"api.openai.com\",\"content_type\":\"application/json\",\"auth\":\"API_Key\",\"max_tokens\":\"7\",\"temperature\":\"0\",\"model\":\"gpt-3.5-turbo-instruct\"},\"credential\":{\"openAI_key\":\"<api key>\"},\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://${parameters.endpoint}/v1/completions\",\"headers\":{\"Authorization\":\"Bearer ${credential.openAI_key}\"},\"request_body\":\"{ \\\"model\\\": \\\"${parameters.model}\\\", \\\"prompt\\\": \\\"${parameters.prompt}\\\", \\\"max_tokens\\\": ${parameters.max_tokens}, \\\"temperature\\\": ${parameters.temperature} }\"}],\"client_config\":{\"max_connection\":20,\"connection_timeout\":50000,\"read_timeout\":50000,\"retry_backoff_millis\":200,\"retry_timeout_seconds\":30,\"max_retry_times\":0,\"retry_backoff_policy\":\"constant\"}}]}] and a refresh]"}],"type":"unavailable_shards_exception","reason":"[.plugins-ml-connector][0] primary shard is not active Timeout: [1m], request: [BulkShardRequest [[.plugins-ml-connector][0]] containing [index {[.plugins-ml-connector][bnO6yZEB1QdOTLrBQkCP], source[{\"name\":\"OpenAI Connector\",\"version\":\"1\",\"description\":\"The connector to public OpenAI model service for GPT 3.5\",\"protocol\":\"http\",\"parameters\":{\"endpoint\":\"api.openai.com\",\"content_type\":\"application/json\",\"auth\":\"API_Key\",\"max_tokens\":\"7\",\"temperature\":\"0\",\"model\":\"gpt-3.5-turbo-instruct\"},\"credential\":{\"openAI_key\":\"<api key>\"},\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://${parameters.endpoint}/v1/completions\",\"headers\":{\"Authorization\":\"Bearer ${credential.openAI_key}\"},\"request_body\":\"{ \\\"model\\\": \\\"${parameters.model}\\\", \\\"prompt\\\": \\\"${parameters.prompt}\\\", \\\"max_tokens\\\": ${parameters.max_tokens}, \\\"temperature\\\": ${parameters.temperature} }\"}],\"client_config\":{\"max_connection\":20,\"connection_timeout\":50000,\"read_timeout\":50000,\"retry_backoff_millis\":200,\"retry_timeout_seconds\":30,\"max_retry_times\":0,\"retry_backoff_policy\":\"constant\"}}]}] and a refresh]"},"status":503} at __randomizedtesting.SeedInfo.seed([5A4DB80AB4595406:9ADC268A24B8243E]:0) at app//org.opensearch.client.RestClient.convertResponse(RestClient.java:501) at app//org.opensearch.client.RestClient.performRequest(RestClient.java:384) at app//org.opensearch.client.RestClient.performRequest(RestClient.java:374) at app//org.opensearch.client.RestClient.performRequest(RestClient.java:359) at app//org.opensearch.ml.utils.TestHelper.makeRequest(TestHelper.java:182) at app//org.opensearch.ml.utils.TestHelper.makeRequest(TestHelper.java:155) at app//org.opensearch.ml.rest.RestMLRemoteInferenceIT.createConnector(RestMLRemoteInferenceIT.java:841) at app//org.opensearch.ml.rest.RestMLRemoteInferenceIT.testDeleteConnector(RestMLRemoteInferenceIT.java:98)

dblock commented 1 month ago

[Catch All Triage - 1, 2, 3, 4]

cc: @ylwu-amzn @varun-lodaya this looks like a problem we should fix soon

ylwu-amzn commented 1 month ago

@dhrubo-os Is working on this.

dhrubo-os commented 2 weeks ago

Closing the issue as the PR is merged now.