Skip to content

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Dec 11, 2025

Proposed commit message

Changes:

  • Add SetPaths(path *paths.Path) method to jsProcessor that accepts a per-beat paths configuration
  • Defer file-based source initialization until SetPaths is called
  • For inline sources, initialization still happens immediately in NewFromConfig
  • loadSources now takes a *paths.Path parameter and uses pathConfig.Resolve() instead of the global paths.Resolve()

Fixes #46988

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using the changelog tool.

How to test this PR locally

Run filebeat with:

path.config: myconfig/

filebeat.inputs:
  - type: filestream
    id: input-a
    paths:
      - /tmp/logs/a.log

    processors:
      - script:
          lang: javascript
          file: test_processor.js
          tag: test-js-processor

output.console:
  enabled: true

myconfig/test_processor.js:

function process(event) {
    event.Put("js_processor.processed", true);
    event.Put("js_processor.timestamp", new Date().toISOString());

    var msg = event.Get("message");
    if (msg) {
        event.Put("message_upper", msg.toUpperCase());
    }

    return event;
}

write some logs:

yes 'some log' | head -n 10000 > /tmp/logs/a.log

See output:

{
  "@timestamp": "2025-12-02T18:09:36.488Z",
  "@metadata": {
    "beat": "filebeat",
    "type": "_doc",
    "version": "9.3.0"
  },
  "ecs": {
    "version": "8.0.0"
  },
  "log": {
    "offset": 89586,
    "file": {
      "path": "/tmp/logs/a.log",
      "device_id": "38",
      "inode": "73159",
      "fingerprint": "83016ba24a8d31ccb16d2230eabcb1f043fa4c65914339eb954619b5c13fd55a"
    }
  },
  "message": "some log",
  "input": {
    "type": "filestream"
  },
  "js_processor": {
    "processed": true,
    "timestamp": "2025-12-02T18:09:36.488Z"
  },
  "message_upper": "SOME LOG",
  "host": {
    "name": "laptop"
  },
  "agent": {
    "version": "9.3.0",
    "ephemeral_id": "f6bb5c64-d2d1-4dad-a0e1-bbc553b617ec",
    "id": "40aef7d0-efcb-4613-a1df-d9bc42ff36b9",
    "name": "laptop",
    "type": "filebeat"
  }
}

Related issues

## Proposed commit message
Changes:
- Add SetPaths(path *paths.Path) method to jsProcessor that accepts a per-beat paths configuration
- Defer file-based source initialization until SetPaths is called
- For inline sources, initialization still happens immediately in NewFromConfig
- loadSources now takes a *paths.Path parameter and uses pathConfig.Resolve() instead of the global paths.Resolve()

Fixes #46988

## How to test this PR locally

Run filebeat with:

```yaml
path.config: myconfig/

filebeat.inputs:
  - type: filestream
    id: input-a
    paths:
      - /tmp/logs/a.log

    processors:
      - script:
          lang: javascript
          file: test_processor.js
          tag: test-js-processor

output.console:
  enabled: true
```

`myconfig/test_processor.js`:
```js
function process(event) {
    event.Put("js_processor.processed", true);
    event.Put("js_processor.timestamp", new Date().toISOString());

    var msg = event.Get("message");
    if (msg) {
        event.Put("message_upper", msg.toUpperCase());
    }

    return event;
}
```

write some logs:
```sh
yes 'some log' | head -n 10000 > /tmp/logs/a.log
```

See output:
```json
{
  "@timestamp": "2025-12-02T18:09:36.488Z",
  "@metadata": {
    "beat": "filebeat",
    "type": "_doc",
    "version": "9.3.0"
  },
  "ecs": {
    "version": "8.0.0"
  },
  "log": {
    "offset": 89586,
    "file": {
      "path": "/tmp/logs/a.log",
      "device_id": "38",
      "inode": "73159",
      "fingerprint": "83016ba24a8d31ccb16d2230eabcb1f043fa4c65914339eb954619b5c13fd55a"
    }
  },
  "message": "some log",
  "input": {
    "type": "filestream"
  },
  "js_processor": {
    "processed": true,
    "timestamp": "2025-12-02T18:09:36.488Z"
  },
  "message_upper": "SOME LOG",
  "host": {
    "name": "laptop"
  },
  "agent": {
    "version": "9.3.0",
    "ephemeral_id": "f6bb5c64-d2d1-4dad-a0e1-bbc553b617ec",
    "id": "40aef7d0-efcb-4613-a1df-d9bc42ff36b9",
    "name": "laptop",
    "type": "filebeat"
  }
}
```

## Related issues

- Closes #46988
- Relates #47353

(cherry picked from commit 2179473)
@mergify mergify bot added the backport label Dec 11, 2025
@mergify mergify bot requested review from a team as code owners December 11, 2025 08:20
@mergify mergify bot requested review from AndersonQ and VihasMakwana and removed request for a team December 11, 2025 08:20
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 11, 2025
@github-actions
Copy link
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Dec 11, 2025
@orestisfl orestisfl enabled auto-merge (squash) December 11, 2025 08:46
@mergify
Copy link
Contributor Author

mergify bot commented Dec 15, 2025

This pull request has not been merged yet. Could you please review and merge it @orestisfl? 🙏

@orestisfl orestisfl merged commit a16804f into 8.19 Dec 15, 2025
208 checks passed
@orestisfl orestisfl deleted the mergify/bp/8.19/pr-47870 branch December 15, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants