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 GET api/v1/indexes to Lambda searcher #5069

Merged
merged 5 commits into from
Jun 4, 2024

Conversation

tyrwzl
Copy link
Contributor

@tyrwzl tyrwzl commented Jun 3, 2024

Description

Closes #5039.
Add GET /api/v1/indexes endpoint to Lambda Searcher to use quickwit Lambda as Grafana datasource.

How was this PR tested?

  1. Locally running Lambda searcher by using cargo lambda.
export AWS_ACCESS_KEY_ID="****"
export AWS_SECRET_ACCESS_KEY="****"
export AWS_SESSION_TOKEN="****"
export AWS_REGION="us-east-1"
export AWS_LAMBDA_HTTP_IGNORE_STAGE_IN_PATH="true"
export QW_LAMBDA_INDEX_BUCKET="quickwitlambdastack-quickwitindexstore****"
export QW_LAMBDA_INDEX_ID="hdfs-logs"
export QW_LAMBDA_METASTORE_BUCKET="quickwitlambdastack-quickwitindexstore****"
export RUST_LOG="quickwit=info"
cargo lambda watch
  1. Setup Grafana (https://quickwit.io/docs/get-started/tutorials/trace-analytics-with-grafana)
    • url: http://host.docker.internal:9000/lambda-url/searcher/api/v1
    • Index ID: hdfs-logs

Screenshot 2024-06-03 at 20 29 44

  1. Explorer quickwit data
    Screenshot 2024-06-03 at 20 32 25

@CLAassistant
Copy link

CLAassistant commented Jun 3, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@rdettai rdettai left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution and for testing it on Grafana! It's amazing to see it works!

Nit: have you tried running the CDK examples already? If so, you could add this new endpoint to the tests here

def test_mock_data_endpoints():
apigw_url = _get_cloudformation_output_value(
app.MOCK_DATA_STACK_NAME, mock_data_stack.API_GATEWAY_EXPORT_NAME
)
def req(method, path, body=None, expected_status=200):
conn = http.client.HTTPSConnection(urlparse(apigw_url).netloc)
conn.request(
method,
path,
body,
headers={"x-api-key": os.getenv("SEARCHER_API_KEY")},
)
response = conn.getresponse()
print(f"{method} {path}")
headers = {k: v for (k, v) in response.getheaders()}
body = _decompress_if_gzip(response.read(), headers)
if response.status != expected_status:
print(f"[{response.status}] => {body}")
exit(1)
else:
print(f"[{response.status}] => {json.dumps(json.loads(body))[0:100]}")
req("GET", f"/api/v1/{mock_sales_index_id}/search?query=animal")
req(
"POST",
f"/api/v1/{mock_sales_index_id}/search",
'{"query":"quantity:>5", "max_hits": 10}',
)
req("GET", f"/api/v1/_elastic/{mock_sales_index_id}/_search?q=animal")
req(
"POST",
f"/api/v1/_elastic/{mock_sales_index_id}/_search",
'{"query":{"bool":{"must":[{"range":{"quantity":{"gt":5}}}]}},"size":10}',
)
req("GET", f"/api/v1/_elastic/{mock_sales_index_id}/_field_caps?fields=quantity")
# expected errors
req(
"GET",
f"/api/v1/_elastic/{mock_sales_index_id}/_search?query=animal",
expected_status=400,
)
req("GET", f"/api/v1/_elastic/_search?q=animal", expected_status=501)
. These are some sanity checks on the end to end CDK deployment. You can run them by first deploying the stack:

export CDK_ACCOUNT=123456789
export CDK_REGION=us-east-1
make bootstrap
make deploy-mock-data
make test-mock-data-endpoints

@tyrwzl
Copy link
Contributor Author

tyrwzl commented Jun 4, 2024

Thank you for instructions.
Added GET api/v1/indexes test.

GET /api/v1/mock-sales/search?query=animal
[200] => {"num_hits": 0, "hits": [], "elapsed_time_micros": 51301, "errors": []}
POST /api/v1/mock-sales/search
[200] => {"num_hits": 0, "hits": [], "elapsed_time_micros": 1600, "errors": []}
GET /api/v1/_elastic/mock-sales/_search?q=animal
[200] => {"took": 1, "timed_out": false, "_shards": {"total": 1, "successful": 1, "skipped": 0, "failed": 0},
POST /api/v1/_elastic/mock-sales/_search
[200] => {"took": 1, "timed_out": false, "_shards": {"total": 1, "successful": 1, "skipped": 0, "failed": 0},
GET /api/v1/_elastic/mock-sales/_field_caps?fields=quantity
[200] => {"indices": [], "fields": {}}
GET /api/v1/_elastic/mock-sales/_search?query=animal
[400] => {"message": "unknown field `query`, expected one of `_source`, `_source_excludes`, `_source_includes
GET /api/v1/_elastic/_search?q=animal
[501] => {"message": "_elastic/_search is not supported yet. Please try the index search endpoint (_elastic/{
GET /api/v1/indexes/mock-sales
[200] => {"version": "0.8", "index_uid": "mock-sales:01HZGCF383DMRQMFNEHPWFWB0S", "index_config": {"version":

@rdettai rdettai enabled auto-merge (squash) June 4, 2024 12:30
@rdettai
Copy link
Contributor

rdettai commented Jun 4, 2024

@tyrwzl we should add some instructions on how to set up Grafana on top of the API Gateway in the README. Would you be interested in opening a PR for that?

@rdettai rdettai merged commit 63f198b into quickwit-oss:main Jun 4, 2024
4 of 5 checks passed
@tyrwzl
Copy link
Contributor Author

tyrwzl commented Jun 5, 2024

@rdettai
Sure, I'll work on that.

@tyrwzl
Copy link
Contributor Author

tyrwzl commented Jun 7, 2024

@rdettai
Hi, I created PR #5092.
Could you please take a look at it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GET api/v1/indexes to Lambda searcher
3 participants