admin: Migrate all metabase dashboard to UI#121
Open
skelz0r wants to merge 28 commits into
Open
Conversation
The existing dsfr-chart library already includes a <pie-chart> web
component. This adds the ERB partial to expose it alongside the
existing _kpi, _line, and _bar partials.
Accepts `title:` and `segments:` (array of {label:, value:}).
These readonly models map to the existing materialized views defined
in very_ansible (controller_name, kpi1, kpi2, kpi3). They follow the
same table naming convention as ConsumptionSummary:
admin_apientreprise_#{Rails.env}_access_logs_<name>
Shared filter for all admin statistics pages. Handles date range (with presets), interval (jour/semaine/mois), domaine (entreprise/particulier), and optional API/email/token/external_id fields. Converts interval to PostgreSQL date_trunc unit.
Query object for the kpi query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the token consumption query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the top users query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the api health query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the api status query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the annual stats query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the api consumers query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the users overview query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the user status query admin statistics page. Translates Metabase SQL cards into ActiveRecord queries against ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Migrates Metabase dashboards from collections 54, 63, 66, 67 into native admin pages. Each page has its own query object and view. Pages: KPI & Statistiques, Consommation d'un token, Top 10 utilisateurs, État de santé global, Statut d'une API, Statistiques annuelles, Consommateurs d'une API, Vue générale utilisateurs, Status utilisateur/datapass/jetons. Merges: D90+D91 (KPI by domain filter), D86+D87 (annual stats by domain filter). Drops: D49 (migration tokens), D43 (EdL anciens jetons), D101 (Suivi FQF). Adds /admin/statistics route, nav link, DSFR tile index, shared filter partial with date presets and domain/interval/email selectors.
These views already exist in production (managed by very_ansible) but were missing from db/schema.rb. Adds them alongside the existing consumption_summary view, following the same naming convention.
Describes the 9 dashboard pages migrated from Metabase, their origin collections/dashboards, architecture (query objects, filter, views), chart components used, and the 3 excluded legacy dashboards.
Replace 9 collection routes with a single `resources :statistics, only: [:index, :show], param: :page`. The show action validates the page key against PAGES and renders the corresponding template. Simplifies routing and removes per-page action boilerplate.
Add `# card XXX` comments to every public query method across all 9 admin query objects, matching the pattern established in Provider::DashboardQuery. This makes it easy to trace each native query back to its original Metabase saved question for debugging and future maintenance.
token_status_breakdown compared exp (integer) against Time.current (timestamp), causing a PG type mismatch error. Compare against Time.current.to_i instead. Also fix the view which called strftime on the raw integer — convert via Time.zone.at first.
A malformed token_id (typo, non-UUID input) would raise a raw PG cast error and 500 the page. Validate the format upfront and raise RecordNotFound instead, which Rails handles gracefully as a 404.
Date subtraction returns the exclusive day count (May 1..May 31 = 30), but the range is inclusive so the actual window is 31 days. Add 1 to get an equally sized comparison window for variation percentages.
Use where(exp: ..now) range syntax instead of manual SQL for the expired tokens filter.
KpiView (abstract_class = true) has no table_name, so flushdb tried to call delete_all on it and raised "no implicit conversion of nil into String". Filter out abstract classes before iterating.
ff946eb to
9f77c9e
Compare
The additional abstract_class? check pushed the method 0.58 over the AbcSize threshold. Inline disable matches the pattern used elsewhere in this file.
- Api* → API* to match inflect.acronym 'API' in inflections.rb
- AnnualStats → AnnualStat, ApiConsumers → APIConsumer,
TopUsers → TopUser to match classify singularization
(controller uses "Admin::#{page.to_s.classify}Query".constantize)
- Qualify access_logs.status in SQL WHERE clauses to prevent
PG::AmbiguousColumn when joining with authorization_requests
Prevent potential PG::AmbiguousColumn when joining with tables that also have a status column (e.g. authorization_requests).
…uery Both classes used `filter` in methods but had no accessor defined, causing NameError at runtime.
Cover 8 query facades: APIStatusQuery, APIHealthQuery, APIConsumerQuery, AnnualStatQuery, TopUserQuery, TokenConsumptionQuery, UserStatusQuery, UsersOverviewQuery. 53 examples covering card methods, filter scoping, edge cases (UUID validation, excluded controllers, epoch-based token expiry). KpiQuery not tested — depends on ConsumptionSummary materialized view.
map { |r| r[:key] } → pluck(:key)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes https://linear.app/pole-api/issue/API-6748