-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Handle multiple upstreams in ingress-controller #21215
Changes from 5 commits
cd2eabe
6452ee9
3e9aefd
c8fe66d
53c9a14
1656658
5c2d179
d224986
d3f0a19
e96271f
539d072
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,18 @@ processors: | |
%{NUMBER:http.response.status_code:long} %{NUMBER:http.response.body.bytes:long} | ||
"(-|%{DATA:http.request.referrer})" "(-|%{DATA:user_agent.original})" %{NUMBER:nginx.ingress_controller.http.request.length:long} | ||
%{NUMBER:nginx.ingress_controller.http.request.time:double} \[%{DATA:nginx.ingress_controller.upstream.name}\] | ||
\[%{DATA:nginx.ingress_controller.upstream.alternative_name}\] (%{UPSTREAM_ADDRESS}|-) | ||
(%{NUMBER:nginx.ingress_controller.upstream.response.length:long}|-) (%{NUMBER:nginx.ingress_controller.upstream.response.time:double}|-) | ||
(%{NUMBER:nginx.ingress_controller.upstream.response.status_code:long}|-) %{GREEDYDATA:nginx.ingress_controller.http.request.id} | ||
\[%{DATA:nginx.ingress_controller.upstream.alternative_name}\] (%{UPSTREAM_ADDRESS_LIST:nginx.ingress_controller.upstream_ip_list}|-) | ||
(%{UPSTREAM_RESPONSE_LENGTH_LIST:nginx.ingress_controller.upstream.response.length_list}|-) (%{UPSTREAM_RESPONSE_TIME_LIST:nginx.ingress_controller.upstream.response.time_list}|-) | ||
(%{UPSTREAM_RESPONSE_STATUS_CODE_LIST:nginx.ingress_controller.upstream.response.status_code_list}|-) %{GREEDYDATA:nginx.ingress_controller.http.request.id} | ||
pattern_definitions: | ||
NGINX_HOST: (?:%{IP:destination.ip}|%{NGINX_NOTSEPARATOR:destination.domain})(:%{NUMBER:destination.port})? | ||
NGINX_NOTSEPARATOR: "[^\t ,:]+" | ||
NGINX_ADDRESS_LIST: (?:%{IP}|%{WORD})("?,?\s*(?:%{IP}|%{WORD}))* | ||
UPSTREAM_ADDRESS: '%{IP:nginx.ingress_controller.upstream.ip}(:%{NUMBER:nginx.ingress_controller.upstream.port})?' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used now. |
||
UPSTREAM_ADDRESS_LIST: (?:%{IP}(:%{NUMBER})?)("?,?\s*(?:%{IP}(:%{NUMBER})?))* | ||
UPSTREAM_RESPONSE_LENGTH_LIST: (?:%{NUMBER})("?,?\s*(?:%{NUMBER}))* | ||
UPSTREAM_RESPONSE_TIME_LIST: (?:%{NUMBER})("?,?\s*(?:%{NUMBER}))* | ||
UPSTREAM_RESPONSE_STATUS_CODE_LIST: (?:%{NUMBER})("?,?\s*(?:%{NUMBER}))* | ||
ignore_missing: true | ||
- grok: | ||
field: nginx.ingress_controller.info | ||
|
@@ -33,6 +37,22 @@ processors: | |
field: nginx.ingress_controller.remote_ip_list | ||
separator: '"?,?\s+' | ||
ignore_missing: true | ||
- split: | ||
field: nginx.ingress_controller.upstream_ip_list | ||
separator: '"?,?\s+' | ||
ignore_missing: true | ||
- split: | ||
field: nginx.ingress_controller.upstream.response.length_list | ||
separator: '"?,?\s+' | ||
ignore_missing: true | ||
- split: | ||
field: nginx.ingress_controller.upstream.response.time_list | ||
separator: '"?,?\s+' | ||
ignore_missing: true | ||
- split: | ||
field: nginx.ingress_controller.upstream.response.status_code_list | ||
separator: '"?,?\s+' | ||
ignore_missing: true | ||
- split: | ||
field: nginx.ingress_controller.origin | ||
separator: '"?,?\s+' | ||
|
@@ -41,6 +61,81 @@ processors: | |
field: source.address | ||
if: ctx.source?.address == null | ||
value: "" | ||
- script: | ||
if: ctx.nginx?.ingress_controller?.upstream?.response?.length_list != null && ctx.nginx.ingress_controller.upstream.response.length_list.length > 0 | ||
lang: painless | ||
source: >- | ||
try { | ||
if (ctx.nginx.ingress_controller.upstream.response.length_list.length == null) { | ||
return; | ||
} | ||
int length = 0; | ||
for (def item : ctx.nginx.ingress_controller.upstream.response.length_list) { | ||
length = length + Integer.parseInt(item); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, does it make sense to sum up the response lengths? The client would only see the most recent response. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, I will go with it! Thanks! |
||
} | ||
ctx.nginx.ingress_controller.upstream.response.length_total = length; | ||
} | ||
catch (Exception e) { | ||
ctx.nginx.ingress_controller.upstream.response.length_total = null; | ||
} | ||
- script: | ||
if: ctx.nginx?.ingress_controller?.upstream?.response?.time_list != null && ctx.nginx.ingress_controller.upstream.response.time_list.length > 0 | ||
lang: painless | ||
source: >- | ||
try { | ||
if (ctx.nginx.ingress_controller.upstream.response.time_list.length == null) { | ||
return; | ||
} | ||
float res_time = 0; | ||
for (def item : ctx.nginx.ingress_controller.upstream.response.time_list) { | ||
res_time = res_time + Float.parseFloat(item); | ||
} | ||
ctx.nginx.ingress_controller.upstream.response.time_total = res_time; | ||
} | ||
catch (Exception e) { | ||
ctx.nginx.ingress_controller.upstream.response.time_total = null; | ||
} | ||
- script: | ||
if: ctx.nginx?.ingress_controller?.upstream?.response?.status_code_list != null && ctx.nginx.ingress_controller.upstream.response.status_code_list.length > 0 | ||
lang: painless | ||
source: >- | ||
try { | ||
if (ctx.nginx.ingress_controller.upstream.response.status_code_list.length == null) { | ||
return; | ||
} | ||
int last_status_code; | ||
for (def item : ctx.nginx.ingress_controller.upstream.response.status_code_list) { | ||
last_status_code = Integer.parseInt(item); | ||
} | ||
ctx.nginx.ingress_controller.upstream.response.status_code = last_status_code; | ||
} | ||
catch (Exception e) { | ||
ctx.nginx.ingress_controller.upstream.response.time = null; | ||
} | ||
- script: | ||
if: ctx.nginx?.ingress_controller?.upstream_ip_list != null && ctx.nginx.ingress_controller.upstream_ip_list.length > 0 | ||
lang: painless | ||
source: >- | ||
try { | ||
if (ctx.nginx.ingress_controller.upstream_ip_list.length == null) { | ||
return; | ||
} | ||
def last_upstream = ""; | ||
for (def item : ctx.nginx.ingress_controller.upstream_ip_list) { | ||
last_upstream = item; | ||
} | ||
StringTokenizer tok = new StringTokenizer(last_upstream, ":"); | ||
if (tok.countTokens()>1) { | ||
ctx.nginx.ingress_controller.upstream.ip = tok.nextToken(); | ||
ctx.nginx.ingress_controller.upstream.port = Integer.parseInt(tok.nextToken()); | ||
} else { | ||
ctx.nginx.ingress_controller.upstream.ip = last_upstream; | ||
} | ||
} | ||
catch (Exception e) { | ||
ctx.nginx.ingress_controller.upstream.ip = null; | ||
ctx.nginx.ingress_controller.upstream.port = null; | ||
} | ||
- script: | ||
if: ctx.nginx?.ingress_controller?.remote_ip_list != null && ctx.nginx.ingress_controller.remote_ip_list.length > 0 | ||
lang: painless | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that
type: array
only doesn't generate any mapping. This should be an array of keywords, or just keyword. Elasticsearch doesn't have a data type for arrays, but any field can have multiple values, see docs about arrays).We could use just keyword:
Or if we still want to indicate that this is intended to store multiple values:
Same for the other lists.