-
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 14 commits
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
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package app | ||
|
|
||
| import ( | ||
| "github.com/stackrox/rox/pkg/logging" | ||
| "github.com/stackrox/rox/pkg/memlimit" | ||
| "github.com/stackrox/rox/pkg/premain" | ||
| ) | ||
|
|
||
| var ( | ||
| log = logging.LoggerForModule() | ||
| ) | ||
|
|
||
| // Run is the main entry point for the central application. | ||
| // For Phase 1, this just does early initialization. | ||
| // The actual central logic remains in main.CentralRun() until full migration. | ||
| func Run() { | ||
| memlimit.SetMemoryLimit() | ||
| premain.StartMain() | ||
|
|
||
| // Component-specific initialization will be added in Phase 3 | ||
| initMetrics() | ||
| initCompliance() | ||
| initGraphQL() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package app | ||
|
|
||
| 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 | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Outdated
|
||
| // 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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -233,6 +233,7 @@ import ( | |||||||||||||||||
| pkgVersion "github.com/stackrox/rox/pkg/version" | ||||||||||||||||||
|
|
||||||||||||||||||
| // BusyBox-style consolidation - import app packages | ||||||||||||||||||
| app "github.com/stackrox/rox/central/app" | ||||||||||||||||||
| complianceapp "github.com/stackrox/rox/compliance/cmd/compliance/app" | ||||||||||||||||||
| roxagentapp "github.com/stackrox/rox/compliance/virtualmachines/roxagent/app" | ||||||||||||||||||
| configcontrollerapp "github.com/stackrox/rox/config-controller/app" | ||||||||||||||||||
|
|
@@ -281,7 +282,9 @@ func runSafeMode() { | |||||||||||||||||
| log.Info("Central terminated") | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func centralRun() { | ||||||||||||||||||
| // CentralRun is the main central application logic. | ||||||||||||||||||
| // Exported temporarily to allow central/app package to call it. | ||||||||||||||||||
| func CentralRun() { | ||||||||||||||||||
| defer utils.IgnoreError(log.InnerLogger.Sync) | ||||||||||||||||||
|
|
||||||||||||||||||
| premain.StartMain() | ||||||||||||||||||
|
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. issue (bug_risk): Central mode now runs premain and initialization twice and default mode misses app-level init In the Please refactor so there is a single, consistent initialization path—for example, by having all |
||||||||||||||||||
|
|
@@ -1086,7 +1089,8 @@ func main() { | |||||||||||||||||
|
|
||||||||||||||||||
| switch binaryName { | ||||||||||||||||||
| case "central": | ||||||||||||||||||
| centralRun() | ||||||||||||||||||
| app.Run() | ||||||||||||||||||
| CentralRun() | ||||||||||||||||||
|
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. issue (bug_risk): Avoid calling premain.StartMain (and other early-init) twice for the central binary For the "central" case, both |
||||||||||||||||||
| case "migrator": | ||||||||||||||||||
| migratorapp.Run() | ||||||||||||||||||
| case "compliance": | ||||||||||||||||||
|
|
@@ -1106,6 +1110,6 @@ func main() { | |||||||||||||||||
| default: | ||||||||||||||||||
| // Default to central if called with unknown name | ||||||||||||||||||
| log.Warnf("Unknown binary name %q, defaulting to central mode", binaryName) | ||||||||||||||||||
| centralRun() | ||||||||||||||||||
| CentralRun() | ||||||||||||||||||
|
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. Default-to-central path skips the new central init flow. The 🔧 Proposed fix default:
// Default to central if called with unknown name
log.Warnf("Unknown binary name %q, defaulting to central mode", binaryName)
+ app.Run()
CentralRun()
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't run the global startup hooks twice here.
Run()now callsmemlimit.SetMemoryLimit()andpremain.StartMain(), but central already does those incentral/main.go:init()andmain.CentralRun(). The central path now executes shared startup initialization twice before serving traffic.🤖 Prompt for AI Agents