flipt icon indicating copy to clipboard operation
flipt copied to clipboard

feat: add comprehensive git sync metrics for v2

Open markphelps opened this issue 4 months ago • 2 comments

Summary

Implements comprehensive git synchronization metrics for Flipt v2, providing visibility into git-based flag synchronization operations.

Addresses: https://github.com/orgs/flipt-io/discussions/4556

New Metrics

This PR adds the following Prometheus metrics to track git sync operations:

Metric Type Description Labels
flipt_git_sync_total Counter Total sync operations remote, branch, status
flipt_git_sync_duration Histogram Sync operation latency (ms) remote, branch
flipt_git_sync_errors_total Counter Categorized sync errors remote, branch, error_type
flipt_git_files_changed_total Counter Files changed during sync remote, branch, operation

Error Types

  • auth - Authentication/authorization failures
  • network - Network/repository access issues
  • conflict - Merge conflicts or repository state issues
  • repository - Repository structure problems
  • unknown - Unrecognized errors

File Operations

  • added - New files created during sync
  • modified - Existing files changed during sync
  • deleted - Files removed during sync

Implementation Details

Core Changes

  • Enhanced repoMetrics struct with new sync-specific counters and histograms
  • Modified Fetch() method to track sync operations and detect file changes
  • Added categorizeError() function using go-git v6 error types with errors.Is()
  • Added trackSyncChanges() to analyze commit diffs and count file modifications

Key Features

  • Proper error categorization using go-git exported error types instead of string matching
  • Change detection that analyzes git tree diffs to track file modifications
  • Branch-aware metrics with branch and remote labels for environment tracking
  • Non-breaking implementation that extends existing metrics without disruption
  • Memory efficient using counters/histograms rather than problematic gauge metrics

Bonus Fix

Also fixes the mage formatting task to exclude all hidden directories (starting with .) instead of hardcoding specific ones like .git and .devenv. This prevents formatting issues with various hidden directories.

Example Usage

Users can now create Prometheus alerts and dashboards:

# Alert on sync failures
- alert: FliptSyncFailures
  expr: rate(flipt_git_sync_errors_total[5m]) > 0.1
  for: 5m
  annotations:
    summary: "High git sync failure rate for {{ $labels.remote }}/{{ $labels.branch }}"

# Alert on slow sync operations  
- alert: FliptSyncSlow
  expr: histogram_quantile(0.95, flipt_git_sync_duration) > 30000
  for: 5m
  annotations:
    summary: "Git sync operations are slow for {{ $labels.remote }}/{{ $labels.branch }}"

Test Plan

  • [x] Unit tests pass for new metrics functionality
  • [x] All existing git storage tests continue to pass
  • [x] Code compiles and builds successfully
  • [x] Mage formatting and linting pass
  • [ ] Manual testing with actual git repository sync operations
  • [ ] Verify metrics appear correctly in Prometheus/monitoring

Breaking Changes

None - this is an additive feature that extends the existing metrics system.

Documentation

The new metrics will be documented in the monitoring/observability documentation as part of the existing git storage metrics section.

markphelps avatar Aug 20 '25 15:08 markphelps

Codecov Report

:x: Patch coverage is 39.72603% with 88 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 60.32%. Comparing base (6c44f8f) to head (86630f1). :warning: Report is 267 commits behind head on v2.

Files with missing lines Patch % Lines
internal/storage/git/repository.go 11.11% 83 Missing and 5 partials :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##               v2    #4587      +/-   ##
==========================================
- Coverage   64.80%   60.32%   -4.48%     
==========================================
  Files         131      131              
  Lines       14776    14920     +144     
==========================================
- Hits         9576     9001     -575     
- Misses       4549     5276     +727     
+ Partials      651      643       -8     
Flag Coverage Δ
integrationtests 20.22% <11.64%> (-18.20%) :arrow_down:
unittests 54.39% <39.72%> (-0.12%) :arrow_down:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Aug 20 '25 15:08 codecov[bot]

👋 Hi @markphelps! Thanks for your contribution to this project.

It looks like one or more of your commits are missing a DCO (Developer Certificate of Origin) sign-off. The DCO is a simple way for you to certify that you have the right to submit this code under the project's license.

How to fix this:

# For future commits, use the -s flag
git commit -s -m "Your commit message"

# To sign off on existing commits in this PR
git rebase HEAD~$(git rev-list --count origin/v2..HEAD) --signoff
git push --force-with-lease

The -s flag adds this line to your commit message: Signed-off-by: Your Name <[email protected]>

📋 View the failing DCO check for more details

For more information about the DCO, visit: https://developercertificate.org/

github-actions[bot] avatar Nov 30 '25 03:11 github-actions[bot]