Skip to content

[CI] Speed up telemetry_check by pre-filtering to collector files#265978

Merged
shahzad31 merged 9 commits intoelastic:mainfrom
shahzad31:speed-up-telemetry-check
May 5, 2026
Merged

[CI] Speed up telemetry_check by pre-filtering to collector files#265978
shahzad31 merged 9 commits intoelastic:mainfrom
shahzad31:speed-up-telemetry-check

Conversation

@shahzad31
Copy link
Copy Markdown
Contributor

@shahzad31 shahzad31 commented Apr 28, 2026

Summary

The telemetry.sh quick check takes ~8m 45s in CI — the single slowest check in the quick_checks step. It also runs in the serial mayChangeFiles queue, blocking all other serial checks behind it.

The problem

extractCollectors() passes all ~36K TS files from each of the 10 telemetry roots into ts.createProgram(), even though only ~69 files across the entire repo actually contain makeUsageCollector or makeStatsCollector calls.

TypeScript parses and type-checks thousands of unrelated source files that will never yield a collector.

The fix

Pre-filter files with a simple regex scan on file contents before feeding them to the TS compiler:

const collectorPaths = fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p, 'utf-8')));

TypeScript still resolves all transitive imports needed for type-checking the collector files, but avoids parsing thousands of unrelated files.

Benchmark results (local)

src/platform/ root (largest OSS root):

Approach Root files Source files TS loads Time
Current (all files) 8,852 17,279 48s
New (collector files only) 30 4,814 15s
Speedup 3.6x fewer 3.1x faster

x-pack/platform/ root (largest x-pack root):

Approach Root files Source files TS loads Time
Current (all files) 15,344 25,002 71s
New (collector files only) 27 13,835 49s
Speedup 1.8x fewer 1.5x faster

CI estimate: telemetry.sh should drop from ~8m 45s to ~3-4 min.

How it was tested

  • Profiled createKibanaProgram locally with the actual Kibana telemetry roots
  • Verified the same collector files are found and processed
  • The pre-filter is conservative — any file mentioning the collector function names is included

Made with Cursor

The telemetry check passes all ~36K TS files from each root directory
into `ts.createProgram()`, even though only ~69 files actually contain
`makeUsageCollector` or `makeStatsCollector` calls.

Pre-filter with a simple regex scan on file contents before feeding to
the TS compiler. TypeScript still resolves transitive imports needed for
type-checking, but avoids parsing thousands of unrelated files.

Benchmarked locally (src/platform root):
- Before: 8,852 root files → 17,279 source files loaded → 48s
- After:  30 root files → 4,814 source files loaded → 15s (3.1x faster)

This optimization applies per-root. Combined across all 10 roots,
the telemetry_check should drop from ~8m 45s to ~3-4 min in CI.

Made-with: Cursor
@shahzad31 shahzad31 added backport:skip This PR does not require backporting ci:use-selective-testing Turns on selective testing features for the PR CI run release_note:skip Skip the PR/issue when compiling release notes Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. labels Apr 28, 2026
@github-actions github-actions Bot added the author:actionable-obs PRs authored by the actionable obs team label Apr 28, 2026
@shahzad31 shahzad31 added backport:all-open Backport to all branches that could still receive a release and removed backport:skip This PR does not require backporting labels Apr 29, 2026
@shahzad31 shahzad31 marked this pull request as ready for review April 29, 2026 18:06
@shahzad31 shahzad31 requested a review from a team as a code owner April 29, 2026 18:06
@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

Pinging @elastic/actionable-obs-team (Team:actionable-obs)

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Apr 29, 2026

Approvability

Verdict: Needs human review

The modified file is owned by @elastic/kibana-core, not the PR author. The pre-filtering optimization could potentially miss files that reference collectors through re-exports rather than direct usage. The designated code owners should verify this CI optimization is safe.

No code changes detected at 29df80e. Prior analysis still applies.

You can customize Macroscope's approvability policy. Learn more.

Copy link
Copy Markdown
Contributor

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! lgtm

Copy link
Copy Markdown
Contributor

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! lgtm

@kibanamachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

@shahzad31 shahzad31 merged commit b3cb3c8 into elastic:main May 5, 2026
24 checks passed
@shahzad31 shahzad31 deleted the speed-up-telemetry-check branch May 5, 2026 07:14
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.19, 9.2, 9.3, 9.4

https://github.com/elastic/kibana/actions/runs/25362981633

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
8.19
9.2
9.3
9.4

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request May 5, 2026
…es (#265978) (#267655)

# Backport

This will backport the following commits from `main` to `9.4`:
- [[CI] Speed up telemetry_check by pre-filtering to collector files
(#265978)](#265978)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2026-05-05T07:14:21Z","message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a","branchLabelMapping":{"^v9.5.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","Team:actionable-obs","author:actionable-obs","ci:use-selective-testing","v9.5.0"],"title":"[CI]
Speed up telemetry_check by pre-filtering to collector
files","number":265978,"url":"https://github.com/elastic/kibana/pull/265978","mergeCommit":{"message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.5.0","branchLabelMappingKey":"^v9.5.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/265978","number":265978,"mergeCommit":{"message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
Co-authored-by: Ahmad Bamieh <ahmad.bamyeh@elastic.co>
mbondyra added a commit to mbondyra/kibana that referenced this pull request May 5, 2026
…ilder_new_vis_attachment

* commit '6fd683609eb6dee81f242f8ff6951edbe3bfd66c': (226 commits)
  Remove Model Author group-by option from external inference endpoints (elastic#264761)
  [Streams][Streamlang] Align ES|QL condition transpiler with Painless on null propagation (elastic#264751)
  chore(axios,workflows-eng): remove axios from workflows connector utils (elastic#267512)
  [failed-test-reporter] avoid opening issues for scout env failures (elastic#267649)
  [kbn-api-contracts] Detect request-body additionalProperties:false tightening (elastic#267546)
  [main] Sync bundled packages with Package Storage (elastic#267644)
  Centralize phase colors and descriptions (elastic#266680)
  [Unified Waterfall] Add "Scroll to origin" button  (elastic#266594)
  [APM] Add alert and SLO badges to the service map embeddable (elastic#266360)
  [CI] Speed up telemetry_check by pre-filtering to collector files (elastic#265978)
  [Discover] Address flaky large CSV test (elastic#266642)
  avoid passing unrelated props within integration card icon component conditional render (elastic#266569)
  [Cases][Templates] Extend cases search by template field label (elastic#266414)
  [Background search] Migrate custom SplitButton to EuiSplitButton (elastic#267447)
  [i18n] Report translation coverage during integrate (elastic#264124)
  [api-docs] 2026-05-05 Daily api_docs build (elastic#267639)
  [Scout] Update test config manifests (elastic#267636)
  [content list] Add saved object provider services (elastic#266428)
  [Fleet] Otel UI add health and implement it in OTelComponentDetail (elastic#267292)
  Update dependency msw to v2.13.4 (main) (elastic#266770)
  ...
kibanamachine added a commit that referenced this pull request May 5, 2026
…les (#265978) (#267652)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[CI] Speed up telemetry_check by pre-filtering to collector files
(#265978)](#265978)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2026-05-05T07:14:21Z","message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a","branchLabelMapping":{"^v9.5.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","Team:actionable-obs","author:actionable-obs","ci:use-selective-testing","v9.5.0"],"title":"[CI]
Speed up telemetry_check by pre-filtering to collector
files","number":265978,"url":"https://github.com/elastic/kibana/pull/265978","mergeCommit":{"message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.5.0","branchLabelMappingKey":"^v9.5.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/265978","number":265978,"mergeCommit":{"message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
Co-authored-by: Ahmad Bamieh <ahmad.bamyeh@elastic.co>
kibanamachine added a commit that referenced this pull request May 5, 2026
…es (#265978) (#267654)

# Backport

This will backport the following commits from `main` to `9.3`:
- [[CI] Speed up telemetry_check by pre-filtering to collector files
(#265978)](#265978)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2026-05-05T07:14:21Z","message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a","branchLabelMapping":{"^v9.5.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","Team:actionable-obs","author:actionable-obs","ci:use-selective-testing","v9.5.0"],"title":"[CI]
Speed up telemetry_check by pre-filtering to collector
files","number":265978,"url":"https://github.com/elastic/kibana/pull/265978","mergeCommit":{"message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.5.0","branchLabelMappingKey":"^v9.5.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/265978","number":265978,"mergeCommit":{"message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
Co-authored-by: Ahmad Bamieh <ahmad.bamyeh@elastic.co>
kibanamachine added a commit that referenced this pull request May 5, 2026
…es (#265978) (#267653)

# Backport

This will backport the following commits from `main` to `9.2`:
- [[CI] Speed up telemetry_check by pre-filtering to collector files
(#265978)](#265978)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2026-05-05T07:14:21Z","message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a","branchLabelMapping":{"^v9.5.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","Team:actionable-obs","author:actionable-obs","ci:use-selective-testing","v9.5.0"],"title":"[CI]
Speed up telemetry_check by pre-filtering to collector
files","number":265978,"url":"https://github.com/elastic/kibana/pull/265978","mergeCommit":{"message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.5.0","branchLabelMappingKey":"^v9.5.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/265978","number":265978,"mergeCommit":{"message":"[CI]
Speed up telemetry_check by pre-filtering to collector files
(#265978)\n\n## Summary\n\nThe `telemetry.sh` quick check takes **~8m
45s** in CI — the single\nslowest check in the `quick_checks` step. It
also runs in the serial\n`mayChangeFiles` queue, blocking all other
serial checks behind it.\n\n### The problem\n\n`extractCollectors()`
passes **all ~36K TS files** from each of the 10\ntelemetry roots into
`ts.createProgram()`, even though only **~69\nfiles** across the entire
repo actually contain `makeUsageCollector` or\n`makeStatsCollector`
calls.\n\nTypeScript parses and type-checks thousands of unrelated
source files\nthat will never yield a collector.\n\n### The
fix\n\nPre-filter files with a simple regex scan on file contents
before\nfeeding them to the TS compiler:\n\n```ts\nconst collectorPaths
= fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p,
'utf-8')));\n```\n\nTypeScript still resolves all transitive imports
needed for\ntype-checking the collector files, but avoids parsing
thousands of\nunrelated files.\n\n### Benchmark results
(local)\n\n**`src/platform/` root** (largest OSS root):\n\n| Approach |
Root files | Source files TS loads | Time |\n|---|---|---|---|\n|
Current (all files) | 8,852 | 17,279 | 48s |\n| New (collector files
only) | 30 | 4,814 | 15s |\n| **Speedup** | | **3.6x fewer** | **3.1x
faster** |\n\n**`x-pack/platform/` root** (largest x-pack root):\n\n|
Approach | Root files | Source files TS loads | Time
|\n|---|---|---|---|\n| Current (all files) | 15,344 | 25,002 | 71s |\n|
New (collector files only) | 27 | 13,835 | 49s |\n| **Speedup** | |
**1.8x fewer** | **1.5x faster** |\n\n**CI estimate**: `telemetry.sh`
should drop from **~8m 45s to ~3-4\nmin**.\n\n### How it was tested\n\n-
Profiled `createKibanaProgram` locally with the actual Kibana\ntelemetry
roots\n- Verified the same collector files are found and processed\n-
The pre-filter is conservative — any file mentioning the
collector\nfunction names is included\n\n\nMade with
[Cursor](https://cursor.com)\n\nCo-authored-by: Ahmad Bamieh
<ahmad.bamyeh@elastic.co>","sha":"b3cb3c89a91ae1ee18b0d7d10c98a1ceb903e82a"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
Co-authored-by: Ahmad Bamieh <ahmad.bamyeh@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author:actionable-obs PRs authored by the actionable obs team backport:all-open Backport to all branches that could still receive a release ci:use-selective-testing Turns on selective testing features for the PR CI run release_note:skip Skip the PR/issue when compiling release notes Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. v8.19.16 v9.2.9 v9.3.5 v9.4.0 v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants