Skip to content

Commit

Permalink
fix: struct properties should be public to be parsed through pgx
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Aug 26, 2024
1 parent 89d30f1 commit 5b3e9fc
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions node/pkg/checker/dalstats/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ import (
)

const (
GetAllValidKeys = "SELECT * FROM keys"
GetAllValidKeys = "SELECT key, description FROM keys"

GetRestCallsPerKey = "SELECT COUNT(1) FROM rest_calls WHERE api_key = @key AND timestamp >= NOW() - interval '7 day'"
GetWebsocketConnectionsPerKey = "SELECT COUNT(1) FROM websocket_connections WHERE api_key = @key AND timestamp >= NOW() - interval '7 day'"
GetWebsocketSubscriptionsPerKey = "SELECT COUNT(1) FROM websocket_subscriptions WHERE connection_id IN (SELECT id FROM websocket_connections WHERE api_key = @key AND timestamp >= NOW() - interval '7 day')"
)

type DBKey struct {
ID int `db:"id"`
key string `db:"key"`
description *string `db:"description"`
Key string `db:"key"`
Description *string `db:"description"`
}

type Count struct {
count int `db:"count"`
Count int `db:"count"`
}

var skippingKeys = []string{"test", "sentinel", "orakl_reporter"}
Expand Down Expand Up @@ -79,27 +78,27 @@ func dalDBStats(ctx context.Context, dalDB *pgxpool.Pool) error {
msg := ""

for _, key := range keys {
if slices.Contains(skippingKeys, *key.description) {
if slices.Contains(skippingKeys, *key.Description) {
continue
}

restCalls, err := db.QueryRowTransient[Count](ctx, dalDB, GetRestCallsPerKey, map[string]interface{}{"key": key.key})
restCalls, err := db.QueryRowTransient[Count](ctx, dalDB, GetRestCallsPerKey, map[string]interface{}{"key": key.Key})
if err != nil {
log.Error().Err(err).Msg("Error getting rest calls")
return err
}
websocketConnections, err := db.QueryRowTransient[Count](ctx, dalDB, GetWebsocketConnectionsPerKey, map[string]interface{}{"key": key.key})
websocketConnections, err := db.QueryRowTransient[Count](ctx, dalDB, GetWebsocketConnectionsPerKey, map[string]interface{}{"key": key.Key})
if err != nil {
log.Error().Err(err).Msg("Error getting websocket connections")
return err
}
websocketSubscriptions, err := db.QueryRowTransient[Count](ctx, dalDB, GetWebsocketSubscriptionsPerKey, map[string]interface{}{"key": key.key})
websocketSubscriptions, err := db.QueryRowTransient[Count](ctx, dalDB, GetWebsocketSubscriptionsPerKey, map[string]interface{}{"key": key.Key})
if err != nil {
log.Error().Err(err).Msg("Error getting websocket subscriptions")
return err
}

msg += fmt.Sprintf("(DAL 7 days calls) client: %s, rest calls: %v, websocket connections: %v, websocket subscriptions: %v\n", *key.description, restCalls.count, websocketConnections.count, websocketSubscriptions.count)
msg += fmt.Sprintf("(DAL 7 days calls) client: %s, rest calls: %v, websocket connections: %v, websocket subscriptions: %v\n", *key.Description, restCalls.Count, websocketConnections.Count, websocketSubscriptions.Count)
}

if msg != "" {
Expand Down

0 comments on commit 5b3e9fc

Please sign in to comment.