Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 58 additions & 19 deletions docs/v0s_console_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,33 +378,47 @@ query GlobalVulnerabilityPage($first: Int, $after: Cursor, $last: Int, $before:
}
```

### CVE-only request cost

The global query above does not fetch a findings page (`ListFindings`). Adding
`summary` uses `GetSummary` independently and still does not fetch findings.
Selecting parent `nodes`, `edges`, `pageInfo` or `facets` keeps the existing
findings-page loading. In particular, package-type facets need the
`PackageTypeCounts` from `ListFindings`; they are not replaced with empty facets.
### Findings-page dependencies

The same loading rules apply to `vulnerabilityFindings` on Query, Team,
TeamEnvironment, Application and Job. Selecting only `summary`, `vulnerabilities`,
`affectedWorkloads` or `__typename` does not fetch the parent findings page
(`ListFindings`). `summary` uses `GetSummary`, `vulnerabilities` uses
`ListVulnerabilities`, and `affectedWorkloads` uses workload overviews.
Parent pagination arguments are optional: `first: 1` is not necessary for
aggregate-only queries, and omitting it does not fetch a default findings page.

Selecting parent `nodes`, `edges`, `pageInfo` or `facets` retains findings-page
loading. In particular, package-type facets need `PackageTypeCounts` from
`ListFindings`; they are not replaced with empty facets. CLI team summaries
that request both `summary` and `facets` therefore still need findings.
Aliases, fragments and `@skip`/`@include` follow the effective field selection.
Scoped findings fields retain their existing loading behavior.

Console CVE details select `summary` and `affectedWorkloads`, then finding rows
inside each returned application or job. Those per-workload finding pages remain
necessary; only the redundant parent page is skipped. Nested `nodes` or
`pageInfo` do not force their ancestor connection to load a findings page.

Authorization, current workload/image selection and parent argument/cursor
validation still run even when the findings page is unused. The nested CVE
connection retains its own cursor, bidirectional pagination and exact filtered
total. This optimization requires only an API rollout, with no Console, GraphQL
or v0s server change and no additional cursor restart.

To measure without tracing, use the same global GraphiQL query, variables and
page traversal before and after deployment, first without and then with
`summary`. Record client latency and Grafana counter deltas for
`ListFindings` and `ListVulnerabilities` over a bounded measurement window:
compare RPC counts and cumulative duration, not just duration per RPC.
These requests should contribute zero `ListFindings` calls after rollout;
`ListVulnerabilities` remains necessary. A mixed query selecting findings/facets
should still contribute findings calls. Counters aggregate all traffic, so use
a quiet window and record background traffic; the deltas cannot attribute
individual calls to GraphiQL. Do not promise a fixed latency reduction or treat
this as an optimization of `ListVulnerabilities` or workload inventory lookups.
To measure without tracing, compare the same global/team overview and CVE detail
queries, variables and page traversal before and after deployment. Summary-only
or CVE-list-only requests should contribute zero `ListFindings` calls. CVE details
should lose the parent findings-page call but retain requested workload pages;
mixed queries selecting parent findings/facets still need findings calls.
Record client latency, existing GraphQL field timing
(`Query/vulnerabilityFindings` or the corresponding scoped field), and Grafana
deltas for RPC counts and cumulative duration of `ListFindings` and
`ListVulnerabilities` over a bounded measurement window.
Counters aggregate all traffic, so use a quiet window and record background
traffic; the deltas cannot attribute individual calls to GraphiQL.
Fewer RPCs alone do not prove lower end-to-end latency. Do not promise a fixed
reduction or treat this as an optimization of `ListVulnerabilities` or inventory
lookups.

Console can use `endCursor` for Next and `startCursor` for Previous with the same
filter and order:
Expand Down Expand Up @@ -1118,3 +1132,28 @@ available; Console must not present one as functional.
Rolling Console back does not copy newer v0s assessments into v13s. Preserve
assessment state; explicitly reconcile any data transfer instead of claiming
consistency between independent models.

### Remaining cutover coordination

Merged changes are not evidence of deployment to every tenant. API
[#670](https://github.com/nais/api/pull/670) accepts workload overviews without
`total_count`; [nais/v0s#26](https://github.com/nais/v0s/pull/26) removes that field
and the deprecated workload-order shell, and optimizes vulnerability totals and
PageInfo probes. Retain the client-first rollout and rollback constraints above.
UNKNOWN ordering is already documented as first in ASC and last in DESC.

[nais/console-frontend#797](https://github.com/nais/console-frontend/pull/797)
uses `V0S_VULNERABILITIES_ENABLED` for direct assessment writes. Coordinate it
with API's `v0s.suppressionsEnabled` per tenant, verify create/edit/delete, and
do not use legacy writes as fallback for a v0s view.

CLI already consumes v0s findings, summaries and workload overviews through this
GraphQL contract. Keep those consumers compatible; source support does not by
itself establish CLI release adoption or completed user migration.

Before full cutover, explicitly decide and communicate the future of
`nais_workload_vulnerabilities`, `nais_workload_vulnerabilities_kev`,
`nais_workload_vulnerabilities_priority` and `nais_workload_risk_score`, including
count/suppression semantics and update delay. Do not silently redefine existing
alerts or reintroduce priority/risk score merely to preserve old metric names.
This coordination is separate from skipping unused findings pages.
14 changes: 14 additions & 0 deletions internal/graph/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package graph
import (
"context"
"maps"
"strings"

"github.com/99designs/gqlgen/graphql"
)
Expand Down Expand Up @@ -31,6 +32,19 @@ func getPreloadString(prefix, name string) string {
return name
}

func needsVulnerabilityFindingPage(ctx context.Context) bool {
for _, field := range getPreloads(ctx) {
switch field {
case "vulnerabilities", "summary", "affectedWorkloads", "__typename":
default:
if !strings.Contains(field, ".") {
return true
}
}
}
return false
}

func onlyAsksForPageInfoTotalCount(ctx context.Context) bool {
preloads := make(map[string]struct{})
for _, preload := range getPreloads(ctx) {
Expand Down
21 changes: 5 additions & 16 deletions internal/graph/v0s.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package graph

import (
"context"
"strings"

"github.com/nais/api/internal/graph/gengql"
"github.com/nais/api/internal/graph/pagination"
Expand All @@ -14,7 +13,7 @@ import (
)

func (r *applicationResolver) VulnerabilityFindings(ctx context.Context, obj *application.Application, filter *v0s.WorkloadVulnerabilityFindingsFilter, first *int, after *pagination.Cursor, last *int, before *pagination.Cursor, orderBy *v0s.VulnerabilityFindingOrder) (*v0s.VulnerabilityFindingConnection, error) {
return v0s.FindingsForWorkloads(ctx, v0s.WorkloadScope(obj), []workload.Workload{obj}, (*v0s.VulnerabilityFindingFilter)(filter), first, after, last, before, orderBy)
return v0s.FindingsForSelection(ctx, v0s.WorkloadScope(obj), []workload.Workload{obj}, nil, (*v0s.VulnerabilityFindingFilter)(filter), first, after, last, before, orderBy, needsVulnerabilityFindingPage(ctx))
}

func (r *applicationResolver) VulnerabilityCoverage(ctx context.Context, obj *application.Application) (*v0s.VulnerabilityCoverage, error) {
Expand All @@ -26,7 +25,7 @@ func (r *applicationResolver) VulnerabilityOverview(ctx context.Context, obj *ap
}

func (r *jobResolver) VulnerabilityFindings(ctx context.Context, obj *job.Job, filter *v0s.WorkloadVulnerabilityFindingsFilter, first *int, after *pagination.Cursor, last *int, before *pagination.Cursor, orderBy *v0s.VulnerabilityFindingOrder) (*v0s.VulnerabilityFindingConnection, error) {
return v0s.FindingsForWorkloads(ctx, v0s.WorkloadScope(obj), []workload.Workload{obj}, (*v0s.VulnerabilityFindingFilter)(filter), first, after, last, before, orderBy)
return v0s.FindingsForSelection(ctx, v0s.WorkloadScope(obj), []workload.Workload{obj}, nil, (*v0s.VulnerabilityFindingFilter)(filter), first, after, last, before, orderBy, needsVulnerabilityFindingPage(ctx))
}

func (r *jobResolver) VulnerabilityCoverage(ctx context.Context, obj *job.Job) (*v0s.VulnerabilityCoverage, error) {
Expand Down Expand Up @@ -56,17 +55,7 @@ func (r *queryResolver) VulnerabilityFindings(ctx context.Context, filter *v0s.V
if err != nil {
return nil, err
}
includePage := false
for _, field := range getPreloads(ctx) {
switch field {
case "vulnerabilities", "summary", "__typename":
default:
if !strings.Contains(field, ".") {
includePage = true
}
}
}
return v0s.FindingsForSelection(ctx, v0s.Scope{}, selected, metadata, findings, first, after, last, before, orderBy, includePage)
return v0s.FindingsForSelection(ctx, v0s.Scope{}, selected, metadata, findings, first, after, last, before, orderBy, needsVulnerabilityFindingPage(ctx))
}

func (r *queryResolver) Vulnerability(ctx context.Context, identifier string) (*v0s.Vulnerability, error) {
Expand All @@ -87,7 +76,7 @@ func (r *teamResolver) VulnerabilityFindings(ctx context.Context, obj *team.Team
metadata = &v0s.VulnerabilityWorkloadFilter{Environments: filter.Environments, Labels: filter.Labels}
findings = &filter.VulnerabilityFindingFilter
}
return v0s.FindingsForSelection(ctx, scope, selectTeamWorkloads(ctx, obj.Slug, workloadFilter), metadata, findings, first, after, last, before, orderBy, true)
return v0s.FindingsForSelection(ctx, scope, selectTeamWorkloads(ctx, obj.Slug, workloadFilter), metadata, findings, first, after, last, before, orderBy, needsVulnerabilityFindingPage(ctx))
}

func (r *teamResolver) VulnerabilitySuppressions(ctx context.Context, obj *team.Team, filter *v0s.TeamVulnerabilitySuppressionsFilter, first *int, after *pagination.Cursor, last *int, before *pagination.Cursor) (*pagination.Connection[*v0s.VulnerabilitySuppression], error) {
Expand All @@ -96,7 +85,7 @@ func (r *teamResolver) VulnerabilitySuppressions(ctx context.Context, obj *team.

func (r *teamEnvironmentResolver) VulnerabilityFindings(ctx context.Context, obj *team.TeamEnvironment, filter *v0s.TeamEnvironmentVulnerabilityFindingsFilter, first *int, after *pagination.Cursor, last *int, before *pagination.Cursor, orderBy *v0s.VulnerabilityFindingOrder) (*v0s.VulnerabilityFindingConnection, error) {
selected := selectTeamWorkloads(ctx, obj.TeamSlug, &workload.TeamWorkloadsFilter{Environments: []string{obj.EnvironmentName}})
return v0s.FindingsForWorkloads(ctx, v0s.Scope{Team: obj.TeamSlug, Environment: obj.EnvironmentName}, selected, (*v0s.VulnerabilityFindingFilter)(filter), first, after, last, before, orderBy)
return v0s.FindingsForSelection(ctx, v0s.Scope{Team: obj.TeamSlug, Environment: obj.EnvironmentName}, selected, nil, (*v0s.VulnerabilityFindingFilter)(filter), first, after, last, before, orderBy, needsVulnerabilityFindingPage(ctx))
}

func (r *teamEnvironmentResolver) VulnerabilitySuppressions(ctx context.Context, obj *team.TeamEnvironment, filter *v0s.TeamEnvironmentVulnerabilitySuppressionsFilter, first *int, after *pagination.Cursor, last *int, before *pagination.Cursor) (*pagination.Connection[*v0s.VulnerabilitySuppression], error) {
Expand Down
Loading
Loading