Repository navigation
refactor(web): reduce cognitive complexity in middleware and monitors - #623
Merged
Merged
Conversation
Extract focused helpers from the high-complexity middleware and monitor functions. Behavior is unchanged; middleware and monitor unit tests pass. - middleware/auth.go AuthMiddleware (25): authorize, handleAuthDisabled, handleDocsPath - middleware/logger.go LoggerMiddleware (17): cloneRequestBody, logRequestResult, logAPIBodies - missed_ping_monitor.go GetStatus (21): resolveMissedPingSettings, countMonitoredDevices, buildNotifiedDeviceDetails, deviceNameAndWWN - heartbeat_monitor.go checkAndSendHeartbeat (19): recordError, clearError, countHealthyMonitored, sendHeartbeatNotification All flagged functions now sit at or below the cognitive complexity limit of 15. Resolves SonarQube go:S3776 in web middleware and monitors.
- iterate devices by index in the new helpers (gocritic rangeValCopy, models.Device is large) - nolint the relocated access-log Sprintf; %q would change the log quoting/escaping (gocritic sprintfQuotedString)
5 tasks done
Starosdev
pushed a commit
that referenced
this pull request
Jun 20, 2026
## [1.65.0-beta.1](v1.64.0...v1.65.0-beta.1) (2026-06-20) ### Features * **api:** expose and update heartbeat_enabled on notify URLs ([99bb242](99bb242)) * **heartbeat:** filter notify URLs by heartbeat_enabled ([24f359a](24f359a)) * **notify:** add heartbeat_enabled field to notify_urls ([6432a2c](6432a2c)) * **notify:** LoadHeartbeatDatabaseUrls filters by heartbeat_enabled ([51d8662](51d8662)) * **thresholds:** detect Power-On Hours 16-bit counter rollover ([#595](#595)) ([#625](#625)) ([390de8b](390de8b)) * **ui:** add contextual help links for settings docs ([#492](#492)) ([8ceb12b](8ceb12b)) * **ui:** add contextual help links pointing to docs folder ([#492](#492)) ([7b484a0](7b484a0)) * **ui:** add heartbeat toggle per notification URL ([e6bbfea](e6bbfea)) * **ui:** add navigation visibility settings for ZFS, MDADM, Btrfs, Workload ([#588](#588)) ([fca1ae3](fca1ae3)) * **ui:** group MDADM and Workload pages by host ([#579](#579)) ([3e3aa73](3e3aa73)) ### Bug Fixes * **api:** return 404 when heartbeat toggle targets non-existent notify URL ([8c375c2](8c375c2)) * **backend:** pass SmartInfo by pointer to syncDeviceSelfTests (hugeParam) ([e027c33](e027c33)) * **backend:** satisfy gocritic hugeParam and govet fieldalignment lint ([be05416](be05416)) * **db:** simplify migration func to satisfy unlambda linter ([8158a34](8158a34)) * **ui:** style learn more link in Consumer Drive Profiles hint ([#492](#492)) ([ba5b6c3](ba5b6c3)) ### Refactoring * **collector:** reduce cognitive complexity in collector commands ([#617](#617)) ([dedf386](dedf386)), closes [#616](#616) * **collector:** reduce cognitive complexity in device detection ([#619](#619)) ([b2e5a9d](b2e5a9d)) * **database:** reduce cognitive complexity in repository ([#621](#621)) ([4990d88](4990d88)) * **database:** reduce cognitive complexity in the migration runner ([#624](#624)) ([037c82d](037c82d)) * **frontend:** reduce cognitive complexity in components ([#620](#620)) ([278cd44](278cd44)) * **measurements:** reduce cognitive complexity in smart.go ([#616](#616)) ([b82e0f5](b82e0f5)) * **models:** reduce cognitive complexity in measurement models ([#622](#622)) ([900e4c3](900e4c3)) * **notify:** reduce cognitive complexity in notification senders ([#618](#618)) ([249d836](249d836)), closes [#616](#616) [#617](#617) * **web:** reduce cognitive complexity in middleware and monitors ([#623](#623)) ([8695dc8](8695dc8))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduces SonarQube cognitive complexity (go:S3776) across the web middleware and background monitors. All flagged functions now sit at or below the allowed limit of 15.
Changes
Pure extraction of helpers; no behavior change.
authorize, withhandleAuthDisabledandhandleDocsPathfor the two special path classescloneRequestBody,logRequestResult(status→level selection),logAPIBodiesresolveMissedPingSettings,countMonitoredDevices,buildNotifiedDeviceDetails,deviceNameAndWWNrecordError/clearError(the repeated status-mutex blocks),countHealthyMonitored,sendHeartbeatNotificationVerification
go build ./webapp/backend/...go veton web + middleware packagesgo test— middleware tests and the heartbeat/missed-ping monitor unit tests pass (verified against a throwaway InfluxDB)gocognit -over 15reports zero functions over the limitgofmtcleanNotes
Continuation of SonarQube Group 5. Only the DB migration runner (
Migrate, complexity 166) remains after this, to be handled in a dedicated change.