Skip to content

Commit

Permalink
Fix the cleanup routine.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszraczylo committed Jun 28, 2024
1 parent b10a28b commit 3467cc5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Creates a passthrough proxy to a graphql endpoint(s), allowing you to analyse the queries and responses, producing the Prometheus metrics at a fraction of the cost - because, as we know - $0 is a fair price.

This project is in active use by [telegram-bot.app](https://telegram-bot.app), and was tested with 30k queries per second on a single instance, consuming 10 MB of RAM and 0.1% CPU.
This project is in active use by [telegram-bot.app](https://telegram-bot.app), and was tested with 30k queries per second on a single instance, consuming 10 MB of RAM and 0.1% CPU. [Benchmarks](https://lukaszraczylo.github.io/graphql-monitoring-proxy/dev/bench/) are available.

![Example of monitoring dashboard](static/monitoring-at-glance.png?raw=true)

Expand Down
33 changes: 19 additions & 14 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const (
cleanupInterval = 1 * time.Hour
)

var delQueries = []string{
"DELETE FROM hdb_catalog.event_invocation_logs WHERE created_at < now() - interval '%d days';",
"DELETE FROM hdb_catalog.event_log WHERE created_at < now() - interval '%d days';",
var delQueries = [...]string{
"DELETE FROM hdb_catalog.event_invocation_logs WHERE created_at < NOW() - interval '%d days';",
"DELETE FROM hdb_catalog.event_log WHERE created_at < NOW() - interval '%d days';",
"DELETE FROM hdb_catalog.hdb_action_log WHERE created_at < NOW() - INTERVAL '%d days';",
"DELETE FROM hdb_catalog.hdb_cron_event_invocation_logs WHERE created_at < NOW() - INTERVAL '%d days';",
"DELETE FROM hdb_catalog.hdb_scheduled_event_invocation_logs WHERE created_at < NOW() - INTERVAL '%d days';",
Expand All @@ -39,17 +39,17 @@ func enableHasuraEventCleaner() {
Pairs: map[string]interface{}{"interval_in_days": cfg.HasuraEventCleaner.ClearOlderThan},
})

pool, err := pgxpool.New(context.Background(), cfg.HasuraEventCleaner.EventMetadataDb)
if err != nil {
cfg.Logger.Error(&libpack_logger.LogMessage{
Message: "Failed to create connection pool",
Pairs: map[string]interface{}{"error": err},
})
return
}
defer pool.Close()

go func() {
pool, err := pgxpool.New(context.Background(), cfg.HasuraEventCleaner.EventMetadataDb)
if err != nil {
cfg.Logger.Error(&libpack_logger.LogMessage{
Message: "Failed to create connection pool",
Pairs: map[string]interface{}{"error": err.Error()},
})
return
}
defer pool.Close()

time.Sleep(initialDelay)

cfg.Logger.Info(&libpack_logger.LogMessage{
Expand All @@ -76,7 +76,12 @@ func cleanEvents(pool *pgxpool.Pool) {
if err != nil {
cfg.Logger.Error(&libpack_logger.LogMessage{
Message: "Failed to execute query",
Pairs: map[string]interface{}{"query": query, "error": err},
Pairs: map[string]interface{}{"query": query, "error": err.Error()},
})
} else {
cfg.Logger.Debug(&libpack_logger.LogMessage{
Message: "Successfully executed query",
Pairs: map[string]interface{}{"query": query},
})
}
}
Expand Down

0 comments on commit 3467cc5

Please sign in to comment.