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

Add support for dynamically adding SearchRequestOperationsListener #11526

Conversation

ansjcy
Copy link
Member

@ansjcy ansjcy commented Dec 8, 2023

Description

Adding support for dynamically creating and registering SearchRequestOperationsListener from other components, and refactored the current code to move the logic related to "adding cluster-level operations listeners" away from the core search path.

This PR will support adding new listeners from other components/workflows/plugins without cluttering the core search path.

Related Issues

Resolves #11520 #11762

Tests

  • Insert documents to test domain
curl -X POST "localhost:9200/my-index-0/_doc/?pretty" -H 'Content-Type: application/json' -d'
{
  "@timestamp": "2099-11-15T13:12:00",
  "message": "this is document 1",
  "user": {
    "id": "cyji"
  }
}'
curl -X POST "localhost:9200/my-index-0/_doc/?pretty" -H 'Content-Type: application/json' -d'
{
  "@timestamp": "2099-11-15T13:12:00",
  "message": "this is document 2",
  "user": {
    "id": "cyji"
  }
}'
  • Search with phaseTook disabled
curl -X GET "localhost:9200/my-index-0/_search?size=20&pretty" -H 'Content-Type: application/json' -d '{}'
{
  "took" : 30,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my-index-0",
        "_id" : "LrFY14wB3KmY3nSaYpcU",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2099-11-15T13:12:00",
          "message" : "this is document 1",
          "user" : {
            "id" : "cyji"
          }
        }
      },
      {
        "_index" : "my-index-0",
        "_id" : "L7FY14wB3KmY3nSadpdG",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2099-11-15T13:12:00",
          "message" : "this is document 2",
          "user" : {
            "id" : "cyji"
          }
        }
      }
    ]
  }
}
  • Search with phaseTook enabled on the request level
curl -X GET "localhost:9200/my-index-0/_search?size=20&phase_took=true&pretty" -H 'Content-Type: application/json' -d '{}'
{
  "took" : 3,
  "phase_took" : {
    "dfs_pre_query" : 0,
    "query" : 2,
    "fetch" : 0,
    "dfs_query" : 0,
    "expand" : 0,
    "can_match" : 0
  },
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my-index-0",
        "_id" : "LrFY14wB3KmY3nSaYpcU",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2099-11-15T13:12:00",
          "message" : "this is document 1",
          "user" : {
            "id" : "cyji"
          }
        }
      },
      {
        "_index" : "my-index-0",
        "_id" : "L7FY14wB3KmY3nSadpdG",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2099-11-15T13:12:00",
          "message" : "this is document 2",
          "user" : {
            "id" : "cyji"
          }
        }
      }
    ]
  }
}
  • Enable phaseTook on the cluster level, run the search request again.
curl -X PUT 'localhost:9200/_cluster/settings' -H 'Content-Type: application/json' -d'
{
    "persistent" : {
        "search.phase_took_enabled" : "true"
    }
}'

curl -X GET "localhost:9200/my-index-0/_search?size=20&pretty" -H 'Content-Type: application/json' -d '{}'
{
  "took" : 2,
  "phase_took" : {
    "dfs_pre_query" : 0,
    "query" : 1,
    "fetch" : 0,
    "dfs_query" : 0,
    "expand" : 0,
    "can_match" : 0
  },
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my-index-0",
        "_id" : "LrFY14wB3KmY3nSaYpcU",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2099-11-15T13:12:00",
          "message" : "this is document 1",
          "user" : {
            "id" : "cyji"
          }
        }
      },
      {
        "_index" : "my-index-0",
        "_id" : "L7FY14wB3KmY3nSadpdG",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2099-11-15T13:12:00",
          "message" : "this is document 2",
          "user" : {
            "id" : "cyji"
          }
        }
      }
    ]
  }
}
  • Enable slowlog and check number of listeners with debugger
curl -X PUT 'localhost:9200/_cluster/settings' -H 'Content-Type: application/json' -d'
{
    "persistent" : {
        "cluster.search.request.slowlog.threshold.warn" : "1ms"
    }
}'

result:
image

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Failing checks are inspected and point to the corresponding known issue(s) (See: Troubleshooting Failing Builds)
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)
  • Public documentation issue/PR created

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.

Copy link
Contributor

github-actions bot commented Dec 8, 2023

❌ Gradle check result for d4e323f: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@ansjcy ansjcy force-pushed the dynamically-add-SearchRequestOperationsListener branch from 79caa4f to 0386fe5 Compare January 10, 2024 02:24
Copy link
Contributor

❕ Gradle check result for 79caa4f: UNSTABLE

  • TEST FAILURES:
      1 org.opensearch.remotestore.RemoteIndexPrimaryRelocationIT.testPrimaryRelocationWhileIndexing

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

Copy link
Contributor

❕ Gradle check result for 0386fe5: UNSTABLE

  • TEST FAILURES:
      1 org.opensearch.search.SearchWeightedRoutingIT.testShardRoutingWithNetworkDisruption_FailOpenEnabled
      1 org.opensearch.repositories.azure.AzureBlobStoreRepositoryTests.testContainerCreationAndDeletion

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

Copy link
Collaborator

@jainankitk jainankitk left a comment

Choose a reason for hiding this comment

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

Thank you for promptly addressing the review comments!

Signed-off-by: Chenyang Ji <cyji@amazon.com>
…ListenerManager

Signed-off-by: Chenyang Ji <cyji@amazon.com>
Signed-off-by: Chenyang Ji <cyji@amazon.com>
Signed-off-by: Chenyang Ji <cyji@amazon.com>
Signed-off-by: Chenyang Ji <cyji@amazon.com>
@ansjcy ansjcy force-pushed the dynamically-add-SearchRequestOperationsListener branch from 0386fe5 to 5d407b3 Compare January 11, 2024 19:50
…rationsCompositeListenerFactory

Signed-off-by: Chenyang Ji <cyji@amazon.com>
@ansjcy ansjcy force-pushed the dynamically-add-SearchRequestOperationsListener branch from 5d407b3 to 96c8388 Compare January 11, 2024 19:53
Copy link
Collaborator

@msfroh msfroh 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! Thanks @ansjcy for all the code cleanup in this change

Copy link
Contributor

❕ Gradle check result for 5d407b3: UNSTABLE

  • TEST FAILURES:
      2 org.opensearch.common.util.concurrent.QueueResizableOpenSearchThreadPoolExecutorTests.classMethod
      1 org.opensearch.remotestore.RemoteIndexPrimaryRelocationIT.testPrimaryRelocationWhileIndexing
      1 org.opensearch.common.util.concurrent.QueueResizableOpenSearchThreadPoolExecutorTests.testResizeQueueDown

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

Copy link
Contributor

✅ Gradle check result for 96c8388: SUCCESS

@msfroh msfroh merged commit 6aab360 into opensearch-project:main Jan 11, 2024
28 checks passed
@ansjcy ansjcy added the backport 2.x Backport to 2.x branch label Feb 6, 2024
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.x
# Create a new branch
git switch --create backport/backport-11526-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 6aab36052055e24c2ef56454da9d3a1e4982ee6e
# Push it to GitHub
git push --set-upstream origin backport/backport-11526-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-11526-to-2.x.

ansjcy added a commit to ansjcy/OpenSearch that referenced this pull request Feb 6, 2024
…h-project#11526)

Along the way, also refactored TransportSearchAction.TimeProvider,
so that it's no longer a (redundant) listener.

---------

Signed-off-by: Chenyang Ji <cyji@amazon.com>
(cherry picked from commit 6aab360)
msfroh pushed a commit that referenced this pull request Feb 6, 2024
…ener (#11526) (#12192)

* Support dynamically adding SearchRequestOperationsListener (#11526)

Along the way, also refactored TransportSearchAction.TimeProvider,
so that it's no longer a (redundant) listener.

---------

Signed-off-by: Chenyang Ji <cyji@amazon.com>
(cherry picked from commit 6aab360)

* fix compilation error

Signed-off-by: Chenyang Ji <cyji@amazon.com>

---------

Signed-off-by: Chenyang Ji <cyji@amazon.com>
@ansjcy ansjcy changed the title Support dynamically adding SearchRequestOperationsListener Add support for dynamically adding SearchRequestOperationsListener Feb 9, 2024
rayshrey pushed a commit to rayshrey/OpenSearch that referenced this pull request Mar 18, 2024
…h-project#11526)

Along the way, also refactored TransportSearchAction.TimeProvider,
so that it's no longer a (redundant) listener.

---------

Signed-off-by: Chenyang Ji <cyji@amazon.com>
shiv0408 pushed a commit to Gaurav614/OpenSearch that referenced this pull request Apr 25, 2024
…h-project#11526)

Along the way, also refactored TransportSearchAction.TimeProvider,
so that it's no longer a (redundant) listener.

---------

Signed-off-by: Chenyang Ji <cyji@amazon.com>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch backport-failed enhancement Enhancement or improvement to existing feature or request Search:Query Insights
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for dynamically adding SearchRequestOperationsListener
8 participants