Skip to content

Adding gitOpsModeEnabled and gitOpsModeExceptions to anonymous statistics payload - #44161

Merged
lucasmrod merged 4 commits into
mainfrom
42240-add-gitops-stats
Apr 27, 2026
Merged

Adding gitOpsModeEnabled and gitOpsModeExceptions to anonymous statistics payload#44161
lucasmrod merged 4 commits into
mainfrom
42240-add-gitops-stats

Conversation

@lucasmrod

@lucasmrod lucasmrod commented Apr 24, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #42240.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • New Features

    • Statistics now include GitOps mode: whether it’s enabled and the ordered list of configured exception categories (serializes as an empty list when none).
  • Tests

    • Added tests for GitOps-related statistics transitions and made statistics-timing tests deterministic for reliable behavior.

Copilot AI review requested due to automatic review settings April 24, 2026 20:32
@lucasmrod
lucasmrod requested a review from a team as a code owner April 24, 2026 20:32

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@lucasmrod lucasmrod changed the title Adding gitOpsModeEnabled and gitOpsModeExceptions to anonymous statistics payload Adding gitOpsModeEnabled and gitOpsModeExceptions to anonymous statistics payload Apr 24, 2026
@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e5ca14a8-2c56-4d2e-a568-451c89375b72

📥 Commits

Reviewing files that changed from the base of the PR and between 4e9fe65 and 9f504e7.

📒 Files selected for processing (1)
  • cmd/fleet/serve_test.go
✅ Files skipped from review due to trivial changes (1)
  • cmd/fleet/serve_test.go

Walkthrough

Adds two GitOps-related fields to the anonymous usage statistics payload: gitOpsModeEnabled (bool) and gitOpsModeExceptions (string array). The values are populated from the application config; a new unexported helper returns a stable-order, non-nil exceptions slice (empty slice when no exceptions). Tests were added/updated to verify GitOps enable/disable transitions and exceptions behavior, and statistics timestamp handling was made deterministic. computeStats error handling was tightened to treat any non-nil error from amountPolicyViolationDaysDB (except sql.ErrNoRows) as a failure.

Possibly related PRs

  • fleetdm/fleet PR 42013: Introduced GitOps exceptions and related config/migration types that this change reads and serializes into the statistics payload.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title directly and specifically describes the main change: adding two fields (gitOpsModeEnabled and gitOpsModeExceptions) to the anonymous statistics payload, which matches the core objective of the changeset.
Description check ✅ Passed The PR description addresses the related issue (#42240), confirms that a changes file was added, and documents that automated tests were added/updated and manual QA was completed, covering the key checklist items from the template.
Linked Issues check ✅ Passed The code changes successfully implement the objectives from issue #42240: adding gitOpsModeEnabled and gitOpsModeExceptions fields to the statistics payload [42240], with comprehensive test coverage including GitOps mode transitions and exception handling [42240].
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: new statistics fields in the payload struct, helper function for exception list generation, test coverage, and a changes file entry. No unrelated modifications to UI, API endpoints, schema, or other systems are present.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 42240-add-gitops-stats

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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
server/datastore/mysql/statistics_test.go (1)

105-108: Fragile expectation coupled to migration-dumped defaults.

Asserting ["labels", "secrets"] here depends on migration 20260323144117_AddGitOpsExceptionsToAppConfig being baked into the dumped test schema. A future migration that changes existing-install defaults will silently require this test to be updated. The inline comment documents the dependency, which is good; consider additionally computing the expected slice from the loaded AppConfig.GitOpsConfig.Exceptions to make the test resilient to default changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/datastore/mysql/statistics_test.go` around lines 105 - 108, The test
currently asserts a hard-coded expectation on stats.GitOpsModeExceptions
(["labels","secrets"]) which is fragile; instead load the app config's default
exceptions and compare against that dynamic value. Replace the hard-coded
assertion with one that reads the expected slice from the loaded AppConfig
(AppConfig.GitOpsConfig.Exceptions) and assert.Equal(t, expectedExceptions,
stats.GitOpsModeExceptions), keeping the existing assertion that
stats.GitOpsModeEnabled is false; reference the test's stats variable and the
AppConfig.GitOpsConfig.Exceptions field when making the change.
server/datastore/mysql/statistics.go (1)

340-354: Helper correctly produces a stable, non-nil slice.

Order matches the field declaration order in fleet.GitOpsExceptions and the capacity hint of 3 is accurate. Returning make([]string, 0, 3) ensures JSON serializes as [] when empty, which matches the intended contract documented on StatisticsPayload.GitOpsModeExceptions.

Optional: this helper could live as a method on fleet.GitOpsExceptions in server/fleet/app.go for cohesion/reuse, but current placement is fine since it's only consumed here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/datastore/mysql/statistics.go` around lines 340 - 354, No change
required: the gitOpsExceptionsList helper correctly returns a stable, non-nil
slice for fleet.GitOpsExceptions and matches
StatisticsPayload.GitOpsModeExceptions' contract; if you prefer to refactor for
cohesion, move this function to a method on fleet.GitOpsExceptions (e.g., func
(e fleet.GitOpsExceptions) List() []string) in server/fleet/app.go and update
callers to use that method, otherwise leave gitOpsExceptionsList as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/datastore/mysql/statistics_test.go`:
- Around line 105-108: The test currently asserts a hard-coded expectation on
stats.GitOpsModeExceptions (["labels","secrets"]) which is fragile; instead load
the app config's default exceptions and compare against that dynamic value.
Replace the hard-coded assertion with one that reads the expected slice from the
loaded AppConfig (AppConfig.GitOpsConfig.Exceptions) and assert.Equal(t,
expectedExceptions, stats.GitOpsModeExceptions), keeping the existing assertion
that stats.GitOpsModeEnabled is false; reference the test's stats variable and
the AppConfig.GitOpsConfig.Exceptions field when making the change.

In `@server/datastore/mysql/statistics.go`:
- Around line 340-354: No change required: the gitOpsExceptionsList helper
correctly returns a stable, non-nil slice for fleet.GitOpsExceptions and matches
StatisticsPayload.GitOpsModeExceptions' contract; if you prefer to refactor for
cohesion, move this function to a method on fleet.GitOpsExceptions (e.g., func
(e fleet.GitOpsExceptions) List() []string) in server/fleet/app.go and update
callers to use that method, otherwise leave gitOpsExceptionsList as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb2c6655-b4fe-4709-9e1e-496c6bd8e53a

📥 Commits

Reviewing files that changed from the base of the PR and between f5560f6 and 282e0cb.

📒 Files selected for processing (4)
  • changes/42240-add-gitops-stats
  • server/datastore/mysql/statistics.go
  • server/datastore/mysql/statistics_test.go
  • server/fleet/statistics.go

Copilot AI 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.

Pull request overview

Adds GitOps mode status and configured exception sub-options to Fleet’s anonymous usage analytics payload, enabling product analytics to measure adoption of GitOps mode and its exception settings.

Changes:

  • Extended fleet.StatisticsPayload with gitOpsModeEnabled and gitOpsModeExceptions.
  • Populated the new fields from AppConfig.GitOpsConfig in MySQL statistics computation.
  • Added automated datastore tests covering default, enabled/disabled, and empty-exception scenarios, plus a changes note.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
server/fleet/statistics.go Adds new GitOps fields to the anonymous statistics payload struct.
server/datastore/mysql/statistics.go Computes/sends GitOps mode enabled + exceptions list (stable ordering, non-nil slice).
server/datastore/mysql/statistics_test.go Adds coverage for GitOps stats across default/modified app config states.
changes/42240-add-gitops-stats Release note entry for the new analytics fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/datastore/mysql/statistics.go
Comment thread server/datastore/mysql/statistics_test.go Outdated
@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.78%. Comparing base (c1b5b62) to head (9f504e7).
⚠️ Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
server/datastore/mysql/statistics.go 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #44161      +/-   ##
==========================================
+ Coverage   66.76%   66.78%   +0.01%     
==========================================
  Files        2629     2627       -2     
  Lines      211215   211157      -58     
  Branches     9421     9421              
==========================================
- Hits       141027   141021       -6     
+ Misses      57361    57317      -44     
+ Partials    12827    12819       -8     
Flag Coverage Δ
backend 68.56% <91.66%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lucasmrod
lucasmrod merged commit bd18bac into main Apr 27, 2026
48 checks passed
@lucasmrod
lucasmrod deleted the 42240-add-gitops-stats branch April 27, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capture GitOps mode and exception sub-options in usage analytics

3 participants