Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

chore(worker): move event_logs janitor routines to worker#63981

Merged
stefanhengl merged 6 commits into
mainfrom
sh/move-event-logs-jobs
Jul 23, 2024
Merged

chore(worker): move event_logs janitor routines to worker#63981
stefanhengl merged 6 commits into
mainfrom
sh/move-event-logs-jobs

Conversation

@stefanhengl

@stefanhengl stefanhengl commented Jul 22, 2024

Copy link
Copy Markdown
Member

This moves the janitor jobs for event logs from frontend to worker.

Next up: move the other recurring jobs as well.

Test plan

  • new unit tests
  • manual testing: the worker dashboard showed the job is running

This moves the janitor jobs for event logs
from frontend to the worker.

Test plan:
- new unit test
Comment on lines +21 to +36
// Only clean up if security event logs are being stored in the database.
c := conf.Get()
if c.Log == nil || c.Log.SecurityEventLog == nil {
return nil
}
if c.Log.SecurityEventLog.Location != "database" && c.Log.SecurityEventLog.Location != "all" {
return nil
}

// We choose 30 days as the interval to ensure that we have at least the last month's worth of
// logs at all times.
_, err := db.ExecContext(
ctx,
`DELETE FROM security_event_logs WHERE "timestamp" < now() - interval '30' day`,
)
return err

Check notice

Code scanning / Semgrep OSS

Semgrep Finding: security-semgrep-rules.semgrep-rules.generic.comment-tagging-rule

Code that highlight SECURITY in comment has changed. Please review the code for changes. The changes might be sensitive.
@cla-bot cla-bot Bot added the cla-signed label Jul 22, 2024
@github-actions github-actions Bot added team/product-platform team/search-platform Issues owned by the search platform team labels Jul 22, 2024
@stefanhengl stefanhengl changed the title chore(worker): move event log janitor routines to worker chore(worker): move event_logs janitor routines to worker Jul 22, 2024
@stefanhengl stefanhengl requested a review from eseliger July 22, 2024 13:58
@stefanhengl stefanhengl marked this pull request as ready for review July 22, 2024 13:58
Comment thread cmd/worker/internal/eventlogs/job.go Outdated
"github.com/sourcegraph/sourcegraph/internal/metrics"

workerdb "github.com/sourcegraph/sourcegraph/cmd/worker/shared/init/db"
"github.com/sourcegraph/sourcegraph/internal/bg"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we move this package under cmd/worker/internal/eventlogs/? It's only imported here, and by being under a specific cmd/X directory, it is very obvious to someone reading the code which service will run this.

Comment on lines +21 to +36
// Only clean up if security event logs are being stored in the database.
c := conf.Get()
if c.Log == nil || c.Log.SecurityEventLog == nil {
return nil
}
if c.Log.SecurityEventLog.Location != "database" && c.Log.SecurityEventLog.Location != "all" {
return nil
}

// We choose 30 days as the interval to ensure that we have at least the last month's worth of
// logs at all times.
_, err := db.ExecContext(
ctx,
`DELETE FROM security_event_logs WHERE "timestamp" < now() - interval '30' day`,
)
return err

Check notice

Code scanning / Semgrep OSS

Semgrep Finding: security-semgrep-rules.semgrep-rules.generic.comment-tagging-rule

Code that highlight SECURITY in comment has changed. Please review the code for changes. The changes might be sensitive.
@stefanhengl stefanhengl merged commit 8f70552 into main Jul 23, 2024
@stefanhengl stefanhengl deleted the sh/move-event-logs-jobs branch July 23, 2024 07:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/product-platform team/search-platform Issues owned by the search platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants