-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
log common errors to catalog for user acknowledgement
- Loading branch information
1 parent
7f97c00
commit 0a86a30
Showing
4 changed files
with
142 additions
and
85 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package activities | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log/slog" | ||
"time" | ||
|
||
"github.com/PeerDB-io/peer-flow/connectors" | ||
"github.com/PeerDB-io/peer-flow/connectors/utils/monitoring" | ||
"github.com/PeerDB-io/peer-flow/peerdbenv" | ||
) | ||
|
||
func (a *FlowableActivity) handleSlotInfo( | ||
ctx context.Context, | ||
srcConn connectors.CDCPullConnector, | ||
slotName string, | ||
peerName string, | ||
) error { | ||
slotInfo, err := srcConn.GetSlotInfo(slotName) | ||
if err != nil { | ||
slog.WarnContext(ctx, "warning: failed to get slot info", slog.Any("error", err)) | ||
return err | ||
} | ||
|
||
deploymentUIDPrefix := "" | ||
if peerdbenv.PeerDBDeploymentUID() != "" { | ||
deploymentUIDPrefix = fmt.Sprintf("[%s] ", peerdbenv.PeerDBDeploymentUID()) | ||
} | ||
|
||
slotLagInMBThreshold := peerdbenv.PeerDBSlotLagMBAlertThreshold() | ||
if (slotLagInMBThreshold > 0) && (slotInfo[0].LagInMb >= float32(slotLagInMBThreshold)) { | ||
a.Alerter.AlertIf(ctx, fmt.Sprintf("%s-slot-lag-threshold-exceeded", peerName), | ||
fmt.Sprintf(`%sSlot `+"`%s`"+` on peer `+"`%s`"+` has exceeded threshold size of %dMB, currently at %.2fMB! | ||
cc: <!channel>`, | ||
deploymentUIDPrefix, slotName, peerName, slotLagInMBThreshold, slotInfo[0].LagInMb)) | ||
} | ||
|
||
// Also handles alerts for PeerDB user connections exceeding a given limit here | ||
maxOpenConnectionsThreshold := peerdbenv.PeerDBOpenConnectionsAlertThreshold() | ||
res, err := srcConn.GetOpenConnectionsForUser() | ||
if err != nil { | ||
slog.WarnContext(ctx, "warning: failed to get current open connections", slog.Any("error", err)) | ||
return err | ||
} | ||
if (maxOpenConnectionsThreshold > 0) && (res.CurrentOpenConnections >= int64(maxOpenConnectionsThreshold)) { | ||
a.Alerter.AlertIf(ctx, fmt.Sprintf("%s-max-open-connections-threshold-exceeded", peerName), | ||
fmt.Sprintf(`%sOpen connections from PeerDB user `+"`%s`"+` on peer `+"`%s`"+ | ||
` has exceeded threshold size of %d connections, currently at %d connections! | ||
cc: <!channel>`, | ||
deploymentUIDPrefix, res.UserName, peerName, maxOpenConnectionsThreshold, res.CurrentOpenConnections)) | ||
} | ||
|
||
if len(slotInfo) != 0 { | ||
return monitoring.AppendSlotSizeInfo(ctx, a.CatalogPool, peerName, slotInfo[0]) | ||
} | ||
return nil | ||
} | ||
|
||
func (a *FlowableActivity) recordSlotSizePeriodically( | ||
ctx context.Context, | ||
srcConn connectors.CDCPullConnector, | ||
slotName string, | ||
peerName string, | ||
) { | ||
// ensures slot info is logged at least once per SyncFlow | ||
err := a.handleSlotInfo(ctx, srcConn, slotName, peerName) | ||
if err != nil { | ||
return | ||
} | ||
|
||
timeout := 5 * time.Minute | ||
ticker := time.NewTicker(timeout) | ||
|
||
defer ticker.Stop() | ||
for { | ||
select { | ||
case <-ticker.C: | ||
err := a.handleSlotInfo(ctx, srcConn, slotName, peerName) | ||
if err != nil { | ||
return | ||
} | ||
case <-ctx.Done(): | ||
return | ||
} | ||
ticker.Stop() | ||
ticker = time.NewTicker(timeout) | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE peerdb_state.alerts_v1 | ||
ADD COLUMN IF NOT EXISTS flow_name TEXT | ||
ADD COLUMN IF NOT EXISTS ack BOOLEAN DEFAULT FALSE; | ||
|
||
CREATE INDEX alerts_v1_flow_name_idx ON peerdb_state.alerts_v1 (flow_name); |