Skip to content

Add abuse_trust_scores table

Ian Anderson requested to merge abuse-trust-scores into master

What does this MR do and why?

This MR adds a new table called abuse_trust_scores that will be used to save scores from various systems used to asses user behavior and trust. These scores will be used to automate actions against abusive users.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

  1. Run database migrations
  2. Create a new correlation ID for the rails session.
[5] pry(main)> Labkit::Correlation::CorrelationId.current_or_new_id
=> "27a0034a15f6ce26b61710039dd38d7a"
  1. Create an abuse_trust_score. The correlation ID should be automatically added when ommited.
[10] pry(main)> a = Abuse::TrustScore.create!(user_id: 3, source: :spamcheck, score: 0.25)
=> #<Abuse::TrustScore:0x00007f88a9124ab0
 id: 1,
 user_id: 3,
 source: "spamcheck",
 score: 0.25,
 created_at: Tue, 11 Apr 2023 18:01:49.181398888 UTC +00:00,
 updated_at: Tue, 11 Apr 2023 18:01:49.181398888 UTC +00:00,
 correlation_id_value: "27a0034a15f6ce26b61710039dd38d7a">
  1. Create an abuse_trust_score with a correlation ID. The correlation ID should not be overwritten.
[12] pry(main)> Abuse::TrustScore.create!(user_id: 3, source: :spamcheck, score: 0.25, correlation_id_value: "foobar")
=> #<Abuse::TrustScore:0x00007f88a9c36ea8 id: 2, user_id: 3, source: "spamcheck", score: 0.25, created_at: Tue, 11 Apr 2023 18:06:02.447461436 UTC +00:00, updated_at: Tue, 11 Apr 2023 18:06:02.447461436 UTC +00:00, correlation_id_value: "foobar">

Database Migrations

▶ rake db:migrate VERSION=20230411171001
WARNING: This version of GitLab depends on gitlab-shell 14.18.0, but you're running 14.17.0. Please update gitlab-shell.
main: == [advisory_lock_connection] object_id: 274560, pg_backend_pid: 1598742
main: == 20230411171001 CreateAbuseTrustScores: migrating ===========================
main: -- create_table(:abuse_trust_scores)
main: -- quote_column_name(:correlation_id_value)
main:    -> 0.0000s
main:    -> 0.0061s
main: == 20230411171001 CreateAbuseTrustScores: migrated (0.0437s) ==================

main: == [advisory_lock_connection] object_id: 274560, pg_backend_pid: 1598742
ci: == [advisory_lock_connection] object_id: 274840, pg_backend_pid: 1598744
ci: == 20230411171001 CreateAbuseTrustScores: migrating ===========================
ci: -- create_table(:abuse_trust_scores)
ci: -- quote_column_name(:correlation_id_value)
ci:    -> 0.0000s
ci:    -> 0.0052s
I, [2023-04-11T10:53:31.799072 #1598181]  INFO -- : Database: 'ci', Table: 'abuse_trust_scores': Lock Writes
ci: == 20230411171001 CreateAbuseTrustScores: migrated (0.0190s) ==================

ci: == [advisory_lock_connection] object_id: 274840, pg_backend_pid: 1598744


▶ rake db:migrate:down:main VERSION=20230411171001
WARNING: This version of GitLab depends on gitlab-shell 14.18.0, but you're running 14.17.0. Please update gitlab-shell.
main: == [advisory_lock_connection] object_id: 274340, pg_backend_pid: 1600450
main: == 20230411171001 CreateAbuseTrustScores: reverting ===========================
main: -- drop_table(:abuse_trust_scores)
main:    -> 0.0029s
main: == 20230411171001 CreateAbuseTrustScores: reverted (0.0099s) ==================

main: == [advisory_lock_connection] object_id: 274340, pg_backend_pid: 1600450

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports