Skip to content

fix: EXC-1781: fix a metric for counting actually executed canisters per round - #1596

Merged
maksymar merged 6 commits into
masterfrom
maksym/executed_canisters_metrics
Sep 20, 2024
Merged

maksymar merged 6 commits into
masterfrom
maksym/executed_canisters_metrics

Conversation

@maksymar

@maksymar maksymar commented Sep 20, 2024 •

Copy link
Copy Markdown
Contributor

This PR improves the tracking of executed canisters during a round by refining the counting logic and switching the associated metric to a histogram.

  • The previous implementation used a variable called executed_canisters, which represented the number of canisters initially planned for execution. However, not all planned canisters were necessarily executed due to round instruction limit. This has been renamed to active_canisters to clarify its meaning. The function now also returns the IDs of the canisters that were actually executed before any instruction limits were reached.

  • The metric scheduler_executed_canisters_per_round is switched from a gauge to a histogram. Gauges led to data loss as scraping occurred every 10-20 seconds, missing changes between scrapes. A histogram stores the data in buckets, preserving information for accurate calculations. The average can be computed using hist_stats.sum / hist_stats.count.

@github-actions github-actions Bot added the fix label Sep 20, 2024
@maksymar maksymar changed the title fix: fix counting actually executed canisters fix: fix a metric for counting actually executed canisters per round Sep 20, 2024
@maksymar
maksymar marked this pull request as ready for review September 20, 2024 12:53
@maksymar
maksymar requested a review from a team as a code owner September 20, 2024 12:53

@alin-at-dfinity alin-at-dfinity left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's rather unfortunate that we have to collect canister IDs into a set. If we were collecting this metric per inner loop, that would be unnecessary.

@maksymar
maksymar enabled auto-merge September 20, 2024 13:43
@maksymar
maksymar added this pull request to the merge queue Sep 20, 2024
Merged via the queue into master with commit b383408 Sep 20, 2024
@maksymar
maksymar deleted the maksym/executed_canisters_metrics branch September 20, 2024 14:36
@berestovskyy berestovskyy changed the title fix: fix a metric for counting actually executed canisters per round fix: EXC-1781: fix a metric for counting actually executed canisters per round Nov 4, 2024
AleDema pushed a commit to AleDema/ic that referenced this pull request Nov 18, 2026
…#12159)

Upgrades `rules_foreign_cc` from 0.15.2 to
[0.17.0](https://github.com/bazel-contrib/rules_foreign_cc/releases/tag/0.17.0),
its latest release. 0.15.2 was never released: the `bazel_dep` only
resolved because an `archive_override` replaced it with the unreleased
commit
[f68b351c](bazel-contrib/rules_foreign_cc@f68b351)
(2026-06-27, between 0.15.1 and 0.16.0), pinned for its newer Meson.
0.17.0 contains that commit plus [28
more](bazel-contrib/rules_foreign_cc@f68b351...0.17.0),
so we're back on a BCR release.

The release artifacts don't change: the IC-OS images and the binary and
canister bundles are byte-identical to master's.

## Changes

- **`MODULE.bazel`**:
- `rules_foreign_cc` 0.15.2 → 0.17.0. The `archive_override` becomes a
`single_version_override` that applies our patch on top of BCR's source.
BCR's only patch for 0.17.0 sets the version in its `MODULE.bazel`. The
comment about using HEAD for a recent Meson is gone, since 0.17.0 ships
Meson 1.12.1 (f68b351c had 1.10.1). The new comment says what the patch
is for.
- 0.17.0 requires at least `bazel_skylib` 1.9.2 and `rules_shell` 0.8.0.
Master has `bazel_skylib` 1.9.2 and `rules_shell` 0.10.0 since dfinity#12150
and dfinity#12152. This PR carried the same two bumps, plus dfinity#12150's two
`allow_symlink = True` lines in `publish/canisters/BUILD.bazel`, which
skylib 1.9.2 needs; they dropped out of its diff when I merged master.
- The `register_toolchains` for the preinstalled `make` and `pkg-config`
are unchanged and still take precedence: the generated build scripts use
`MAKE=make` and `PKG_CONFIG=pkg-config`. Since 0.16.0, the make and
pkg-config that rules_foreign_cc builds by default come from the `make`
and `pkgconf` BCR modules, not from the bootstrap scripts
[dfinity#1313](bazel-contrib/rules_foreign_cc#1313)
is about. A new comment above them says why we register them, with a
TODO to drop the registrations if the module-built make and pkg-config
turn out to be reproducible. That check is left for a follow-up.
- **`bazel/rules_foreign_cc.patch`**: the content is unchanged. Only the
`index` line and the hunk position (715 → 748) are regenerated, so the
patch applies to 0.17.0 with no offset (the old patch applied with a
33-line offset). We still need it:
[dfinity#1313](bazel-contrib/rules_foreign_cc#1313)
is open, and 0.17.0's `wrap_outputs` still declares the build log as an
output and keeps it after a successful build. With the patch, the logs
of all seven foreign_cc targets are 1 byte (a newline).
- **`bazel/conf/.bazelrc.build`**: the comment on
`--incompatible_default_to_explicit_init_py` now names the `meson`
module's `py_binary` (`@@meson+//:meson`), which rules_foreign_cc 0.17.0
runs instead of a meson it builds itself. The flag still applies to it.
dfinity#12158 (rules_python 2.5.1), now in master, edited the same comment: it
dropped rules_python's `py_console_script_gen_py` from the list and
notes that rules_python opts out its own targets. The merge of master
keeps both edits.

## Module graph

Compared with master, `bazel mod graph` shows these changes besides
`rules_foreign_cc`:

- 0.17.0 adds six modules: `m4` 1.4.21.bcr.8, `make` 4.4.1.bcr.3,
`meson` 1.12.1, `ninja` 1.13.2, `pkgconf` 3.0.10, and
`rules_cc_autoconf` 0.32.0, which `m4`, `make` and `pkgconf` are built
with.
- `nlohmann_json` moves from 3.6.1 to 3.12.0.bcr.1, required by
`rules_cc_autoconf`. The only other module that depends on it is
`rules_swift`.
- `package_metadata` moves from 0.0.7 to 0.0.13, required by `m4` and
`make`.
- 0.17.0 requires at least `bazel_features` 1.47.1 and `bazel_lib`
3.2.0. We already resolve 1.50.0 and 3.2.2, so neither moves.

There are no new direct-dependency version warnings.

## Upstream changes that touch our setup

These are the relevant changes between f68b351c and 0.17.0.
[NEWS.md](https://github.com/bazel-contrib/rules_foreign_cc/blob/0.17.0/NEWS.md)
has the full list. All seven of our foreign_cc targets were built with
0.17.0, and I compared their generated build scripts with master's.

- **m4, make, ninja, meson and pkg-config now come from BCR modules by
default**
([dfinity#1582](bazel-contrib/rules_foreign_cc#1582),
[dfinity#1584](bazel-contrib/rules_foreign_cc#1584),
[dfinity#1596](bazel-contrib/rules_foreign_cc#1596)).
The build scripts differ from master's only in these tools:
- **m4**: previously the container's `m4`, found on `PATH`. Now it is m4
1.4.21, built from the `m4` module with our hermetic toolchain, exported
as `M4` and linked into `$EXT_BUILD_DEPS/bin` in every `configure_make`
action. Of our targets, only `@jemalloc//:jemalloc_private` runs
autoconf (`autoconf = True`). Its autoconf, still the container's, now
gets that m4 through `M4`. `libjemalloc.a` stays byte-identical.
- **meson** (libfuse only): previously 1.10.1, built by
rules_foreign_cc. Now it is the `py_binary` from the `meson` 1.12.1
module, wrapped in the new `meson_tool_toolchain`
([dfinity#1599](bazel-contrib/rules_foreign_cc#1599)).
That toolchain also exports `PYTHON3`, `MESON_REAL` and
`RULES_PYTHON_EXTRACT_ROOT`.
- **ninja** (libfuse only): previously the prebuilt 1.13.2 binary. Now
it is ninja 1.13.2, built from the `ninja` module.
- **make and pkg-config**: unchanged, because our preinstalled
registrations come first.
- **Build cost**: the first build of a `configure_make` target now also
builds m4, and `rules_cc_autoconf` runs m4's configure checks as
separate (cacheable) Bazel actions. In a fresh output base, building all
seven targets ran 1,463 actions locally; the other actions came from the
shared disk cache.
- **rules_foreign_cc no longer registers a Python toolchain for its
consumers**
([dfinity#1583](bazel-contrib/rules_foreign_cc#1583)).
Meson now runs on the Python 3.12 toolchain that our root module
registers (`PYTHON3` is `python_3_12_x86_64-unknown-linux-gnu`).
rules_foreign_cc's old registration was also for 3.12.
- **Foreign builds resolve their toolchains in a `foreign_cc` exec
group**
([dfinity#1604](bazel-contrib/rules_foreign_cc#1604)).
On Linux we have a single execution platform (`//:linux-glibc-2.31`),
and the tools still build in the same `linux-glibc-2.31-opt-exec`
configuration.
- **`PWD` is dropped from the C/C++ toolchain environment**
([dfinity#1606](bazel-contrib/rules_foreign_cc#1606)).
Our toolchain never put it there: no build script exports it, before or
after this change.

## Verification

All of these were run in the dev container. The module graph, analysis,
lint and release-artifact checks were run again on the latest commit,
along with the new canister and `py_binary` checks. The foreign_cc
builds and tests ran on the first commit; the later commits only change
`publish/canisters/BUILD.bazel` and comments. After dfinity#12150, dfinity#12152 and
dfinity#12158 landed, I merged master into this branch and re-ran `bazel mod
graph` (the changes above, and only the `rules_qemu` warning that master
also prints), `bazel build //... --nobuild` (all 3389 targets analyze)
and `bazel run //:buildifier` (no changes).

- `bazel mod graph`, master vs. this PR: the changes listed above. The
only warning is the existing `rules_qemu` `use_repo` one.
- `bazel build //... --nobuild`: all 3387 targets analyze, with no
`__init__.py` deprecation warnings.
- CI Linter parity: the eight `//pre-commit` checks pass, including
`buf-breaking-check`. The autofixes (`buildifier-fix`, `shfmt-fix`,
`ruff-fix`, `:rustfmt`, `:gazelle`) and `//:buildifier` leave the tree
clean.
- **Canister copies**: `bazel aquery
'mnemonic("Symlink|CopyFile|SymlinkFile", //publish/canisters:all)'`
finds 87 `Symlink` actions, and its output is identical to master's.
Without the two `allow_symlink` lines it finds 87 `CopyFile` actions.
The 20 `file_size_check` tests in `//publish/canisters` pass (cached
results).
- **Python executables of other modules**: `bazel cquery
'kind("py_binary", deps(//...))'` lists `@@meson+//:meson` and no
`py_binary` from a rules_foreign_cc repository.
- **Builds and tests**: all seven rules_foreign_cc targets in the repo
build, along with `//:mke2fs`, `//:fuse2fs` and `//:debugfs`. That is
five `configure_make` targets (e2fsprogs, dosfstools, mtools, openssl,
jemalloc), one `make` target (dnsmasq) and one `meson` target (libfuse).
These tests, which run the built `mkfs.fat` and `mcopy`, pass:
  - `//rs/ic_os/build_tools/partition_tools:partition_tools_test`
  - `//rs/ic_os/config/tool:config_lib_test`
  - `//rs/ic_os/config/tool:config_lib_test_dev`
  - `//rs/ic_os/os_tools/guest_vm_runner:guest_vm_runner_test`
- **Release artifacts**: these are byte-identical to master's (133
files), both on the first commit and on the latest one:
- the unstamped IC-OS bundles (GuestOS prod disk and update, GuestOS
recovery update, HostOS update, SetupOS)
  - `//publish/binaries:bundle`
  - `//publish/canisters:bundle`

e2fsprogs (with libfuse), dosfstools, mtools and jemalloc are in that
build graph and were built with 0.17.0 for this check.
- **The foreign_cc outputs themselves**: I hashed the outputs of all
seven targets (332 files) for master and for this PR, in one output
base. Master's outputs came from the caches; this PR's were built
locally. 331 files are identical, including `mke2fs`, `debugfs`,
`fuse2fs`, `libfuse3.a`, `libjemalloc.a`, `libssl.a`, `mkfs.fat`,
`mcopy` and `dnsmasq`.
- The one difference is openssl's `libcrypto.a`, which isn't
reproducible in the first place. Master's copy was built on a CI runner
and this PR's locally, at different times. Only four of its 961 objects
differ. `cversion.o` has the build time. All four (`cversion.o`,
`defaults.o`, `x509_def.o` and `ct_log.o`) have the absolute sandbox
path, which is compiled in through `OPENSSLDIR`, `ENGINESDIR` and
`MODULESDIR` (configure derives them from `--prefix`) and through the
clang path in the `compiler:` string. openssl isn't in the release
artifacts' build graph.

Not verified locally: macOS builds (openssl is built with
`configure_make` there too), the system tests (the only users of
dnsmasq), and the rest of the test suite. CI covers the full build and
test suite.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants