Repository navigation
refactor(models): reduce cognitive complexity in measurement models - #622
Merged
Merged
Conversation
Collapse the repeated optional-field extraction in the InfluxDB constructors using the existing influxString/influxInt64/influxFloat64 helpers, and split the threshold/profile parsers into focused helpers. Behavior is unchanged; measurements and thresholds tests pass. - btrfs_metrics NewBtrfsMetricsFromInfluxDB (34) - performance NewPerformanceFromInfluxDB (32) - mdadm_metrics NewMDADMMetricsFromInfluxDB (18) - smart_ata_attribute ValidateThreshold (27): thresholdValue, observedThresholdContains, observedFailureRate, applyFailureRateStatus - thresholds parseConsumerDriveProfiles (23): addConsumerDriveProfile, addConsumerDriveAlias All flagged functions now sit at or below the cognitive complexity limit of 15. Resolves SonarQube go:S3776 in measurement models and threshold parsing.
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 measurement models and threshold parsing. All flagged functions now sit at or below the allowed limit of 15.
Changes
Pure refactor; no behavior change.
NewXFromInfluxDBconstructors had long runs ofif val, ok := attrs[k]; ok && val != nil { ... }optional-field blocks. These now use the package's existinginfluxString/influxInt64/influxFloat64helpers (defined inzfs_pool_metrics.go). Assigning the helper's zero value for an absent key is equivalent to leaving the field unset, and the helpers keep the same panic-on-type-mismatch behavior as the original direct assertions.thresholdValue(display-type selection),observedThresholdContains,observedFailureRate, andapplyFailureRateStatus.addConsumerDriveProfileandaddConsumerDriveAliasper-entry handlers.Verification
go build ./webapp/backend/...go veton both packagesgo test -count=1 ./webapp/backend/pkg/models/measurements/... ./webapp/backend/pkg/thresholds/...— pass (no InfluxDB needed)gocognit -over 15reports zero functions over the limitgofmtcleanNotes
Continuation of SonarQube Group 5, after #616/#617/#618/#619/#620/#621. Remaining: web middleware/monitors (auth, logger, heartbeat, missed-ping) and the DB migration runner (Migrate, 166).