You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Introduce bash based metrics
* Fix/test duration metrics test
* Standardize on Ruby yaml format
* Shellcheck metrics file
* Re-use bash YAML file in Ruby
* Capture problems with build report file
If the env var is missing or the file does not exist, print that information.
* Add docs to bin/report
* Stricter bash
* Capture manually installing JVM
* Capture known stack failures
* Add failure reasons for compile_buildpack_v2
* Capture if `which java` is detected
* Move metrics into main bash functions file
Simplifies calling metrics functions inside of bash functions, and it's relatively small.
* Namespace env var
* Capture boostrap failure
* Fix Shellcheck
```
Run shellcheck bin/support/bash_functions.sh bin/support/download_ruby -x &&
In bin/support/bash_functions.sh line 234:
local timestamp=$(date +%s%3N 2>/dev/null)
^-------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In bin/support/bash_functions.sh line 243:
local seconds=$(date +%s)
^-----^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In bin/support/bash_functions.sh line 244:
local nanoseconds=$(date +%N 2>/dev/null || echo "000000000")
^---------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
```
* Changelog
* Fix missing export
```
+remote: Updated 2 paths from 60b426a
+remote: Compressing source files... done.
+remote: Building source:
+remote:
+remote: -----> Building on the Heroku-24 stack
+remote: -----> Using buildpack: https://github.com/heroku/heroku-buildpack-ruby#schneems/bash-metrics-initial
+remote: -----> Ruby app detected
+remote: /tmp/codon/tmp/buildpacks/bc6628ed5814e6d8925d4527655dd8e7dda421f4/bin/support/ruby_compile:14:in `fetch': key not found: "HEROKU_RUBY_BUILD_REPORT_FILE" (KeyError)
+remote: from /tmp/codon/tmp/buildpacks/bc6628ed5814e6d8925d4527655dd8e7dda421f4/bin/support/ruby_compile:14:in `<main>'
+remote: ! Push rejected, failed to compile Ruby app.
+remote:
+remote: ! Push failed
+remote: Verifying deploy...
+remote:
+remote: ! Push rejected to hatchet-t-90251d64ed.
+remote:
+To https://git.heroku.com/hatchet-t-90251d64ed.git
+ ! [remote rejected] HEAD -> main (pre-receive hook declined)
+error: failed to push some refs to 'https://git.heroku.com/hatchet-t-90251d64ed.git'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.4/lib/rspec/support.rb:110:in `block in <module:Support>'
```
* Fix shellcheck
```
In bin/compile line 12:
BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)
^-----------^ SC2034 (warning): BUILDPACK_DIR appears unused. Verify use (or export if used externally).
In bin/test line 9:
BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)
^-----------^ SC2034 (warning): BUILDPACK_DIR appears unused. Verify use (or export if used externally).
In bin/test line 15:
metrics::init "${CACHE_DIR}"
^----------^ SC2153 (info): Possible misspelling: CACHE_DIR may not be assigned. Did you mean cache_dir?
In bin/test-compile line 12:
BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)
^-----------^ SC2034 (warning): BUILDPACK_DIR appears unused. Verify use (or export if used externally).
For more information:
https://www.shellcheck.net/wiki/SC2034 -- BUILDPACK_DIR appears unused. Ver...
https://www.shellcheck.net/wiki/SC2153 -- Possible misspelling: CACHE_DIR m...
```
* Add and fix shellcheck for bin/report
* Fix docs
* Fix spec
The file now relies on importing bash functions which weren't being copied. This fixes the error.
* bin/test has no cache dir
```
$ bin/test BUILD_DIR ENV_DIR
```
https://devcenter.heroku.com/articles/testpack-api
* Use JSON for bash metrics
The python buildpack was modified to use JSON instead of YAML as it's easier to use `jq` to format and handle issues such as escaping.
This preserves the same API, but changes the format and adopts the strategy from heroku/heroku-buildpack-python#1878.
* Update Ruby build report to use json output
Previously the bash build output helpers were adjusted to emit json. This wires up the Ruby metrics code to be compatible with that change.
* Apply suggestions from code review
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Signed-off-by: Richard Schneeman <richard.schneeman+no-recruiters@gmail.com>
* Use EPOCHREALTIME
Inspired by heroku/heroku-buildpack-python#1881. This works locally and on Heroku. It works in bash, but not zsh by default (have to `zmodload zsh/datetime` to get it to work). We're explicitly using bash in these scripts.
* metrics:: prefix to build_data:: prefix
Metrics implies numeric data. While we derive numeric data by counting the outputs, it contains other values and has other uses. `build_data` is an accurate representation of the domain.
* Update bash docs
Switched from emitting YMAL to emitting JSON.
* Change metric name
Address feedback from https://github.com/heroku/heroku-buildpack-ruby/pull/1635/files#r2293428233
> (optional) If I were looking through a Ruby event in Honeycomb (eg if I were paged in the night) and saw a field named which_java I might struggle to understand what it meant. My first guess is that the values for such a key would be the path to the Java being used or similar, rather than a bool. Is there another name that might be clearer here and less coupled to the Bash function names?
Switching away from boolean and to a string field with two values either `ruby_buildpack` or `previously_installed`
* Delete removed function
* Remove error handling from printing
Comment https://github.com/heroku/heroku-buildpack-ruby/pull/1635/files#r2293616228
```
I'm not too sure about this error handling implementation.
If the env var isn't set, it's a buildpack bug, and with the :-'(unset) fallback removed that bug would correctly be caught by bash error on undefined env vars (which which file enables). As-is, this fallback masks the issue and causes bin/report to exit zero when it actually hit an internal error case.
Also, if the report file is missing, that's also an internal buildpack bug (and not a user facing error case).
Currently cytokine logs an error if a buildpack has a bin/report and it exits 1 (having set a minimal build report), which I think might be a better way to catch these cases? If we did still want to customise the report in this scenario, implementing it in cytokine (rather than each buildpack) would allow standardising across buildpacks more easily.
```
Adds in a check for when the exported env var HEROKU_RUBY_BUILD_REPORT_FILE is mutated to error.
* print -> print_bin_report_json
Align API with python
https://github.com/heroku/heroku-buildpack-python/blob/30086f2e8da2bf50d1b669b2e9ca82d479bf0892/lib/build_data.sh
* Update docs
* Use /dev/null in unsupported bin/ executables
The bin/report script does not work on bin/test-compile or bin/test. We don't want to hint that data can be collected about usage in those cases. The shared code still calls `build_data::kv` functions so those need to not error. Setting to `/dev/null` allows these calls to work without error even if no data is being collected.
* Update docs
* Update shellcheck CI call
So we don't forget any files by mistake
heroku#1635 (comment)
* Fix test
We have another test for when the variables differ, this test is supposed to show using a bad file raises an error.
Fixes this failure
1) Bash functions metrics prints error when report env var is set to a non-existent file
Failure/Error: expect(out).to include("No such file or directory")
expected "Error: HEROKU_RUBY_BUILD_REPORT_FILE does not match BUILD_DATA_FILE\nHEROKU_RUBY_BUILD_REPORT_FILE: /dev/null\nBUILD_DATA_FILE: /var/folders/yr/yytf3z3n3q336f1tj2b2j0gw0000gn/T/d20250822-87942-cz2rfj/does-not-exist\n" to include "No such file or directory"
Diff:
@@ -1 +1,3 @@
-No such file or directory
+Error: HEROKU_RUBY_BUILD_REPORT_FILE does not match BUILD_DATA_FILE
+HEROKU_RUBY_BUILD_REPORT_FILE: /dev/null
+BUILD_DATA_FILE: /var/folders/yr/yytf3z3n3q336f1tj2b2j0gw0000gn/T/d20250822-87942-cz2rfj/does-not-exist
# /Users/rschneeman/.gem/ruby/3.3.9/gems/rspec-support-3.13.4/lib/rspec/support.rb:110:in `block in <module:Support>'
# /Users/rschneeman/.gem/ruby/3.3.9/gems/rspec-support-3.13.4/lib/rspec/support.rb:119:in `notify_failure'
* Prefer bash if/else
Mentioned in heroku#1635 (comment) the `|| {}` style of bash error handling was not behaving as expected.
* Fix missing error output
Before
```
-----> Downloading Buildpack: heroku/jvm
```
After
```
-----> Downloading Buildpack: heroku/jvm
curl: (22) The requested URL returned error: 403
Failed to download https://buildpack-registry.s3.us-east-1.amazonaws.com/buildpacks/heroku/oops.tgz
```
* Prefer quiet commands to routing to dev/null
- tar: Remove verbose `v`
- git clone: Add --quiet
* Track loading bad json results in metric
When deserializing a prior json input fails, capture that status. This doesn't technically
* Apply suggestions from code review
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Signed-off-by: Richard Schneeman <richard.schneeman+no-recruiters@gmail.com>
* Add .rb suffix to ruby executables
This provides a more robust grep for the shellcheck exclude.
heroku#1635 (comment)
* Fix Error
Calling `build_data::init "/dev/null" does not actually allow `build_data::kv_*` calls as it behaves differently than the test. It sets the data file to `/dev/null/build-data/ruby.json` which doesn't exist so those calls fail.
The default of that file is already `/dev/null` we can use that instead.
heroku#1635 (comment)
* Use null termination for xargs inputs
The shellcheck command now uses git ls-files -z to output null-separated file paths, which requires xargs -0 to properly handle filenames containing spaces or special characters. Without the -0 flag, xargs treats newlines as separators and may incorrectly parse complex file paths, leading to unreliable behavior when processing the file list.
Added a link to docs that mention the exclude syntax
> After a path matches any non-exclude pathspec, it will be run through all exclude pathspecs (magic signature: ! or its synonym ^). If it matches, the path is ignored. When there is no non-exclude pathspec, the exclusion is applied to the result set as if invoked without any pathspec.
* Use verbose `git ls-files` exclude syntax
> "In the long form, the leading colon : is followed by an open parenthesis (, a comma-separated list of zero or more "magic words", and a close parentheses ), and the remainder is the pattern to match against the path."
It's not clear looking at the docs but the header itself qualifies as a "magic word"
```
exclude
After a path matches any non-exclude pathspec, it will be run through all exclude pathspecs (magic signature: ! or its synonym ^). If it matches, the path is ignored. When there is no non-exclude pathspec, the exclusion is applied to the result set as if invoked without any pathspec.
```
This allows us to use `(exclude)` as syntax here. heroku#1635 (comment)
---------
Signed-off-by: Richard Schneeman <richard.schneeman+no-recruiters@gmail.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
3
3
## [Unreleased]
4
4
5
+
- Add bash based failure metrics reporting for `bin/report`. This allows the buildpack to distinguish beteween types of failures that occur before Ruby code in the buildpack has executed (such as when bootstrapping). (https://github.com/heroku/heroku-buildpack-ruby/pull/1635)
0 commit comments