`GET /v1/stats` and the `simlock stats --csv` ledger
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 65/100
- Type d'issue
- Fonctionnalité
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- typescript
- Domaine
- api, backend, cli, documentation
Piste de recherche
Start with the shared window rules and duration parser, then read src/core/usage/, src/contract/operations.ts, and the relevant handler in src/http/app.ts. Implement the ledger and CSV behavior in src/cli/index.ts, following the listed test cases; update docs/HTTP-API.md and docs/CLI.md. Done means the route matches CLI figures, CSV has one row per request, and the authorization and history-window cases behave as specified.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Part of #329.
Scope
After this PR, GET /v1/stats answers the same figures as simlock stats --json for the same window, and simlock stats --csv writes one row per lease request in the window, a file a spreadsheet opens.
Technical spec
Modules touched
src/http/app.ts—GET /v1/stats?since=<duration>or?from=<ISO>&to=<ISO>, with&ledger=1to include the ledger;todefaults to now; both forms together, or neither, follow the CLI's rules (neither means the last 24 hours). The handler parses the query with the shared duration parser, dispatchesusage.get, and returns its output as JSON.HISTORY_NOT_KEPTtakes its status from the contract's error table, as every error does; a bad window is 400.src/contract/operations.ts—usage.getinput gainsincludeLedger: boolean, defaultfalse; the output carriesrequests[]only when it istrue, so a console or a plainsimlock statscall never receives the ledger.src/core/usage/—computeUsageoutput gainsrequests[]when asked, the ledger:{ requestId, requester, label?, platform, model, workerId?, source?, requestedAt, grantedAt?, endedAt?, waitMs?, heldMs?, turnaroundMs?, outcome: "granted" | "rejected" | "open", reason?, endReason? }, one entry perlease.requestedin the window.src/cli/index.ts—--csvonsimlock statsasks for the ledger and writes it as RFC 4180 CSV to stdout, one header row, a column per ledger field in that order, timestamps as ISO 8601, empty cell for an absent value.--csvwith--jsonis a usage error.docs/HTTP-API.md(route, query, errors, gateway behaviour),docs/CLI.md(--csv),docs/CLIENT.mdif the ledger shows in the client type.
Contract and event changes
usage.getinput gainsincludeLedger(defaultfalse); output gainsrequests[]when it is set. Additive.- New route
GET /v1/stats. Operator token; an agent token gets 403 as every operator route does.
Rules in play
safety.mdrule 10:since,from,toare wire input, parsed and bounded before dispatch.architecture.mdrule 10: the window rules are the CLI's and the route's through one shared function, not two copies.
Tests
computeUsagelists one ledger entry per request with the timestamps and durations of its grant and end, andopenfor a request still waiting at the window's end- the CSV writer quotes a field containing a comma, a quote or a newline, and writes an empty cell for an absent value
simlock stats --csvprints a header row and one row per request, and rejects--csv --jsonGET /v1/stats?since=1hreturns the same body asusage.getfor that window, withoutrequests[];&ledger=1adds itGET /v1/stats?from=&to=withfromlater thantoreturns 400 naming the parameterGET /v1/statswith no window returns the last 24 hoursGET /v1/statswith a window that ends before the oldest held event returnsHISTORY_NOT_KEPTwith the status the error table gives itGET /v1/statswith an agent token returns 403- (e2e) after a scripted run,
curl GET /v1/stats?since=1handsimlock stats --since 1h --jsonprint equal figures - (e2e)
simlock stats --csv --since 1hhas as many data rows aslease.requestedevents in the window
Done when
- After a scripted run against the fake driver,
GET /v1/stats?since=1hwith an operator token returns the same figures assimlock stats --since 1h --json. simlock stats --csv --since 1h > run.csvwrites a file with one header row and one row per lease request, which a spreadsheet opens with the columns separated.- An agent token gets 403 on the route; a window older than the kept history gets 422 with the oldest kept time in the body.
docs/HTTP-API.mddescribes the route under Operator routes, anddocs/CLI.mddescribes--csv.
Out of scope
- The console view (next task).
- A Prometheus or OpenMetrics endpoint.
Depends on
- #347
Approval
- Approved for delivery
Written by an agent.
- Langage dominant
- TypeScript
- Étoiles
- 15
- Forks
- 1
- Merge moyen
- 9 h 6 min
- PR mergées (30 j)
- 138
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de callstackincubator/simlock
-
bug:new
Difficulté 1/5 Moins d'une heure Accessibilité débutants 70/100
callstackincubator/simlock#430 ·
Les mainteneurs répondent en général sous 1 jour
-
bug:new
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
callstackincubator/simlock#429 ·
Les mainteneurs répondent en général sous 1 jour
-
bug:new
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
callstackincubator/simlock#424 ·
Les mainteneurs répondent en général sous 1 jour
-
daemon-lifecycle e2e: the it.fails status test passes for the wrong reasonPeut-être pris @V3RON l’a pris il y a 1 jour. Ouvertebug:triage
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
callstackincubator/simlock#422 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
bug:new
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
callstackincubator/simlock#420 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de callstackincubator/simlock
Issues similaires
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulté 1/5 Moins d'une heure Accessibilité débutants 75/100
lingdojo/kana-dojo#32018 · 1 commentaire · 5 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
paperclipai/paperclip#15751 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
BuilderIO/agent-native#7275 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
Les mainteneurs répondent en général sous 1 jour