Skip to content

RFE-5434: Add cluster ID and timestamp to must-gather directory name#2252

Open
asadawar wants to merge 2 commits intoopenshift:mainfrom
asadawar:rfe-5434-must-gather-dir-naming
Open

RFE-5434: Add cluster ID and timestamp to must-gather directory name#2252
asadawar wants to merge 2 commits intoopenshift:mainfrom
asadawar:rfe-5434-must-gather-dir-naming

Conversation

@asadawar
Copy link
Copy Markdown

@asadawar asadawar commented Apr 13, 2026

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

Summary by CodeRabbit

  • New Features

    • Enhanced must-gather destination naming to include a cluster identifier suffix (when available), a UTC timestamp, and a random suffix for clearer artifact organization and traceability.
    • Retains a fallback naming format when cluster metadata is unavailable.
  • Tests

    • Added tests validating new naming semantics, timestamp format, and behavior when no cluster metadata/client is present.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 13, 2026
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 13, 2026

@asadawar: This pull request references RFE-5434 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature request to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 13, 2026

Warning

Rate limit exceeded

@asadawar has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 22 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 22 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 3af9c820-daf8-49b9-8fb5-592e969071fc

📥 Commits

Reviewing files that changed from the base of the PR and between 67a47be and 9a50bdb.

📒 Files selected for processing (2)
  • pkg/cli/admin/mustgather/mustgather.go
  • pkg/cli/admin/mustgather/mustgather_test.go

Walkthrough

Default must-gather output directory naming changed: when unset, DestDir is now generated by a new generateDestDir() method that includes a UTC timestamp and, when available, a cluster-id suffix (last 12 chars of cluster ID); if unavailable, the suffix is omitted.

Changes

Cohort / File(s) Summary
Must-Gather Default Directory Generation
pkg/cli/admin/mustgather/mustgather.go
Added (*MustGatherOptions) generateDestDir() and updated Complete to call it when DestDir is empty. New default formats: must-gather.local.<cluster-id-suffix>.<timestamp>.<rand> (uses last 12 chars of cluster ID and UTC timestamp 20060102T150405Z) or fallback must-gather.local.<timestamp>.<rand> when cluster ID unavailable. Updated example text accordingly.
Must-Gather Tests
pkg/cli/admin/mustgather/mustgather_test.go
Added TestGenerateDestDir and TestGenerateDestDirNoConfigClient to assert generated names begin with must-gather.local., conditionally include the cluster-id suffix, contain a UTC timestamp in YYYYMMDDTHHMMSSZ form, and end with a trailing numeric random segment. Added regexp and strings imports for assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 8 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Structure And Quality ❓ Inconclusive The test file specified in the PR summary could not be located in the repository. Verify that the repository has the correct PR changes applied or provide access to the test file contents to evaluate test quality.
✅ Passed checks (8 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding cluster ID and timestamp to the must-gather directory name, which aligns with the implementation details in the changeset.
Stable And Deterministic Test Names ✅ Passed All test names and sub-test titles use static, descriptive strings without dynamic information such as timestamps, random identifiers, or pod/node names.
Microshift Test Compatibility ✅ Passed The PR adds standard Go unit tests, not Ginkgo e2e tests, so it falls outside the scope of the MicroShift compatibility check.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests were added in this PR. The changes only include standard Go unit tests using the testing package.
Topology-Aware Scheduling Compatibility ✅ Passed Pull request modifies only CLI must-gather tool for directory naming; no deployment manifests, operator code, or scheduling constraints introduced.
Ote Binary Stdout Contract ✅ Passed The pull request introduces generateDestDir() method and unit tests without violating the OTE Binary Stdout Contract; new code uses only fmt.Sprintf() for string formatting and contains no direct stdout writes or process-level code violations.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The PR adds two standard Go unit tests that validate the generateDestDir() function's string generation logic without involving Ginkgo e2e tests, networking, or IPv4 assumptions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot requested review from ingvagabund and tchap April 13, 2026 10:53
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 13, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: asadawar
Once this PR has been reviewed and has the lgtm label, please assign atiratree for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 13, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 13, 2026

Hi @asadawar. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/cli/admin/mustgather/mustgather.go`:
- Around line 277-279: generateDestDir() currently calls
o.ConfigClient.ConfigV1().ClusterVersions().Get with context.TODO(), which can
block startup on slow/unreachable API servers; replace the context.TODO() with a
short timeout context (e.g., using context.WithTimeout) and defer cancel so the
lookup is bounded, then use that ctx when calling
ConfigV1().ClusterVersions().Get; target the call site referencing
o.ConfigClient, ConfigV1(), ClusterVersions().Get and ensure errors from context
deadline are handled the same as other lookup failures so the fallback path
still executes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: b20ea37c-8b72-4cbd-a950-65a1fbfb2bad

📥 Commits

Reviewing files that changed from the base of the PR and between 66dee73 and 7785cf8.

📒 Files selected for processing (2)
  • pkg/cli/admin/mustgather/mustgather.go
  • pkg/cli/admin/mustgather/mustgather_test.go

Comment thread pkg/cli/admin/mustgather/mustgather.go
@asadawar asadawar force-pushed the rfe-5434-must-gather-dir-naming branch from 1c1f293 to 7785cf8 Compare April 13, 2026 11:19
@tchap
Copy link
Copy Markdown
Contributor

tchap commented Apr 13, 2026

Wouldn't it be nicer to use must-gather.local.<cluster-id-suffix>.<timestamp>.<rand> ? Like this it would be sorted when listing by name according to cluster, timestamp.

@asadawar asadawar force-pushed the rfe-5434-must-gather-dir-naming branch from 7785cf8 to 7396e5b Compare April 13, 2026 13:10
@asadawar
Copy link
Copy Markdown
Author

Good point, reordered to must-gather.local.<cluster-id-suffix>.<timestamp>.<rand> so that ls groups by cluster and sorts chronologically. Updated.

@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 13, 2026

@asadawar: This pull request references RFE-5434 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature request to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

Summary by CodeRabbit

Release Notes

  • New Features
  • Enhanced must-gather directory naming to include cluster identifier and timestamp information for improved artifact organization and traceability.
  • Added fallback naming mechanism when cluster metadata is unavailable.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@asadawar asadawar force-pushed the rfe-5434-must-gather-dir-naming branch from 7396e5b to 67a47be Compare April 14, 2026 14:41
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 14, 2026

@asadawar: This pull request references RFE-5434 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature request to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

Summary by CodeRabbit

  • New Features

  • Enhanced must-gather destination naming to include a cluster identifier suffix (when available), a UTC timestamp, and a random suffix for clearer artifact organization and traceability.

  • Retains a fallback naming format when cluster metadata is unavailable.

  • Tests

  • Added tests validating new naming semantics, timestamp format, and behavior when no cluster metadata/client is present.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

// times. If the cluster ID cannot be retrieved (e.g. cluster is unreachable), it falls back
// to the timestamp and random ID only.
// See: https://issues.redhat.com/browse/RFE-5434
func (o *MustGatherOptions) generateDestDir(ctx context.Context) string {
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.

Honestly would be nicer to pass a clock.Clock interface so that the tests are deterministic. And then align the tests to check for exact names instead of just contains.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good suggestion, done. Added a clock.PassiveClock field to MustGatherOptions — that's a smaller interface from k8s.io/utils/clock that only requires Now() and Since(), which is all we need here (the full Clock interface includes timers that we don't use).

In production, it's initialized with clock.RealClock{} in NewMustGatherOptions(), so it calls the real time.Now(). In tests, I created a simple fakeClock struct that returns a fixed time (2026-04-14T12:00:00Z), which lets us assert exact prefixes like must-gather.local.76708af6b91c.20260414T120000Z. instead of regex patterns.

The random suffix from rand.Int63() is still non-deterministic, but that's fine — the important parts (cluster ID and timestamp) are now fully testable.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/cli/admin/mustgather/mustgather.go`:
- Around line 76-77: Update the example text in the must-gather help/usage block
(the comment containing "# Gather information..." and the example line "oc adm
must-gather") to explicitly show that the `<cluster-id-suffix>` is optional —
state that the default output directory is
`must-gather.local.<cluster-id-suffix>.<timestamp>.<rand>` but when a cluster ID
is unavailable the suffix is omitted producing
`must-gather.local.<timestamp>.<rand>`, and adjust the example line or add a
second example to demonstrate the fallback form without `<cluster-id-suffix>`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 8609b9a3-7893-43d3-83a6-26b82ef7ddbe

📥 Commits

Reviewing files that changed from the base of the PR and between 7396e5b and 67a47be.

📒 Files selected for processing (2)
  • pkg/cli/admin/mustgather/mustgather.go
  • pkg/cli/admin/mustgather/mustgather_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/cli/admin/mustgather/mustgather_test.go

Comment thread pkg/cli/admin/mustgather/mustgather.go Outdated
Include the last 12 characters of the cluster ID and a UTC timestamp
in the auto-generated must-gather destination directory name. This helps
support engineers distinguish must-gather archives from different clusters
and collection times, especially when customers upload multiple archives
to the same support case.

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example:    must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

If the cluster ID cannot be retrieved (e.g. cluster is unreachable),
the directory name falls back to: must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434
@asadawar asadawar force-pushed the rfe-5434-must-gather-dir-naming branch from 67a47be to dda7aec Compare April 14, 2026 15:07
The example text now mentions both the format with cluster ID suffix
and the fallback format without it, so users know what to expect when
the cluster ID is unavailable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants