-
Notifications
You must be signed in to change notification settings - Fork 177
WIP: ROX-34074: Fix components init func #19966
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
79d020c
ce0bf8d
99f16b5
391316f
6834046
29b615f
2cf4237
2af5b79
eb3f1e0
bdfdc77
2287e20
0449ea6
8b5a49f
eca4ef0
d3de83e
987c76a
82a6968
c78f077
93f7842
db6b9d5
f1a6ada
6744213
9b30c56
f24eb46
668c7ef
0a704c0
b84cb73
3b1086c
530b499
f487fd3
4e8afdd
f8083d4
4c0dbf7
998006c
3ab5d12
5dfcdc9
26ed417
e9f029f
4eb3d12
51425e9
441a472
d62a670
a7c0386
0d397c9
0cb5d2a
6fceb99
dd31084
aeee0e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Establishes initGraphQL() in central/app/init.go. Full migration of GraphQL loader init() functions deferred to separate PR. Documents migration strategy in docs/graphql-loader-init-migration.md. Part of ROX-33958. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,65 @@ | ||
| package app | ||
|
|
||
| // Component-specific initialization functions will be added in Phase 3. | ||
| // This file is created now to establish the structure. | ||
| import ( | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/stackrox/rox/central/metrics" | ||
| ) | ||
|
|
||
| func initMetrics() { | ||
| prometheus.MustRegister( | ||
| metrics.PipelinePanicCounter, | ||
| metrics.GraphQLOperationHistogramVec, | ||
| metrics.GraphQLQueryHistogramVec, | ||
| metrics.IndexOperationHistogramVec, | ||
| metrics.SensorEventQueueCounterVec, | ||
| metrics.ResourceProcessedCounterVec, | ||
| metrics.TotalNetworkFlowsReceivedCounter, | ||
| metrics.TotalNetworkEndpointsReceivedCounter, | ||
| metrics.TotalExternalPoliciesGauge, | ||
| metrics.CurrentExternalPolicies, | ||
| metrics.SensorEventDurationHistogramVec, | ||
| metrics.RiskProcessingHistogramVec, | ||
| metrics.DatastoreFunctionDurationHistogramVec, | ||
| metrics.FunctionSegmentDurationHistogramVec, | ||
| metrics.K8sObjectProcessingDuration, | ||
| metrics.PostgresOperationHistogramVec, | ||
| metrics.AcquireDBConnHistogramVec, | ||
| metrics.ClusterMetricsNodeCountGaugeVec, | ||
| metrics.ClusterMetricsCPUCapacityGaugeVec, | ||
| metrics.TotalOrphanedPLOPCounter, | ||
| metrics.ProcessQueueLengthGauge, | ||
| metrics.SensorEventsDeduperCounter, | ||
| metrics.SensorConnectedCounter, | ||
| metrics.GrpcMaxMessageSize, | ||
| metrics.GrpcSentSize, | ||
| metrics.GrpcLastMessageSizeSent, | ||
| metrics.GrpcLastMessageSizeReceived, | ||
| metrics.GrpcError, | ||
| metrics.DeploymentEnhancementRoundTripDuration, | ||
| metrics.ReprocessorDurationGauge, | ||
| metrics.SignatureVerificationReprocessorDurationGauge, | ||
| metrics.PruningDurationHistogramVec, | ||
| metrics.StoreCacheOperationHistogramVec, | ||
| metrics.MsgToSensorNotSentCounter, | ||
| ) | ||
| } | ||
|
|
||
| // initCompliance registers all compliance checks. | ||
| func initCompliance() { | ||
| // Import side-effect: pkg/compliance/checks registers all standard checks via init() | ||
| // We consolidate that registration here by calling the registration function explicitly | ||
| // This is handled by importing central/compliance/checks/remote which calls MustRegisterChecks | ||
|
|
||
| // The actual registration is done via the package import | ||
| // Future work: refactor compliance/checks to use explicit registration | ||
| } | ||
|
|
||
| // initGraphQL registers all GraphQL type loaders. | ||
| func initGraphQL() { | ||
| // GraphQL loaders registration | ||
| // Each loader registers itself via RegisterTypeFactory in their init() functions | ||
|
|
||
| // Similar to compliance checks, this requires refactoring the loader registration | ||
| // to be explicit rather than init()-based | ||
| // Stub for now - full migration in separate PR | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These helpers do not remove the busybox init cost yet. Both functions are stubs, and the comments explicitly say the real registration still happens through package-import side effects. In the consolidated binary, those 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # GraphQL Loader Init Migration | ||
|
|
||
| ## Current State | ||
| - ~15 GraphQL loader files in central/graphql/resolvers/loaders/ | ||
| - Each has init() calling RegisterTypeFactory() | ||
| - Loaders: cluster_cves, componentsV2, deployments, images, namespaces, etc. | ||
|
|
||
| ## Migration Strategy | ||
| Phase 3.3 establishes initGraphQL() stub in central/app/init.go | ||
|
|
||
| Future work (separate PR): | ||
| 1. Refactor loaders package to export registration function | ||
| 2. Call registration from central/app/init.go initGraphQL() | ||
| 3. Remove init() from all loader files | ||
|
|
||
| ## Files affected: | ||
| - central/graphql/resolvers/loaders/cluster_cves.go | ||
| - central/graphql/resolvers/loaders/componentsV2.go | ||
| - central/graphql/resolvers/loaders/context.go | ||
| - central/graphql/resolvers/loaders/deployments.go | ||
| - central/graphql/resolvers/loaders/factory.go | ||
| - central/graphql/resolvers/loaders/image_cves_v2.go | ||
| - central/graphql/resolvers/loaders/images.go | ||
| - central/graphql/resolvers/loaders/images_v2.go | ||
| - central/graphql/resolvers/loaders/list_deployments.go | ||
| - central/graphql/resolvers/loaders/namespaces.go | ||
| - central/graphql/resolvers/loaders/node_components.go | ||
| - central/graphql/resolvers/loaders/node_cves.go | ||
| - central/graphql/resolvers/loaders/nodes.go | ||
| - central/graphql/resolvers/loaders/policies.go | ||
| - central/graphql/resolvers/loaders/utils.go | ||
|
|
||
| ## RegisterTypeFactory Pattern | ||
| Each loader file follows this pattern: | ||
|
|
||
| ```go | ||
| var deploymentLoaderType = reflect.TypeOf(storage.Deployment{}) | ||
|
|
||
| func init() { | ||
| RegisterTypeFactory(reflect.TypeOf(storage.Deployment{}), func() interface{} { | ||
| return NewDeploymentLoader(datastore.Singleton(), deploymentsView.Singleton()) | ||
| }) | ||
| } | ||
| ``` | ||
|
|
||
| ## Future Migration Approach | ||
| 1. Create central/graphql/resolvers/loaders/register.go with exported RegisterAllLoaders() function | ||
| 2. Move all RegisterTypeFactory calls into RegisterAllLoaders() | ||
| 3. Call RegisterAllLoaders() from central/app/init.go initGraphQL() | ||
| 4. Remove init() functions from individual loader files | ||
| 5. Verify GraphQL queries still work in integration tests |
Uh oh!
There was an error while loading. Please reload this page.