Skip to content

Commit

Permalink
bug 826564 Add exploitability to reports_clean
Browse files Browse the repository at this point in the history
  • Loading branch information
selenamarie committed Jun 5, 2013
1 parent d159933 commit 229eb56
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 5 deletions.
85 changes: 85 additions & 0 deletions alembic/versions/9798b1cc04_bug_826564_add_explo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""bug 826564 - add exploitability to reports_clean
Revision ID: 9798b1cc04
Revises: 3805e9f77df4
Create Date: 2013-06-05 13:20:25.116074
"""

# revision identifiers, used by Alembic.
revision = '9798b1cc04'
down_revision = '3805e9f77df4'

import os
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy import types
from sqlalchemy.sql import table, column
from sqlalchemy.dialects import postgresql

class CITEXT(types.UserDefinedType):
name = 'citext'

def get_col_spec(self):
return 'CITEXT'

def bind_processor(self, dialect):
def process(value):
return value
return process

def result_processor(self, dialect, coltype):
def process(value):
return value
return process

def __repr__(self):
return "citext"

class JSON(types.UserDefinedType):
name = 'json'

def get_col_spec(self):
return 'JSON'

def bind_processor(self, dialect):
def process(value):
return value
return process

def result_processor(self, dialect, coltype):
def process(value):
return value
return process

def __repr__(self):
return "json"

def upgrade():
op.create_table(u'exploitability_reports',
sa.Column(u'signature_id', sa.INTEGER(), nullable=False),
sa.Column(u'report_date', postgresql.TIMESTAMP(timezone=True), nullable=True),
sa.Column(u'null_count', sa.INTEGER(), server_default='0', nullable=False),
sa.Column(u'none_count', sa.INTEGER(), server_default='0', nullable=False),
sa.Column(u'low_count', sa.INTEGER(), server_default='0', nullable=False),
sa.Column(u'high_count', sa.INTEGER(), server_default='0', nullable=False),
sa.ForeignKeyConstraint(['signature_id'], [u'signatures.signature_id'], ),
sa.PrimaryKeyConstraint()
)
# We can probably get away with just applying this to the parent table
# If there are performance problems on stage, break this out and apply to all
# child partitions first, then reports_clean last.
op.add_column(u'reports_clean', sa.Column(u'exploitability', sa.TEXT(), nullable=True))
app_path=os.getcwd()
procs = [ '001_update_reports_clean.sql' ]
for myfile in [app_path + '/socorro/external/postgresql/raw_sql/procs/' + line for line in procs]:
proc = open(myfile, 'r').read()
op.execute(proc)


def downgrade():
op.drop_column(u'reports_clean', u'exploitability')
op.drop_table(u'exploitability_reports')
# Not rolling back 001_update_reports_clean.sql...
# if rolling back, need to pull out the old version and apply manually
16 changes: 16 additions & 0 deletions socorro/external/postgresql/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ class Extension(DeclarativeBase):

__mapper_args__ = {"primary_key":(report_id, date_processed, extension_key, extension_id, extension_version)}

class ExploitabilityReport(DeclarativeBase):
__tablename__ = 'exploitability_reports'

#column definitions
signature_id = Column(u'signature_id', INTEGER(), ForeignKey('signatures.signature_id'), nullable=False)
report_date = Column(u'report_date', TIMESTAMP(timezone=True))
null_count = Column(u'null_count', INTEGER(), nullable=False, server_default=text('0'))
none_count = Column(u'none_count', INTEGER(), nullable=False, server_default=text('0'))
low_count = Column(u'low_count', INTEGER(), nullable=False, server_default=text('0'))
high_count = Column(u'high_count', INTEGER(), nullable=False, server_default=text('0'))

exploitable_signature_idx = Index('exploitable_signature_date_idx', signature_id, report_date, unique=True)

__mapper_args__ = {"primary_key":(signature_id, report_date)}

class PluginsReport(DeclarativeBase):
__tablename__ = 'plugins_reports'

Expand Down Expand Up @@ -1111,6 +1126,7 @@ class ReportsClean(DeclarativeBase):
signature_id = Column(u'signature_id', INTEGER(), nullable=False)
uptime = Column(u'uptime', INTERVAL())
uuid = Column(u'uuid', TEXT(), primary_key=True, nullable=False)
exploitability = Column(u'exploitability', TEXT())

#relationship definitions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ as select uuid,
email, user_comments, url, app_notes,
release_channel, hangid as hang_id,
cpu_name as architecture,
get_cores(cpu_info) as cores
get_cores(cpu_info) as cores,
exploitability
from reports
where date_processed >= fromtime and date_processed < ( fromtime + fortime )
and completed_datetime is not null;
Expand Down Expand Up @@ -185,7 +186,8 @@ release_channel citext,
duplicate_of text,
domain_id int,
architecture citext,
cores int
cores int,
exploitability text
) on commit drop ;

-- populate the new buffer with uuid, date_processed,
Expand Down Expand Up @@ -218,7 +220,8 @@ SELECT new_reports.uuid,
reports_duplicates.duplicate_of,
domains.domain_id,
architecture,
cores
cores,
exploitability
FROM new_reports
LEFT OUTER JOIN release_channel_matches ON new_reports.release_channel ILIKE release_channel_matches.match_string
LEFT OUTER JOIN signatures ON new_reports.signature = signatures.signature
Expand Down Expand Up @@ -333,12 +336,12 @@ EXECUTE 'INSERT INTO ' || rc_part || '
build, signature_id, install_age, uptime,
reason_id, address_id, os_name, os_version_id,
hang_id, flash_version_id, process_type, release_channel,
duplicate_of, domain_id, architecture, cores )
duplicate_of, domain_id, architecture, cores, exploitability )
SELECT uuid, date_processed, client_crash_date, product_version_id,
build, signature_id, install_age, uptime,
reason_id, address_id, os_name, os_version_id,
hang_id, flash_version_id, process_type, release_channel,
duplicate_of, domain_id, architecture, cores
duplicate_of, domain_id, architecture, cores, exploitability
FROM reports_clean_buffer;';

IF analyze_it THEN
Expand Down

0 comments on commit 229eb56

Please sign in to comment.