Feat : Add consumer API endpoint audit#749
Conversation
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds a new api-audit pipeline under validation/ plus a cmd/api-audit CLI to index schema endpoints, parse consumer route registrations (Meshery Gorilla/mux + Meshery Cloud Echo), match them, and optionally reconcile results against a Google Sheet / prior CSV rows.
Changes:
- Implement schema endpoint indexing + schema shape extraction (request/2xx response) to drive audit rows.
- Implement consumer route parsers (Gorilla + Echo) and handler scanning to infer request/response Go types + struct fields.
- Add reconciliation + Google Sheets read/write support and a new
cmd/api-auditentrypoint.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| validation/source_tree.go | Introduces a filesystem/in-memory abstraction for scanning consumer repos and test fixtures. |
| validation/sheets.go | Implements reconciliation logic and Google Sheets read/write integration for audit output. |
| validation/matcher.go | Adds schema↔consumer matching, classification logic, and field/type diffing utilities. |
| validation/matcher_test.go | Unit tests for matching, normalization, and classification behavior. |
| validation/gotype_index.go | Builds an index of Go structs and extracts JSON-tagged field/type shapes for verification. |
| validation/gotype_index_test.go | Tests for JSON tag parsing and Go type string rendering. |
| validation/endpoint_index.go | Walks constructs to index endpoints and derive request/response schema shapes. |
| validation/endpoint_index_test.go | Integration-ish tests that build an index from the real repo tree and validate invariants. |
| validation/consumer.go | Joins route registrations to handler files and infers request/response payload types + fields. |
| validation/consumer_gorilla.go | Gorilla/mux router AST parser for Meshery route registrations. |
| validation/consumer_gorilla_test.go | Tests for Gorilla parser patterns (middleware chains, PathPrefix, anonymous wrappers, sorting). |
| validation/consumer_field_extract_test.go | Tests for extracting struct fields from handler-local and schema-imported types. |
| validation/consumer_echo.go | Echo router AST parser for Meshery Cloud route registrations (including fmt.Sprintf + const resolution). |
| validation/consumer_echo_test.go | Tests for Echo parser patterns (group prefixes, param normalization, WrapHandler, multi-file parsing). |
| validation/apiaudit.go | Orchestrates the end-to-end audit: index schemas, parse consumers, match, build rows, summarize. |
| validation/apiaudit_test.go | Verifies summary accounting for the “Partial” bucket. |
| cmd/api-audit/main.go | Adds a runnable CLI (go run ./cmd/api-audit) to execute the audit and print results. |
| .gitignore | Ignores a locally built api-audit binary. |
There was a problem hiding this comment.
Code Review
This pull request introduces an API audit pipeline to validate OpenAPI schemas against handler implementations in the Meshery and Meshery Cloud repositories. The implementation features AST-based route parsing, field-level verification, and Google Sheets integration for reconciliation. Feedback identifies a critical compilation error due to missing variable definitions and a high-severity risk of handler name collisions in the indexing logic. Additionally, recommendations were made to optimize performance by reducing redundant file I/O and loop complexity, and to improve testability and scalability by avoiding non-deterministic time calls and hardcoded spreadsheet ranges.
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
…, remove unnecessary colms, smoke tests with real changes Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
53ac952 to
67b1f1a
Compare
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
2334533 to
4cc01d4
Compare
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
… was duplification of code Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
…not with generated go types Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
f5a1831 to
2b479af
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a consumer audit tool designed to reconcile OpenAPI schemas with their actual implementations in the Meshery and Meshery Cloud repositories. The implementation includes a new CLI, Makefile targets, and a validation package that performs AST-based parsing of Go source code to identify route registrations and handler payload types. Feedback highlights several areas for improvement, including refining the heuristics for identifying request and response types, respecting Go's block scoping during variable collection, and enhancing the robustness of the router parsers. Additionally, concerns were raised regarding the non-atomic nature of Google Sheets updates and the use of hardcoded cell ranges, which could impact data integrity and scalability.
- reconcile: use UTC date stamp for deterministic Change Log output - matcher: iterate request/response assessments in a fixed order so Notes/Drift columns do not churn across runs - consumer_echo: skip unresolved route expressions instead of aborting the whole audit so a single dynamic Sprintf pattern cannot break the report - consumer_gorilla: use strconv.Unquote so interpreted string literals with standard Go escape sequences are decoded correctly and invalid literals surface as errors Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
cf7344f to
7e32bbc
Compare
|
/gemini review |
- consumer.go: replace substring-based middleware detection with positional CamelCase prefix/suffix/exact matching so handler names like GetAuthorization are no longer skipped as middleware. - consumer.go: clarify identifyArgType comment — only new(T) is resolved here; make(T) flows through the local-var map. - consumer_audit.go: standardize computeEndpointStatus output to the "Active - X, Unimplemented Y" format across all branches so reconciliation does not churn on cosmetic differences in the Endpoint Status column. - sheets.go: build the Google Sheets service once in reconcileFromOpts and reuse it for read + write; wrap the flow in a 2-minute context.WithTimeout so a stalled API call cannot hang CI. Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive consumer audit tool designed to reconcile OpenAPI schemas with actual handler implementations in the Meshery and Meshery Cloud repositories. The implementation includes AST-based Go code parsing for Gorilla and Echo routers, an endpoint indexing system, and Google Sheets integration for tracking coverage and implementation drift over time. The review feedback suggests refactoring hardcoded status strings into exported constants to improve maintainability and ensure consistency between the validation logic and the CLI output.
5463c5c to
425baa8
Compare
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
9038cea to
7a7d971
Compare
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
f04fa56 to
ee42b30
Compare
|
/gemini review |
| t.AddRow("Schema Backed", "-", s.Meshery.BackedTrue, s.Cloud.BackedTrue) | ||
| t.AddRow("Schema Completeness (TRUE)", "-", s.Meshery.CompletenessTrue, s.Cloud.CompletenessTrue) |
There was a problem hiding this comment.
printAuditReport prints schema-backed and schema-completeness counts as 0 when a consumer repo wasn’t provided (because the tallies remain at their zero values). This is misleading in the report output; those cells should display "-" (like the other rows) when meshery/cloud scanning is disabled. Consider using the existing cell() helper for these rows as well.
| t.AddRow("Schema Backed", "-", s.Meshery.BackedTrue, s.Cloud.BackedTrue) | |
| t.AddRow("Schema Completeness (TRUE)", "-", s.Meshery.CompletenessTrue, s.Cloud.CompletenessTrue) | |
| t.AddRow("Schema Backed", "-", | |
| cell(s.Meshery.BackedTrue, s.MesheryEndpoints > 0), | |
| cell(s.Cloud.BackedTrue, s.CloudEndpoints > 0)) | |
| t.AddRow("Schema Completeness (TRUE)", "-", | |
| cell(s.Meshery.CompletenessTrue, s.MesheryEndpoints > 0), | |
| cell(s.Cloud.CompletenessTrue, s.CloudEndpoints > 0)) |
| XInternal []string // ["meshery"], ["cloud"], or nil (= both repos) | ||
| RequestShape *schemaShape // nil for GET/DELETE without body | ||
| ResponseShape *schemaShape // from primary 2xx response | ||
| Deprecated bool // operation-level OR construct-level |
There was a problem hiding this comment.
schemaEndpoint.Deprecated is documented as “operation-level OR construct-level”, but construct-level deprecated specs are filtered out entirely by walkValidatedConstructSpecs (deprecated constructs are skipped), so this field only reflects op.Deprecated for the indexed endpoints. Please update the comment to match the actual behavior to avoid confusion for consumers of the index.
| Deprecated bool // operation-level OR construct-level | |
| Deprecated bool // operation-level only for indexed endpoints |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive consumer audit system designed to reconcile OpenAPI schemas with handler implementations in the Meshery and Meshery Cloud repositories. It includes a new CLI tool, Makefile targets, and a validation package that utilizes Go AST parsing to identify endpoint coverage and implementation drift, with support for Google Sheets integration for state reconciliation. The review feedback identifies critical compilation issues due to missing variable definitions (serverGeneratedFields, dbMirroredFields, and validInternalTags) and suggests several performance optimizations, such as reducing redundant file I/O and combining AST traversal passes. Additionally, minor logic redundancies and formatting inconsistencies in timestamp generation were noted.
55570d8 to
1e158e7
Compare
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
7d0bece to
a68a17d
Compare
…well Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
a68a17d to
b859645
Compare
What this PR does
Adds a consumer audit pipeline (
go run ./cmd/consumer-audit) that answers: for every endpoint defined in meshery/schemas, is it implemented by meshery/meshery and/or meshery-cloud, and does the implementation actually use the shared schema types?The audit produces a structured report — printable to the terminal or reconciled into a Google Sheet — with one row per endpoint and the following columns:
x-internal: None / Meshery / Cloud onlygithub.com/meshery/schemas/models/…Pipeline stages
1. Endpoint index (
validation/endpoint_index.go)Walks every
schemas/constructs/*/api.yml, extracts all operations, and resolves their request/2xx-response schema shapes (following$refs). ReuseswalkValidatedConstructSpecsfrom the existing validator.2. Consumer route parsers
validation/consumer_gorilla.go— AST parser for Meshery's Gorilla/mux router (server/router/server.go). Handles chained.Methods().Handle(),PathPrefix().Handler(), and anonymous wrappers.validation/consumer_echo.go— AST parser for Meshery Cloud's Echo router. Handles group prefixes,:param→{param}rewriting,Any(), andfmt.Sprintfpath construction via a small constant resolver table.3. Handler indexing (
validation/consumer.go)Walks
server/handlers,server/models,server/services,server/daoin each consumer repo. For each HTTP handler function (matched by signature shape), extracts:github.com/meshery/schemas/models/…Decode/Bindcall sites)Encode/JSONcall sites, or inferred from return types of service calls)Multiple handlers with the same name are flagged as ambiguous rather than silently binding to the first match.
4. Matcher (
validation/matcher.go)Outer-join of schema endpoints against consumer endpoints. Three buckets: Matched, Schema-only (unimplemented), Consumer-only (no schema). Two-pass matching: exact path-parameter names first, then loose (names stripped) to surface param-naming drift in the Notes column without losing the match.
5. Audit rows and reconciliation (
validation/consumer_audit.go,validation/sheets.go)Builds one
ConsumerAuditRowper endpoint, then optionally reconciles against a Google Sheet:6. CLI (
cmd/consumer-audit/main.go)Prints a summary table and, with
--verbose, per-endpoint Schema-only and Consumer-only lists. When--sheet-idis set, also prints a diff of new/changed/deleted rows detected on this run.7. Source tree abstraction (
validation/source_tree.go)sourceTreeinterface (ReadFile,Walk,Ref) lets tests inject in-memory file trees instead of real checkouts, keeping integration tests hermetic.Files changed
cmd/consumer-audit/main.govalidation/consumer_audit.govalidation/consumer.govalidation/consumer_gorilla.govalidation/consumer_echo.govalidation/endpoint_index.govalidation/matcher.govalidation/sheets.govalidation/source_tree.govalidation/audit.gowalkValidatedConstructSpecsreusedMakefilemake consumer-audittarget.gitignoreapi-auditbinaryNo schema YAML files, generated Go structs, or TypeScript types are modified.