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

The "formatDate" to UNIX on httpjson is not working on multiple version (7.17.0-8.11.3) #37479

Open
nitzango opened this issue Dec 21, 2023 · 3 comments
Labels
needs_team Indicates that the issue/PR needs a Team:* label

Comments

@nitzango
Copy link

Hi team,

I'm trying to pull data from an API that expect UNIX time as a query parameter (e.g. oldest event to pull).
While setting '[[ formatDate (now (parseDuration "-4h")) ]]' as the default for the first time run, it seems like the actual parameter is not transformed to UNIX as stays normal timestamp (I used ngrok to debug):

latest=Thu+Dec+21+09%3A30%3A28+UTC+2023

I tried to use the following filebeat config:

filebeat.inputs:
  - type: httpjson
    config_version: 2
    interval: 10m

    request.method: POST
    request.url: https://url.goes.here

    request.transforms:
    - set:
        target: header.Authorization
        value: "Bearer 123456"
    - set:
        target: header.Accept
        value: "application/json"
    - set:
        target: url.params.latest
        value: '[[.cursor.last_event_time]]'
        default: '[[ formatDate (now (parseDuration "-4h")) ]]'

For confirmed bugs, please report:

  • Version: multiple version (7.17.0-8.11.3)
  • Operating System: Docker on macOS + Kubernetes
  • Steps to Reproduce: Use the config above
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 21, 2023
@botelastic
Copy link

botelastic bot commented Dec 21, 2023

This issue doesn't have a Team:<team> label.

@nitzango nitzango changed the title The "formatDate" on httpjson is not working on multiple version (7.17.0-8.11.3) The "formatDate" to UNIX on httpjson is not working on multiple version (7.17.0-8.11.3) Dec 21, 2023
@levi-burton
Copy link

Are there any updates on this issue? I am running the Elastic Agent on version '8.11.3" and also observing the same issue where I need to provide a request transform including a dynamic Unix timestamp but instead see a human readable timestamp is being passed when viewing the debug logs.

@efd6
Copy link
Contributor

efd6 commented Oct 9, 2024

I have confirmed that the default behaves as intended by adding a test to the transforms test suite.

..at/input/httpjson [master|✚] $ git diff            
diff --git a/x-pack/filebeat/input/httpjson/value_tpl_test.go b/x-pack/filebeat/input/httpjson/value_tpl_test.go
index 4b642a1697..8bf8dbd2cb 100644
--- a/x-pack/filebeat/input/httpjson/value_tpl_test.go
+++ b/x-pack/filebeat/input/httpjson/value_tpl_test.go
@@ -56,6 +56,15 @@ func TestValueTpl(t *testing.T) {
                        paramDefVal: "",
                        expectedVal: "25",
                },
+               {
+                       name:        "date",
+                       setup:       func() { timeNow = func() time.Time { return time.Unix(1604582732, 0).UTC() } },
+                       teardown:    func() { timeNow = time.Now },
+                       value:       `[[ formatDate (now (parseDuration "-4h")) ]]`,
+                       paramCtx:    emptyTransformContext(),
+                       paramTr:     transformable{},
+                       expectedVal: "2020-11-05T09:25:32Z",
+               },
                {
                        name:  "can render default value if execute fails",
                        value: "[[.last_response.body.does_not_exist]]",
..at/input/httpjson [master|✚] $ go test -run TestValueTpl/date
PASS
ok  	github.com/elastic/beats/v7/x-pack/filebeat/input/httpjson	0.367s

My guess is that what is happening is that the value from the .cursor.last_event_time has not been formatted correctly and you are seeing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs_team Indicates that the issue/PR needs a Team:* label
Projects
None yet
Development

No branches or pull requests

3 participants