Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions shared/django_apps/test_analytics/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

from django.db import migrations, models

"""
BEGIN;
--
-- Create model Flake
--
CREATE TABLE "test_analytics_flake" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "repoid" integer NOT NULL, "test_id" bytea NOT NULL, "recent_passes_count" integer NOT NULL, "count" integer NOT NULL, "fail_count" integer NOT NULL, "start_date" timestamp with time zone NOT NULL, "end_date" timestamp with time zone NULL);
CREATE INDEX "test_analyt_repoid_fcd881_idx" ON "test_analytics_flake" ("repoid");
CREATE INDEX "test_analyt_test_id_f504a1_idx" ON "test_analytics_flake" ("test_id");
CREATE INDEX "test_analyt_repoid_0690c3_idx" ON "test_analytics_flake" ("repoid", "test_id");
CREATE INDEX "test_analyt_repoid_9e2402_idx" ON "test_analytics_flake" ("repoid", "end_date");
COMMIT;
"""


class Migration(migrations.Migration):
initial = True
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.16 on 2025-01-20 17:38

from django.db import migrations, models

"""
BEGIN;
--
-- Add field flags_id to flake
--
ALTER TABLE "test_analytics_flake" ADD COLUMN "flags_id" bytea NULL;
COMMIT;
"""


class Migration(migrations.Migration):
dependencies = [
("test_analytics", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="flake",
name="flags_id",
field=models.BinaryField(null=True),
),
]
1 change: 1 addition & 0 deletions shared/django_apps/test_analytics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Flake(models.Model):

repoid = models.IntegerField()
test_id = models.BinaryField()
flags_id = models.BinaryField(null=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

BinaryField. What kind of data do you plan to put there? Also noticing now that test_id is also a BinaryField. Will these hold (non-base16-encoded) hash values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, they're both has values. I think i can probably indicate it somehow with some sort of max length in the binary field but the test_id is meant to be 16 bytes and the flags_id is meant to be 8 bytes. they're both generated using mmh3 and they don't have any particular encoding hence: BinaryField. In BQ they're defined as BYTES fields

Copy link
Contributor

Choose a reason for hiding this comment

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

we have a normal index on repo_id and test_id, but are you planning on having any kind of uniqueness constraint based on the test_id or the flags_id?

it should be fine if both are still also dependent on the repo_id.

just thinking of that as I recently read https://orlp.net/blog/breaking-hash-functions/ which is a very well written post about how to trivially cause collisions of mmh3 and similar non cryptographic hash functions.
it would be really bad if one customer could mess with another customers data based on such trivially breakable hash values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think the uniqueness constraint should be on (repoid, test_id, flags_id) so that will isolate test_id collisions to a single customer. The mistake I made with the Test model previously is that the primary key was the test_id, which was all around a bad idea.

At least this strategy of isolating unique (test_id, flags_id) combinations to the repo means that one customer can't mess with another, however this still leaves an opening for open source repos (or any repo that doesn't protect its uploads) to be polluted. I'm not sure how to fix that problem.


recent_passes_count = models.IntegerField()
count = models.IntegerField()
Expand Down
Loading