Permalink
Browse files

add in es and start a resource

  • Loading branch information...
1 parent 6fd41a3 commit 23ae3e1e9c2e424cf5bf912216db94d8a816f7d7 @andymckay andymckay committed Dec 28, 2012
View
No changes.
@@ -0,0 +1,22 @@
+[
+ {
+ "pk": 1,
+ "model": "metrics.metric",
+ "fields": {
+ "date": "2009-07-15",
+ "value": 5,
+ "name": "addons.downloads.count",
+ "key": ""
+ }
+ },
+ {
+ "pk": 2,
+ "model": "metrics.metric",
+ "fields": {
+ "date": "2009-07-15",
+ "value": 1305,
+ "name": "addons.downloads.count.addon",
+ "key": "722"
+ }
+ }
+]
No changes.
No changes.
@@ -0,0 +1,40 @@
+from optparse import make_option
+
+from django.core.management.base import BaseCommand
+
+from elasticutils import get_es
+
+class Command(BaseCommand):
+
+ option_list = BaseCommand.option_list + (
+ make_option('--delete', action='store_true', default=False,
+ dest='delete', help='Delete the index.'),
+ )
+
+ def handle(self, *args, **options):
+ conn = get_es()
+ if options.get('delete'):
+ conn.delete_index('monolith')
+ conn.create_index('monolith')
+ mapping = {
+ 'name': {
+ 'store': 'yes',
+ 'type': 'string',
+ },
+ 'date': {
+ 'store': 'yes',
+ 'type': 'date',
+ 'format': 'yyyy-MM-dd',
+ },
+ 'key': {
+ 'store': 'yes',
+ 'type': 'string',
+ },
+ 'value': {
+ 'store': 'yes',
+ 'type': 'integer',
+ }
+ }
+ conn.put_mapping('metrics',
+ {'properties': mapping},
+ ['monolith'])
View
@@ -0,0 +1,22 @@
+from django.db import models
+from elasticutils import get_es
+
+
+class Metric(models.Model):
+ date = models.DateField(db_index=True)
+ key = models.CharField(max_length=255, db_index=True)
+ name = models.CharField(max_length=255, db_index=True)
+ value = models.IntegerField(db_index=True)
+
+ class Meta:
+ db_table = 'metric'
+
+ def index(self):
+ conn = get_es()
+ data = {
+ 'date': self.date.strftime('%Y-%m-%d'),
+ 'key': self.key,
+ 'name': self.name,
+ 'value': self.value
+ }
+ conn.index(data, 'monolith', 'metrics/%s/' % self.pk)
View
@@ -0,0 +1,7 @@
+from tastypie.resources import Resource
+
+
+class ESResource(Resource):
+
+ class Meta:
+ resource_name = 'query'
View
@@ -0,0 +1,11 @@
+from django import test
+from metrics.models import Metric
+
+from nose.tools import eq_
+
+
+class TestMetrics(test.TestCase):
+ fixtures = ['metrics.json']
+
+ def test_metrics(self):
+ eq_(len(Metric.objects.filter(name='addons.downloads.count')), 1)
View
@@ -12,69 +12,40 @@
# Defines the views served for root URLs.
ROOT_URLCONF = '%s.urls' % PROJECT_MODULE
-INSTALLED_APPS = list(INSTALLED_APPS) + [
- # Application base, containing global templates.
- '%s.base' % PROJECT_MODULE,
- # Example code. Can (and should) be removed for actual projects.
- '%s.examples' % PROJECT_MODULE,
+INSTALLED_APPS = [
+ 'funfactory',
+ 'django_nose',
+ 'django_statsd',
+ 'monolith',
+ # Now our custom stuff.
+ 'metrics',
]
-LOCALE_PATHS = (
- os.path.join(ROOT, PROJECT_MODULE, 'locale'),
-)
-
-# Because Jinja2 is the default template loader, add any non-Jinja templated
-# apps here:
-JINGO_EXCLUDE_APPS = [
- 'admin',
- 'registration',
-]
+USE_I18N = False
+USE_L10N = False
-# BrowserID configuration
-AUTHENTICATION_BACKENDS = [
- 'django_browserid.auth.BrowserIDBackend',
- 'django.contrib.auth.backends.ModelBackend',
-]
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+)
+JINJA_CONFIG = lambda: ''
SITE_URL = 'http://127.0.0.1:8000'
LOGIN_URL = '/'
-LOGIN_REDIRECT_URL = 'examples.home'
-LOGIN_REDIRECT_URL_FAILURE = 'examples.home'
-
-TEMPLATE_CONTEXT_PROCESSORS = list(TEMPLATE_CONTEXT_PROCESSORS) + [
- 'django_browserid.context_processors.browserid_form',
-]
# Should robots.txt deny everything or disallow a calculated list of URLs we
# don't want to be crawled? Default is false, disallow everything.
# Also see http://www.google.com/support/webmasters/bin/answer.py?answer=93710
ENGAGE_ROBOTS = False
-# Always generate a CSRF token for anonymous users.
-ANON_ALWAYS = True
-
-# Tells the extract script what files to look for L10n in and what function
-# handles the extraction. The Tower library expects this.
-DOMAIN_METHODS['messages'] = [
- ('%s/**.py' % PROJECT_MODULE,
- 'tower.management.commands.extract.extract_tower_python'),
- ('%s/**/templates/**.html' % PROJECT_MODULE,
- 'tower.management.commands.extract.extract_tower_template'),
- ('templates/**.html',
- 'tower.management.commands.extract.extract_tower_template'),
-]
-
-# # Use this if you have localizable HTML files:
-# DOMAIN_METHODS['lhtml'] = [
-# ('**/templates/**.lhtml',
-# 'tower.management.commands.extract.extract_tower_template'),
-# ]
-
-# # Use this if you have localizable JS files:
-# DOMAIN_METHODS['javascript'] = [
-# # Make sure that this won't pull in strings from external libraries you
-# # may use.
-# ('media/js/**.js', 'javascript'),
-# ]
+MIDDLEWARE_CLASSES = (
+ 'django_statsd.middleware.GraphiteMiddleware',
+)
LOGGING = dict(loggers=dict(playdoh = {'level': logging.DEBUG}))
+
+ES_DUMP_CURL = '/tmp/curl_dump.log'
+ES_HOSTS = ['127.0.0.1:9200']
+ES_INDEXES = {
+ 'default': 'monolith'
+}
@@ -0,0 +1 @@
+An error occured in monolith.
@@ -0,0 +1 @@
+A home page in monolith.
View
@@ -1,35 +1,15 @@
-from django.conf import settings
-from django.conf.urls.defaults import patterns, include
-from django.contrib.staticfiles.urls import staticfiles_urlpatterns
+from django.conf.urls.defaults import include, patterns, url
-from .examples import urls
+from tastypie.api import Api
-from funfactory.monkeypatches import patch
-patch()
+from metrics.resources import ESResource
-# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
+api = Api(api_name='query')
+api.register(ESResource())
urlpatterns = patterns('',
- # Example:
- (r'', include(urls)),
-
- # Generate a robots.txt
- (r'^robots\.txt$',
- lambda r: HttpResponse(
- "User-agent: *\n%s: /" % 'Allow' if settings.ENGAGE_ROBOTS else 'Disallow' ,
- mimetype="text/plain"
- )
- )
-
- # Uncomment the admin/doc line below to enable admin documentation:
- # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
-
- # Uncomment the next line to enable the admin:
- # (r'^admin/', include(admin.site.urls)),
+ url(r'^', include(api.urls)),
+ url(r'^$', 'monolith.views.home', name='home'),
)
-## In DEBUG mode, serve media files through Django.
-if settings.DEBUG:
- urlpatterns += staticfiles_urlpatterns()
+handler500 = handler404 = handler403 = 'monolith.views.error'
View
@@ -0,0 +1,9 @@
+from django.shortcuts import render_to_response
+
+
+def home(request):
+ return render_to_response('home.html')
+
+
+def error(request):
+ return render_to_response('error.html')
View
@@ -1,12 +1,16 @@
Django==1.4.3
+django-multidb-router==0.5
django-nose==1.1
+django-sha2==0.4
django-statsd-mozilla==0.3.8.3
django-tastypie==0.9.11
+elasticutils==0.5
funfactory==2.1.1
gunicorn==0.15.0
importlib==1.0.2
mock==1.0b1
nose==1.2.1
+pyes<=0.17
python-memcached==1.48
raven==2.0.10
requests==0.14.1
@@ -15,6 +19,5 @@ six==1.2.0
statsd==1.0.0
# not on pypi
--e git+https://github.com/fwenzel/django-sha2.git@f4519bf0cc9b1dd7a7d78394fa4aec4504bc86e9#egg=django-sha2
-e git+https://github.com/mozilla/nuggets.git@96e80a64aa4bfcfef4f43fc3ab6966450ccd7325#egg=nuggets
--e git+https://github.com/jbalogh/test-utils.git@3c2214d193d1b0c0d74c77b3731c8afb0173e669#egg=test-utils
+-e git+https://github.com/andymckay/test-utils.git@263cbb6aaee6ceff75155eb7f3a4b7afc5b47433#egg=test-utils

0 comments on commit 23ae3e1

Please sign in to comment.