Skip to content

Commit

Permalink
[CCXDEV-14053] Remove problematic logs (#2038)
Browse files Browse the repository at this point in the history
* remove problematic logs

* use Interface for orgID

* undo delete

* remove duplicated strings

* update insights-operator-utils

* remove other problematic logs
  • Loading branch information
juandspy authored Aug 7, 2024
1 parent a430efb commit da4b734
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 39 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/BurntSushi/toml v1.4.0
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/RedHatInsights/insights-operator-utils v1.25.4
github.com/RedHatInsights/insights-operator-utils v1.25.5
github.com/RedHatInsights/insights-results-aggregator-data v1.3.9
github.com/RedHatInsights/insights-results-types v1.23.4
github.com/Shopify/sarama v1.27.1
Expand All @@ -29,8 +29,8 @@ require (
require (
github.com/RedHatInsights/cloudwatch v0.0.0-20210111105023-1df2bdfe3291 // indirect
github.com/RedHatInsights/kafka-zerolog v1.0.0 // indirect
github.com/archdx/zerolog-sentry v1.8.2 // indirect
github.com/aws/aws-sdk-go v1.50.16 // indirect
github.com/archdx/zerolog-sentry v1.8.4 // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
Expand Down Expand Up @@ -63,7 +63,7 @@ require (
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/redis/go-redis/v9 v9.4.0 // indirect
github.com/redis/go-redis/v9 v9.6.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/kafka-go v0.4.10 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ github.com/RedHatInsights/insights-operator-utils v1.21.0/go.mod h1:B2hizFGwXCc8
github.com/RedHatInsights/insights-operator-utils v1.21.2/go.mod h1:3Pfsgsi7GCu2wgIqQlt1llpyQyyxsDWEGdgnPvadM40=
github.com/RedHatInsights/insights-operator-utils v1.21.8/go.mod h1:qa1a8NdarIzcZkr5mu9fBw4OarOfg1qZFZC1vNGbyas=
github.com/RedHatInsights/insights-operator-utils v1.24.5/go.mod h1:7qR/8rlMdiqoXAkZyQ5JhVrVNCa6SBwNUt4KMq/17j4=
github.com/RedHatInsights/insights-operator-utils v1.25.4 h1:H5iXuvsxFkjmGmAefkv6b+FxQWq9b0me7FPa7Fx8M1Y=
github.com/RedHatInsights/insights-operator-utils v1.25.4/go.mod h1:GGa8HtCNKyfugkNkpVojp+mO24N27npbgi85QkpPteA=
github.com/RedHatInsights/insights-operator-utils v1.25.5 h1:xyk4UAolH6vAzd+D6zKf6CoyDYsN4lx603qQhGXIxxA=
github.com/RedHatInsights/insights-operator-utils v1.25.5/go.mod h1:T9tCuJUXLThmmcg9sLkj+/ZMExsj7RFTmfyyHiHBCjQ=
github.com/RedHatInsights/insights-results-aggregator v0.0.0-20200604090056-3534f6dd9c1c/go.mod h1:7Pc15NYXErx7BMJ4rF1Hacm+29G6atzjhwBpXNFMt+0=
github.com/RedHatInsights/insights-results-aggregator-data v0.0.0-20200825113234-e84e924194bc/go.mod h1:DcDgoCCmBuUSKQOGrTi0BfFLdSjAp/KxIwyqKUd46sM=
github.com/RedHatInsights/insights-results-aggregator-data v0.0.0-20201014142608-de97c4b07d5c/go.mod h1:x8IvreR2g24veCKVMXDPOR6a0D86QK9UCBfi5Xm5Gnc=
Expand Down Expand Up @@ -83,8 +83,8 @@ github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9Pq
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/archdx/zerolog-sentry v0.0.1/go.mod h1:dAIUEqBAhDI/yVS3nqOr7VS9BsvHJ5btxoGFEE2RmGk=
github.com/archdx/zerolog-sentry v1.8.2 h1:zS8n0+H7SsG161RN8dP47CSsdyrhODdo9LEDOPXJhXI=
github.com/archdx/zerolog-sentry v1.8.2/go.mod h1:XrFHGe1CH5DQk/XSySu/IJSi5C9XR6+zpc97zVf/c4c=
github.com/archdx/zerolog-sentry v1.8.4 h1:Thxb8Crm+JaV1kcAF2KEcpKwkMtQaj+GazhktFgGTUc=
github.com/archdx/zerolog-sentry v1.8.4/go.mod h1:XrFHGe1CH5DQk/XSySu/IJSi5C9XR6+zpc97zVf/c4c=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
Expand All @@ -96,8 +96,8 @@ github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
github.com/aws/aws-sdk-go v1.30.11/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.30.25/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.35.7/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
github.com/aws/aws-sdk-go v1.50.16 h1:/KuHK+Sadp9BKXWWtMhPtBdj+PLIFCnQZxQnsuLhxKc=
github.com/aws/aws-sdk-go v1.50.16/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down Expand Up @@ -570,8 +570,8 @@ github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/redhatinsights/app-common-go v1.6.8 h1:hyExMp6WHprlGkHKElQvSFF2ZPX8XTW6X+54PLLyUv0=
github.com/redhatinsights/app-common-go v1.6.8/go.mod h1:KW0BK+bnhp3kXU8BFwebQXqCqjdkcRewZsDlXCSNMyo=
github.com/redis/go-redis/v9 v9.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk=
github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
Expand Down
8 changes: 5 additions & 3 deletions producer/payload_tracker_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ func (producer *PayloadTrackerProducer) TrackPayload(

_, _, err := producer.produceMessage(statusUpdate)
if err != nil {
log.Error().Err(err).Msgf(
"unable to produce payload tracker message (request ID: '%s', timestamp: %v, status: '%s')",
reqID, timestamp, status)
log.Error().Err(err).
Str("request ID", string(reqID)).
Time("timestamp", timestamp).
Str("status", status).
Msg("unable to produce payload tracker message")

return err
}
Expand Down
2 changes: 1 addition & 1 deletion server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (server *HTTPServer) GetCurrentUserID(request *http.Request) (types.UserID,
i := request.Context().Value(types.ContextKeyUser)

if i == nil {
log.Error().Msgf("user id was not found in request's context")
log.Error().Msg("user id was not found in request's context")
return "", &UnauthorizedError{ErrString: "user id is not provided"}
}

Expand Down
13 changes: 10 additions & 3 deletions server/dvo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (server *HTTPServer) getWorkloadsForNamespace(writer http.ResponseWriter, r
func (server *HTTPServer) ProcessSingleDVONamespace(workload types.DVOReport) (
processedWorkloads WorkloadsForCluster,
) {
firstBytesStr := "first bytes"
processedWorkloads = WorkloadsForCluster{
Cluster: types.Cluster{
UUID: workload.ClusterID,
Expand All @@ -221,21 +222,27 @@ func (server *HTTPServer) ProcessSingleDVONamespace(workload types.DVOReport) (
// and also take care of the escaped `\"` quotes and replaces them with valid `"`, producing a valid JSON
err := json.Unmarshal(json.RawMessage(workload.Report), &report)
if err != nil {
log.Error().Err(err).Msgf("report has unknown structure: [%v]", string([]rune(workload.Report)[:100]))
log.Error().Err(err).
Str(firstBytesStr, string([]rune(workload.Report)[:100])).
Msg("report has unknown structure")
}
case `{`:
// we're dealing with either a valid JSON `{"system":{}}` or a string with escaped
// quotes `{\"system\":{}}`. Stripping escape chars `\` if any, produces a valid JSON
report = strings.Replace(workload.Report, `\`, "", -1)
default:
log.Error().Msgf("report has unknown structure: [%v]", string([]rune(workload.Report)[:100]))
log.Error().
Str(firstBytesStr, string([]rune(workload.Report)[:100])).
Msg("report has unknown structure")
return
}

var dvoReport types.DVOMetrics
err := json.Unmarshal([]byte(report), &dvoReport)
if err != nil {
log.Error().Err(err).Msgf("error unmarshalling full report: [%v]", string([]rune(report)[:100]))
log.Error().
Str(firstBytesStr, string([]rune(report)[:100])).
Msg("error unmarshalling full report")
log.Info().Msgf("report without escape %v", string([]rune(workload.Report)[:100]))
return
}
Expand Down
2 changes: 1 addition & 1 deletion server/rating.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (server *HTTPServer) getRuleRating(writer http.ResponseWriter, request *htt

rating, err := server.Storage.GetRuleRating(orgID, ruleSelector)
if err != nil {
log.Error().Err(err).Msg("Unable to get rating")
log.Warn().Err(err).Msg("Unable to get rating")
handleServerError(writer, err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (server *HTTPServer) readReportForCluster(writer http.ResponseWriter, reque
clusterName,
)
if err != nil {
log.Error().Err(err).Msgf("Unable to read report for cluster %v", clusterName)
log.Warn().Err(err).Str("cluster", string(clusterName)).Msg("Unable to read report for cluster")
handleServerError(writer, err)
return
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func (server *HTTPServer) readReportMetainfoForCluster(writer http.ResponseWrite
clusterName,
)
if err != nil {
log.Error().Err(err).Msg("Unable to read report for cluster")
log.Warn().Err(err).Msg("Unable to read report for cluster")
handleServerError(writer, err)
return
}
Expand Down
12 changes: 7 additions & 5 deletions storage/dvo_recommendations_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,23 @@ func (storage DVORecommendationsDBStorage) updateReport(
// Get reported_at if present before deletion
reportedAtMap, err := storage.getReportedAtMap(orgID, clusterName)
if err != nil {
log.Error().Err(err).Msgf("Unable to get dvo report reported_at")
log.Error().Err(err).Msg("Unable to get dvo report reported_at")
reportedAtMap = make(map[string]types.Timestamp) // create empty map
}

// Delete previous reports (CCXDEV-12529)
_, err = tx.Exec("DELETE FROM dvo.dvo_report WHERE org_id = $1 AND cluster_id = $2;", orgID, clusterName)
if err != nil {
log.Err(err).Msgf("Unable to remove previous cluster DVO reports (org: %v, cluster: %v)", orgID, clusterName)
log.Err(err).
Str(clusterKey, string(clusterName)).Interface(orgIDStr, orgID).
Msg("Unable to remove previous cluster DVO reports")
return err
}

if len(recommendations) == 0 {
log.Info().Msgf("No new DVO report to insert (org: %v, cluster: %v)",
orgID, clusterName,
)
log.Info().
Str(clusterKey, string(clusterName)).Interface(orgIDStr, orgID).
Msg("No new DVO report to insert")
return nil
}

Expand Down
28 changes: 17 additions & 11 deletions storage/ocp_recommendations_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func (storage OCPRecommendationsDBStorage) ReadReportForCluster(

err = types.ConvertDBError(err, []interface{}{orgID, clusterName})
if err != nil {
log.Error().Err(err).Str(clusterKey, string(clusterName)).Msg(
log.Warn().Err(err).Str(clusterKey, string(clusterName)).Msg(
"ReadReportForCluster query from report table error",
)
return report, lastCheckedStr, reportedAtStr, gatheredAtStr, err
Expand Down Expand Up @@ -983,14 +983,16 @@ func (storage OCPRecommendationsDBStorage) updateReport(
"rule_hit", orgID, clusterName,
)
if err != nil {
log.Error().Err(err).Msgf("Unable to get recommendation impacted_since")
log.Error().Err(err).Msg("Unable to get recommendation impacted_since")
RuleKeyCreatedAt = make(map[string]types.Timestamp) // create empty map
}

deleteQuery := "DELETE FROM rule_hit WHERE org_id = $1 AND cluster_id = $2;"
_, err = tx.Exec(deleteQuery, orgID, clusterName)
if err != nil {
log.Err(err).Msgf("Unable to remove previous cluster reports (org: %v, cluster: %v)", orgID, clusterName)
log.Err(err).
Str(clusterKey, string(clusterName)).Interface(orgIDStr, orgID).
Msg("Unable to remove previous cluster reports")
return err
}

Expand All @@ -1006,9 +1008,9 @@ func (storage OCPRecommendationsDBStorage) updateReport(

_, err = tx.Exec(ruleInsertStatement, values...)
if err != nil {
log.Err(err).Msgf("Unable to insert the cluster report rules (org: %v, cluster: %v)",
orgID, clusterName,
)
log.Err(err).
Str(clusterKey, string(clusterName)).Interface(orgIDStr, orgID).
Msg("Unable to insert the cluster report rules")
return err
}
}
Expand All @@ -1020,7 +1022,9 @@ func (storage OCPRecommendationsDBStorage) updateReport(
}

if err != nil {
log.Err(err).Msgf("Unable to upsert the cluster report (org: %v, cluster: %v)", orgID, clusterName)
log.Err(err).
Str(clusterKey, string(clusterName)).Interface(orgIDStr, orgID).
Msg("Unable to upsert the cluster report")
return err
}

Expand Down Expand Up @@ -1234,7 +1238,7 @@ func (storage OCPRecommendationsDBStorage) WriteRecommendationsForCluster(
impactedSinceMap, err = storage.getRuleKeyCreatedAtMapForTable(
"recommendation", orgID, clusterName)
if err != nil {
log.Error().Err(err).Msgf("Unable to get recommendation impacted_since")
log.Error().Err(err).Msg("Unable to get recommendation impacted_since")
}
// it is needed to use `org_id = $1` condition there
// because it allows DB to use proper btree indexing
Expand All @@ -1243,7 +1247,9 @@ func (storage OCPRecommendationsDBStorage) WriteRecommendationsForCluster(
"DELETE FROM recommendation WHERE org_id = $1 AND cluster_id = $2;", orgID, clusterName)
err = types.ConvertDBError(err, []interface{}{clusterName})
if err != nil {
log.Error().Err(err).Msgf("Unable to delete the existing recommendations for %s", clusterName)
log.Error().Err(err).
Str(clusterKey, string(clusterName)).Interface(orgIDStr, orgID).
Msg("Unable to delete the existing recommendations")
return err
}

Expand Down Expand Up @@ -1288,12 +1294,12 @@ func finishTransaction(tx *sql.Tx, err error) {
if err != nil {
rollbackError := tx.Rollback()
if rollbackError != nil {
log.Err(rollbackError).Msgf("error when trying to rollback a transaction")
log.Err(rollbackError).Msg("error when trying to rollback a transaction")
}
} else {
commitError := tx.Commit()
if commitError != nil {
log.Err(commitError).Msgf("error when trying to commit a transaction")
log.Err(commitError).Msg("error when trying to commit a transaction")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func regexGetNthMatchOrLogError(regexStr string, nMatch uint, str string) string
log.Error().
Str("regex", regexStr).
Str("str", str).
Msgf("unable to get first match from string '%v' with regex '%v'", str, regexStr)
Msg("unable to get first match from string")
return ""
}

Expand Down

0 comments on commit da4b734

Please sign in to comment.