From 615b1e22a3e3cadfecdcae959d4bd75dfbfb552c Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Sun, 29 Dec 2019 12:37:23 +0200 Subject: [PATCH] added tracking to which es host the search was sent --- README.md | 2 +- lib/finish_tracking.js | 2 ++ lib/proxy_request.js | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1414fec..5497aa1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The proxy intercepts search requests and record them into Elasticsearch for furt "x-opaque-id": "123", "content-type": "application/json", "x-query-tracker-id": "1234", - "x-query-tracker-tags": "itay, or" + "x-query-tracker-tags": "auth, login" }, "tags": [ "itay", diff --git a/lib/finish_tracking.js b/lib/finish_tracking.js index 07ac037..74e6137 100644 --- a/lib/finish_tracking.js +++ b/lib/finish_tracking.js @@ -7,10 +7,12 @@ function sign_request(context, res) { context.times.end = new Date(); context.times.req_took_ms = context.times.end - context.times.start; const body = JSON.parse(res.payload.body); + const target = res.payload.target; context.times.elastic_took_ms = body.took; //context.query.times = context.times; context.response = { + es_host: target, took: body.took, timed_out: body.timed_out, shards: body._shards, diff --git a/lib/proxy_request.js b/lib/proxy_request.js index 1e2f3ab..a599e00 100644 --- a/lib/proxy_request.js +++ b/lib/proxy_request.js @@ -21,9 +21,10 @@ const wreck = Wreck.defaults({ function proxy_request(req, res) { + const target = fetch_host(process.env.ELASTIC_HOST || 'http://localhost:9200'); // all attributes are optional const options = { - baseUrl: fetch_host(process.env.ELASTIC_HOST || 'http://localhost:9200'), + baseUrl: target, //payload: readableStream || 'foo=bar' || new Buffer('foo=bar'), headers: { /* http headers */ }, redirects: 3, @@ -52,6 +53,7 @@ function proxy_request(req, res) { res.payload = { statusCode: response.statusCode, headers: response.headers, + target, body }; return resolve();