Skip to content

Commit

Permalink
enhancement(remap transform): add parse_aws_alb_log function (#5489)
Browse files Browse the repository at this point in the history
Signed-off-by: Kirill Fomichev <fanatid@ya.ru>
  • Loading branch information
fanatid authored Dec 18, 2020
1 parent 9f760f2 commit 6389e88
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
/docs/reference/remap/log.cue @FungusHumungus
/docs/reference/remap/merge.cue @FungusHumungus
/docs/reference/remap/parse_grok.cue @FungusHumungus
/docs/reference/remap/parse_aws_alb_log.cue @fanatid

/distribution/ @hoverbear @jamtur01
/distribution/docker/ @vector-kubernetes
Expand All @@ -101,6 +102,7 @@
/lib/remap-functions/src/ipv6_to_ipv4.rs @FungusHumungus
/lib/remap-functions/src/log.rs @FungusHumungus
/lib/remap-functions/src/merge.rs @FungusHumungus
/src/remap/function/parse_aws_alb_log.rs @fanatid
/lib/remap-functions/src/parse_grok.rs @FungusHumungus

/proto/ @lukesteensen
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions docs/reference/remap/parse_aws_alb_log.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package metadata

remap: functions: parse_aws_alb_log: {
arguments: [
{
name: "value"
description: "Access log of the Application Load Balancer."
required: true
type: ["string"]
},
]
return: ["map"]
category: "parse"
description: #"""
Parses a Elastic Load Balancer Access log into it's constituent components.
"""#
examples: [
{
title: "Success"
input: {
log: #"http 2018-11-30T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 - 0.000 0.001 0.000 200 200 34 366 "GET http://www.example.com:80/ HTTP/1.1" "curl/7.46.0" - - arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337364-23a8c76965a2ef7629b185e3" "-" "-" 0 2018-11-30T22:22:48.364000Z "forward" "-" "-" "-" "-" "-" "-""#
}
source: #"""
.parsed = parse_aws_alb_log(.log)
"""#
output: {
log: #"http 2018-11-30T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 - 0.000 0.001 0.000 200 200 34 366 "GET http://www.example.com:80/ HTTP/1.1" "curl/7.46.0" - - arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337364-23a8c76965a2ef7629b185e3" "-" "-" 0 2018-11-30T22:22:48.364000Z "forward" "-" "-" "-" "-" "-" "-""#
parsed: {
"type": "http"
"timestamp": "2018-11-30T22:23:00.186641Z"
"elb": "app/my-loadbalancer/50dc6c495c0c9188"
"client_host": "192.168.131.39:2817"
"target_host": null
"request_processing_time": 0.0
"target_processing_time": 0.001
"response_processing_time": 0.0
"elb_status_code": "200"
"target_status_code": "200"
"received_bytes": 34
"sent_bytes": 366
"request_method": "GET"
"request_url": "http://www.example.com:80/"
"request_protocol": "HTTP/1.1"
"user_agent": "curl/7.46.0"
"ssl_cipher": null
"ssl_protocol": null
"target_group_arn": "arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"
"trace_id": "Root=1-58337364-23a8c76965a2ef7629b185e3"
"domain_name": null
"chosen_cert_arn": null
"matched_rule_priority": "0"
"request_creation_time": "2018-11-30T22:22:48.364000Z"
"actions_executed": "forward"
"redirect_url": null
"error_reason": null
"target_port_list": []
"target_status_code_list": []
"classification": null
"classification_reason": null
}
}
},
{
title: "Error"
input: {
log: "I am not a log"
}
source: #"""
.parsed = parse_aws_alb_log(.log)
"""#
output: {
error: remap.errors.ParseError
}
},
]
}
3 changes: 3 additions & 0 deletions lib/remap-functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ grok = { version = "1", optional = true }
hex = { version = "0.4", optional = true }
lazy_static = { version = "1", optional = true }
md-5 = { version = "0.9", optional = true }
nom = { version = "6.0.1", optional = true }
regex = { version = "1", optional = true }
rust_decimal = { version = "1", optional = true }
serde_json = { version = "1", optional = true }
Expand Down Expand Up @@ -57,6 +58,7 @@ default = [
"now",
"ok",
"only_fields",
"parse_aws_alb_log",
"parse_duration",
"parse_grok",
"parse_json",
Expand Down Expand Up @@ -108,6 +110,7 @@ merge = []
now = []
ok = []
only_fields = []
parse_aws_alb_log = ["nom"]
parse_duration = []
parse_grok = ["grok"]
parse_json = ["serde_json"]
Expand Down
6 changes: 6 additions & 0 deletions lib/remap-functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ mod now;
mod ok;
#[cfg(feature = "only_fields")]
mod only_fields;
#[cfg(feature = "parse_aws_alb_log")]
mod parse_aws_alb_log;
#[cfg(feature = "parse_duration")]
mod parse_duration;
#[cfg(feature = "parse_grok")]
Expand Down Expand Up @@ -147,6 +149,8 @@ pub use now::Now;
pub use ok::OK;
#[cfg(feature = "only_fields")]
pub use only_fields::OnlyFields;
#[cfg(feature = "parse_aws_alb_log")]
pub use parse_aws_alb_log::ParseAwsAlbLog;
#[cfg(feature = "parse_duration")]
pub use parse_duration::ParseDuration;
#[cfg(feature = "parse_grok")]
Expand Down Expand Up @@ -248,6 +252,8 @@ pub fn all() -> Vec<Box<dyn remap::Function>> {
Box::new(OK),
#[cfg(feature = "only_fields")]
Box::new(OnlyFields),
#[cfg(feature = "parse_aws_alb_log")]
Box::new(ParseAwsAlbLog),
#[cfg(feature = "parse_duration")]
Box::new(ParseDuration),
#[cfg(feature = "parse_grok")]
Expand Down
Loading

0 comments on commit 6389e88

Please sign in to comment.