Skip to content

feat: report environment metrics api #5430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Jun 6, 2025
Merged

Conversation

Zaimwa9
Copy link
Contributor

@Zaimwa9 Zaimwa9 commented May 7, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

⚠️ Branch with front/back: feat/report-environment-metrics-frontend

Dark mode with workflows
image

Light mode without workflows
image

Aim of this PR is to provide an endpoint returning a set of environment-level metrics:

  • Total features

  • Features enabled

  • Segment override

  • Open change requests

  • Scheduled change to come

  • Created a base metric view nested within environment view

  • Added specific query-sets for each metrics

  • New metric service

/api/v1/environments/<environment_api_key>/metrics/	
environments.views.EnvironmentMetricsViewSet	
api-v1:environments:environment-metrics-list
  • Added environment model methods to aggregate the metrics
  • Added serializers and service methods

Payload example:

{
    "metrics": [
        {
            "value": 3,
            "description": "Total features",
            "name": "total_features",
            "disabled": false,
            "entity": "features",
            "rank": 1
        },
        {
            "value": 2,
            "description": "Features enabled",
            "name": "enabled_features",
            "disabled": false,
            "entity": "features",
            "rank": 2
        },
        {
            "value": 0,
            "description": "Segment Overrides",
            "name": "segment_overrides",
            "disabled": false,
            "entity": "segments",
            "rank": 3
        },
        {
            "value": 1,
            "description": "Open change requests",
            "name": "open_change_requests",
            "disabled": false,
            "entity": "change_requests",
            "rank": 4
        },
        {
            "value": 1,
            "description": "Total scheduled changes",
            "name": "total_scheduled_changes",
            "disabled": false,
            "entity": "scheduled_changes",
            "rank": 5
        }
    ]
}

How did you test this code?

  • New tests
  • Via requests
http://localhost:8000/api/v1/environments/<EnvID>/metrics/

How to

  • Create segments, add segments to features
  • Enable / Disable Features
  • Add identity overrides to features
  • Create change requests (activating 4 eyes)
  • Schedule some changes via change requests

Make sure that the displayed metrics reflects reality state

@Zaimwa9 Zaimwa9 requested a review from a team as a code owner May 7, 2025 15:27
@Zaimwa9 Zaimwa9 requested review from khvn26 and removed request for a team May 7, 2025 15:27
Copy link

vercel bot commented May 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Jun 6, 2025 9:00am
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Jun 6, 2025 9:00am
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Jun 6, 2025 9:00am

@Zaimwa9 Zaimwa9 marked this pull request as draft May 7, 2025 15:28
@github-actions github-actions bot added the api Issue related to the REST API label May 7, 2025
Copy link
Contributor

github-actions bot commented May 7, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-5430 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-5430 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-5430 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-5430 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-5430 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5430 Finished ✅ Results

@github-actions github-actions bot added the feature New feature or request label May 7, 2025
Copy link
Contributor

github-actions bot commented May 7, 2025

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/5430

⚙️ Updating now by workflow run 14887281399.

What is Uffizzi? Learn more!

Copy link
Contributor

github-actions bot commented May 7, 2025

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/5430

⚙️ Updating now by workflow run 15320227152.

What is Uffizzi? Learn more!

…h/flagsmith into feat/report-environment-metrics
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels May 7, 2025
Copy link

codecov bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.69%. Comparing base (62c6ef5) to head (24fdc04).
Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5430      +/-   ##
==========================================
+ Coverage   97.65%   97.69%   +0.04%     
==========================================
  Files        1237     1247      +10     
  Lines       43580    44250     +670     
==========================================
+ Hits        42558    43231     +673     
+ Misses       1022     1019       -3     

☔ 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.

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels May 8, 2025
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels May 8, 2025
Returns total feature count and enabled-by-default feature count
scoped to this environment's project.
"""
from edge_api.identities.models import EdgeIdentity
Copy link
Member

Choose a reason for hiding this comment

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

All these local imports suggest this should be moved to the service layer?

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels May 30, 2025
@Zaimwa9 Zaimwa9 requested a review from gagantrivedi June 2, 2025 14:37
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Jun 2, 2025
@matthewelwell matthewelwell linked an issue Jun 3, 2025 that may be closed by this pull request

fs_base_query = (
feature_states_qs.values("feature_id", "feature_segment_id")
.annotate(latest_id=Max("id"))
Copy link
Member

Choose a reason for hiding this comment

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

Why are we doing Max?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, thanks for catching up, it's a (useless) artifact from before using get_live_feature_states

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Jun 6, 2025
)
version += 1

for i in range(segment_overrides_count):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add versions to segments to check version selection

@github-actions github-actions bot removed the feature New feature or request label Jun 6, 2025
@Zaimwa9 Zaimwa9 requested a review from gagantrivedi June 6, 2025 09:01
@github-actions github-actions bot added the feature New feature or request label Jun 6, 2025
@Zaimwa9 Zaimwa9 merged commit ad1f3c1 into main Jun 6, 2025
30 checks passed
@Zaimwa9 Zaimwa9 deleted the feat/report-environment-metrics branch June 6, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API feature New feature or request front-end Issue related to the React Front End Dashboard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Reporting on overall Feature Management Program
3 participants