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

[filebeat] Add write access to 'url.value' from 'request.transforms'. #27937

Merged
merged 1 commit into from Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Expand Up @@ -756,6 +756,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Improve memory usage of line reader of `log` and `filestream` input. {pull}27782[27782]
- Add `ignore_empty_value` flag to `httpjson` `split` processor. {pull}27880[27880]
- Update Cisco ASA/FTD ingest pipeline grok/dissect patterns for multiple message IDs. {issue}26869[26869] {pull}26879[26879]
- Add write access to `url.value` from `request.transforms` in `httpjson` input. {pull}27937[27937]

*Heartbeat*

Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/docs/inputs/input-httpjson.asciidoc
Expand Up @@ -466,7 +466,7 @@ Available transforms for request: [`append`, `delete`, `set`].

Can read state from: [`.last_response.*`, `.last_event.*`, `.cursor.*`, `.header.*`, `.url.*`, `.body.*`].

Can write state to: [`header.*`, `url.params.*`, `body.*`].
Can write state to: [`body.*`, `header.*`, `url.*`].

["source","yaml",subs="attributes"]
----
Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/httpjson/internal/v2/pagination.go
Expand Up @@ -19,7 +19,7 @@ const paginationNamespace = "pagination"
func registerPaginationTransforms() {
registerTransform(paginationNamespace, appendName, newAppendPagination)
registerTransform(paginationNamespace, deleteName, newDeletePagination)
registerTransform(paginationNamespace, setName, newSetPagination)
registerTransform(paginationNamespace, setName, newSetRequestPagination)
}

type pagination struct {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/httpjson/internal/v2/request.go
Expand Up @@ -22,7 +22,7 @@ const requestNamespace = "request"
func registerRequestTransforms() {
registerTransform(requestNamespace, appendName, newAppendRequest)
registerTransform(requestNamespace, deleteName, newDeleteRequest)
registerTransform(requestNamespace, setName, newSetRequest)
registerTransform(requestNamespace, setName, newSetRequestPagination)
}

type httpClient struct {
Expand Down
26 changes: 3 additions & 23 deletions x-pack/filebeat/input/httpjson/internal/v2/transform_set.go
Expand Up @@ -39,7 +39,7 @@ type set struct {

func (set) transformName() string { return setName }

func newSetRequest(cfg *common.Config, log *logp.Logger) (transform, error) {
func newSetRequestPagination(cfg *common.Config, log *logp.Logger) (transform, error) {
set, err := newSet(cfg, log)
if err != nil {
return nil, err
Expand All @@ -52,6 +52,8 @@ func newSetRequest(cfg *common.Config, log *logp.Logger) (transform, error) {
set.runFunc = setHeader
case targetURLParams:
set.runFunc = setURLParams
case targetURLValue:
set.runFunc = setURLValue
default:
return nil, fmt.Errorf("invalid target type: %s", set.targetInfo.Type)
}
Expand All @@ -75,28 +77,6 @@ func newSetResponse(cfg *common.Config, log *logp.Logger) (transform, error) {
return &set, nil
}

func newSetPagination(cfg *common.Config, log *logp.Logger) (transform, error) {
set, err := newSet(cfg, log)
if err != nil {
return nil, err
}

switch set.targetInfo.Type {
case targetBody:
set.runFunc = setBody
case targetHeader:
set.runFunc = setHeader
case targetURLParams:
set.runFunc = setURLParams
case targetURLValue:
set.runFunc = setURLValue
default:
return nil, fmt.Errorf("invalid target type: %s", set.targetInfo.Type)
}

return &set, nil
}

func newSet(cfg *common.Config, log *logp.Logger) (set, error) {
c := &setConfig{}
if err := cfg.Unpack(c); err != nil {
Expand Down
52 changes: 10 additions & 42 deletions x-pack/filebeat/input/httpjson/internal/v2/transform_set_test.go
Expand Up @@ -41,72 +41,40 @@ func TestNewSet(t *testing.T) {
expectedErr: "invalid target: cursor.foo",
},
{
name: "newSetRequest targets body",
constructor: newSetRequest,
name: "newSetRequestPagination targets body",
constructor: newSetRequestPagination,
config: map[string]interface{}{
"target": "body.foo",
},
expectedTarget: targetInfo{Name: "foo", Type: "body"},
},
{
name: "newSetRequest targets header",
constructor: newSetRequest,
name: "newSetRequestPagination targets header",
constructor: newSetRequestPagination,
config: map[string]interface{}{
"target": "header.foo",
},
expectedTarget: targetInfo{Name: "foo", Type: "header"},
},
{
name: "newSetRequest targets url param",
constructor: newSetRequest,
name: "newSetRequestPagination targets url param",
constructor: newSetRequestPagination,
config: map[string]interface{}{
"target": "url.params.foo",
},
expectedTarget: targetInfo{Name: "foo", Type: "url.params"},
},
{
name: "newSetRequest targets something else",
constructor: newSetRequest,
config: map[string]interface{}{
"target": "cursor.foo",
},
expectedErr: "invalid target: cursor.foo",
},
{
name: "newSetPagination targets body",
constructor: newSetPagination,
config: map[string]interface{}{
"target": "body.foo",
},
expectedTarget: targetInfo{Name: "foo", Type: "body"},
},
{
name: "newSetPagination targets header",
constructor: newSetPagination,
config: map[string]interface{}{
"target": "header.foo",
},
expectedTarget: targetInfo{Name: "foo", Type: "header"},
},
{
name: "newSetPagination targets url param",
constructor: newSetPagination,
config: map[string]interface{}{
"target": "url.params.foo",
},
expectedTarget: targetInfo{Name: "foo", Type: "url.params"},
},
{
name: "newSetPagination targets url value",
constructor: newSetPagination,
name: "newSetRequestPagination targets url value",
constructor: newSetRequestPagination,
config: map[string]interface{}{
"target": "url.value",
},
expectedTarget: targetInfo{Type: "url.value"},
},
{
name: "newSetPagination targets something else",
constructor: newSetPagination,
name: "newSetRequestPagination targets something else",
constructor: newSetRequestPagination,
config: map[string]interface{}{
"target": "cursor.foo",
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/filebeat/input/httpjson/internal/v2/transform_test.go
Expand Up @@ -46,7 +46,7 @@ func TestTransformableClone(t *testing.T) {
}

func TestNewTransformsFromConfig(t *testing.T) {
registerTransform("test", setName, newSetRequest)
registerTransform("test", setName, newSetRequestPagination)
t.Cleanup(func() { registeredTransforms = newRegistry() })

cases := []struct {
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestNewBasicTransformsFromConfig(t *testing.T) {
return fakeTransform{}, nil
}

registerTransform("test", setName, newSetRequest)
registerTransform("test", setName, newSetRequestPagination)
registerTransform("test", "fake", fakeConstr)
t.Cleanup(func() { registeredTransforms = newRegistry() })

Expand Down