Skip to content

Commit

Permalink
fix bug 972612 - use build_adu and crashes_madu, limit crashes to w
Browse files Browse the repository at this point in the history
ithin 7 days of build date r=selenamarie
  • Loading branch information
rhelmer committed Feb 15, 2014
1 parent a4ce4e3 commit 1f8d917
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
Expand Up @@ -25,9 +25,10 @@


def upgrade():
load_stored_proc(op, ['update_gccrashes.sql'])
load_stored_proc(op, ['crash_madu.sql', 'update_gccrashes.sql'])
op.execute(""" TRUNCATE gccrashes """)
op.alter_column(u'gccrashes', sa.Column(u'version_string', sa.REAL()))
op.alter_column(u'gccrashes', u'is_gc_count',
new_column_name=u'gc_count_madu', type_=sa.REAL())
now = datetime.datetime.utcnow()
for backfill_date in [
(now - datetime.timedelta(days=days)).strftime("%Y-%m-%d")
Expand All @@ -39,4 +40,6 @@ def upgrade():

def downgrade():
load_stored_proc(op, ['update_gccrashes.sql'])
op.alter_column(u'gccrashes', sa.Column(u'version_string', sa.INT()))
op.execute(""" DROP FUNCTION crash_madu(bigint, numeric, numeric) """)
op.alter_column(u'gccrashes', u'gc_count_madu',
new_column_name=u'is_gc_count', type_=sa.INT())
2 changes: 1 addition & 1 deletion socorro/external/postgresql/gccrashes.py
Expand Up @@ -33,7 +33,7 @@ def get(self, **kwargs):
/* socorro.external.postgresql.gccrashes.GCCrashes.get */
SELECT
build::text,
sum(is_gc_count)
sum(gc_count_madu)
FROM gccrashes
JOIN product_versions
USING (product_version_id)
Expand Down
4 changes: 2 additions & 2 deletions socorro/external/postgresql/models.py
Expand Up @@ -1469,10 +1469,10 @@ class GCCrashes(DeclarativeBase):
report_date = Column(u'report_date', TIMESTAMP(timezone=True), nullable=False)
product_version_id = Column(u'product_version_id', INTEGER(), nullable=False)
build = Column(u'build', NUMERIC(), nullable=True)
is_gc_count = Column(u'is_gc_count', NUMERIC(), nullable=False)
gc_count_madu = Column(u'gc_count_madu', REAL(), nullable=False)

__mapper_args__ = {"primary_key": (report_date, product_version_id, build,
is_gc_count)}
gc_count_madu)}

class RawUpdateChannel(DeclarativeBase):
""" Scraped information from reports table for release_channel/update_channel """
Expand Down
9 changes: 9 additions & 0 deletions socorro/external/postgresql/raw_sql/procs/crash_madu.sql
@@ -0,0 +1,9 @@
CREATE OR REPLACE FUNCTION crash_madu(crashes bigint, adu numeric, throttle numeric DEFAULT 1.0) RETURNS numeric
LANGUAGE sql
AS $_$
SELECT CASE WHEN $2 = 0 THEN 0::numeric
ELSE
round( ( $1 * 10^6::numeric / $2 ) / $3, 3)
END;
$_$;

12 changes: 7 additions & 5 deletions socorro/external/postgresql/raw_sql/procs/update_gccrashes.sql
Expand Up @@ -37,7 +37,7 @@ INSERT INTO gccrashes (
report_date,
product_version_id,
build,
is_gc_count
gc_count_madu
)
WITH raw_crash_filtered AS (
SELECT
Expand All @@ -52,16 +52,18 @@ WITH raw_crash_filtered AS (
SELECT updateday
, product_version_id
, build
, sum(CASE WHEN r.is_garbage_collecting = '1' THEN 1 ELSE 0 END)::real / sum(adu_count)::real as is_gc_count
, crash_madu(sum(CASE WHEN r.is_garbage_collecting = '1' THEN 1 ELSE 0 END), sum(adu_count), 1) as gc_count_madu
FROM reports_clean
JOIN product_versions USING (product_version_id)
JOIN product_adu USING (product_version_id)
JOIN build_adu USING (product_version_id)
LEFT JOIN raw_crash_filtered r ON r.uuid::text = reports_clean.uuid
WHERE utc_day_is(date_processed, updateday)
AND tstz_between(date_processed, build_date, sunset_date)
AND tstz_between(date_processed, build_date(build), sunset_date)
AND product_versions.build_type = 'nightly'
AND tstz_between(adu_date, build_date, sunset_date)
AND tstz_between(adu_date, build_date(build), sunset_date)
AND adu_count > 0
AND build_date(build) = build_adu.build_date
AND date_processed - build_date(build) < '7 days'::interval
GROUP BY build, product_version_id
ORDER BY build;

Expand Down
2 changes: 1 addition & 1 deletion socorro/unittest/external/postgresql/test_gccrashes.py
Expand Up @@ -114,7 +114,7 @@ def setUp(self):

cursor.execute("""
INSERT INTO gccrashes (report_date, product_version_id, build,
is_gc_count)
gc_count_madu)
VALUES
('%s', '%s', '%s', '%s'),
('%s', '%s', '%s', '%s'),
Expand Down

0 comments on commit 1f8d917

Please sign in to comment.