Skip to content

Instantly share code, notes, and snippets.

@adngdb
Created April 3, 2015 14:09
Show Gist options
  • Save adngdb/b74c1d8906903b4a3842 to your computer and use it in GitHub Desktop.
Save adngdb/b74c1d8906903b4a3842 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""This app inserts a set of fake crash reports into elasticsearch, based
on date parameters.
This app can be invoked like this:
.../scripts/populate_elasticsearch_app.py --help
set your path to make that simpler
set both socorro and configman in your PYTHONPATH
"""
import json
import pyelasticsearch
import uuid
from configman import Namespace
from socorro.app import generic_app
from socorro.external.elasticsearch.crashstorage import (
ElasticSearchCrashStorage
)
from socorro.lib.datetimeutil import utc_now
class PopulateElasticsearch(generic_app.App):
app_name = 'populate_elasticsearch'
app_version = '0.1'
app_description = __doc__
required_config = Namespace()
required_config.add_option(
'elasticsearch_storage_class',
default=ElasticSearchCrashStorage,
doc='The class to use to store crash reports in elasticsearch.'
)
required_config.add_option(
'processed_crash_file',
default='./testcrash/processed_crash.json',
doc='The base file containing the processed crash.'
)
required_config.add_option(
'raw_crash_file',
default='./testcrash/raw_crash.json',
doc='The base file containing the raw crash.'
)
required_config.add_option(
'date',
default=utc_now().isoformat(),
doc='When to insert that data.'
)
def main(self):
storage = self.config.elasticsearch_storage_class(self.config)
processed_crash_file = open(self.config.processed_crash_file)
processed_crash = json.load(processed_crash_file)
raw_crash_file = open(self.config.raw_crash_file)
raw_crash = json.load(raw_crash_file)
date = self.config.date
for i in range(100):
crash = dict(
processed_crash,
uuid=uuid.uuid4().hex,
signature='FakeSignature1',
product='WaterWolf',
version='3.1b1',
date_processed=date,
os_name='Windows NT',
app_notes='some things collector blabla',
)
raw = dict(
raw_crash,
# PluginHang=0,
)
# storage.save_processed(crash)
storage.save_raw_and_processed(
raw,
None,
crash,
crash['uuid']
)
crash = dict(
processed_crash,
uuid=uuid.uuid4().hex,
signature='FakeSignature2',
product='WaterWolf',
version='4.0a2',
date_processed=date,
os_name='Mac OS X',
user_comments='meow',
)
raw = dict(
raw_crash,
PluginHang=1,
)
# storage.save_processed(crash)
storage.save_raw_and_processed(
raw,
None,
crash,
crash['uuid']
)
crash = dict(
processed_crash,
uuid=uuid.uuid4().hex,
signature='FakeSignature3',
product='NightTrain',
version='2.1',
date_processed=date,
email='[email protected]',
user_comments='boooh!',
)
# storage.save_processed(crash)
storage.save_raw_and_processed(
raw_crash,
None,
crash,
crash['uuid']
)
if __name__ == '__main__':
generic_app.main(PopulateElasticsearch)
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment