Skip to content

Improve error logging for DCM operations#101

Open
guru-ossdev wants to merge 1 commit into
developfrom
feature/improve-dcm-error-logging
Open

Improve error logging for DCM operations#101
guru-ossdev wants to merge 1 commit into
developfrom
feature/improve-dcm-error-logging

Conversation

@guru-ossdev
Copy link
Copy Markdown
Contributor

This pull request improves error logging throughout the DCM (Dynamic Configuration Management) admin API services. It adds detailed log messages wherever critical operations fail, especially when database updates or deletions do not succeed, or when type assertions for response writers fail. This will make debugging and monitoring much easier by providing more context in log outputs.

The most important changes are:

Enhanced Error Logging for Database Operations:

  • Added structured log messages (including entity IDs and error details) when create, update, or delete operations fail in DCM formula, device settings, log repo settings, log upload settings, and VOD settings services. This applies to functions such as CreateDcmRule, UpdateDcmRule, DeleteDcmFormulabyId, and their equivalents for device, log, and VOD settings. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]

Improved Error Logging for Response Writer Type Assertions:

  • Added explicit error log messages when failing to cast http.ResponseWriter to XResponseWriter in various handler functions, making it clear where and why the failure occurred. [1] [2] [3] [4] [5]

Dependency Update:

  • Imported the logrus logging library in dcmformula_service.go to support structured logging.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves observability for the DCM admin API by adding more explicit error logging around failed persistence operations and failed http.ResponseWriterXResponseWriter type assertions.

Changes:

  • Add structured error logs (with entity IDs and error details) for failed create/update/delete operations across multiple DCM settings services.
  • Add explicit error logs when http.ResponseWriter cannot be cast to *xwhttp.XResponseWriter in several handlers/controllers.
  • Introduce a logrus import in dcmformula_service.go to support the new structured logs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
adminapi/dcm/vod_settings_service.go Adds structured error logs for VOD settings DB write/delete failures.
adminapi/dcm/test_page_controller.go Logs when ResponseWriter type assertion fails in test page handler.
adminapi/dcm/logupload_settings_service.go Adds structured error logs for log upload settings DB write/delete failures.
adminapi/dcm/logrepo_settings_service.go Adds structured error logs for log repo settings DB write/delete failures.
adminapi/dcm/device_settings_service.go Adds structured error logs for device settings DB write/delete failures.
adminapi/dcm/dcmformula_service.go Adds structured error logs for formula/rule persistence failures (and adds logrus import).
adminapi/dcm/dcmformula_handler.go Logs when ResponseWriter type assertion fails in several handlers; logs on priority update persistence failure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 38 to +42
xwhttp "github.com/rdkcentral/xconfwebconfig/http"
"github.com/rdkcentral/xconfwebconfig/rulesengine"
re "github.com/rdkcentral/xconfwebconfig/rulesengine"
"github.com/rdkcentral/xconfwebconfig/shared/logupload"
log "github.com/sirupsen/logrus"
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import block includes the same package path twice: github.com/rdkcentral/xconfadmin/common is imported both unaliased (common) and as xcommon. Go does not allow duplicate imports of the same path, so this will fail to compile. Remove one of these imports and update references to use the remaining import name consistently.

Copilot uses AI. Check for mistakes.
for _, entry := range changedDcmRules {
entry.(*logupload.DCMGenericRule).Updated = util.GetTimestamp()
if err := db.GetCachedSimpleDao().SetOne(db.TABLE_DCM_RULE, entry.GetID(), entry); err != nil {
log.WithFields(log.Fields{"entity_id": entry.GetID(), "error": err}).Error("failed to create dcm formula")
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log message is misleading: the failing SetOne call is persisting a mix of new and re-prioritized existing rules after reorganization, not strictly "create". Consider using wording like "failed to persist dcm rule changes" (and/or include operation context) so logs are accurate during priority rebalancing failures.

Suggested change
log.WithFields(log.Fields{"entity_id": entry.GetID(), "error": err}).Error("failed to create dcm formula")
log.WithFields(log.Fields{"entity_id": entry.GetID(), "error": err}).Error("failed to persist dcm rule changes")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants