nanit / kubernetes-graphite-cluster

StatsD + Graphite cluster on top of Kubernetes
MIT License
77 stars 29 forks source link

First-run database migrations required #14

Closed vmrob closed 7 years ago

vmrob commented 7 years ago

I just set up a cluster per the recommendations here and found that I needed to set up the sqlite database for a first run lest specific queries fail such as graphite/metrics/find?query=*:

# curl graphite/metrics/find\?query=\*
<body style="background-color: #666666; color: black;">
<center>
<h2 style='font-family: "Arial", sans-serif'>
<p>Graphite encountered an unexpected error while handling your request.</p>
<p>Please contact your site administrator if the problem persists.</p>
</h2>
<br/>
<div style="width: 50%; text-align: center; font-family: monospace; background-color: black; font-weight: bold; color: #ff4422;">

</div>

<div style="width: 70%; text-align: left; background-color: black; color: #44ff22; border: thin solid gray;">
<pre>
Traceback (most recent call last):
  File &quot;/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py&quot;, line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File &quot;/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py&quot;, line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File &quot;/opt/graphite/webapp/graphite/metrics/views.py&quot;, line 150, in find_view
    profile = getProfile(request)
  File &quot;/opt/graphite/webapp/graphite/user_util.py&quot;, line 25, in getProfile
    return default_profile()
  File &quot;/opt/graphite/webapp/graphite/user_util.py&quot;, line 41, in default_profile
    &#39;password&#39;: &#39;!&#39;})
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py&quot;, line 122, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/models/query.py&quot;, line 465, in get_or_create
    return self.get(**lookup), False
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/models/query.py&quot;, line 381, in get
    num = len(clone)
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/models/query.py&quot;, line 240, in __len__
    self._fetch_all()
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/models/query.py&quot;, line 1074, in _fetch_all
    self._result_cache = list(self.iterator())
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/models/query.py&quot;, line 52, in __iter__
    results = compiler.execute_sql()
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py&quot;, line 848, in execute_sql
    cursor.execute(sql, params)
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py&quot;, line 64, in execute
    return self.cursor.execute(sql, params)
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/utils.py&quot;, line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py&quot;, line 64, in execute
    return self.cursor.execute(sql, params)
  File &quot;/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py&quot;, line 323, in execute
    return Database.Cursor.execute(self, query, params)
OperationalError: no such table: auth_user

</pre>
</div>

</center>

Luckily, it wasn't too difficult to figure out how to set up the schema for a first run:

PYTHONPATH=/opt/graphite/webapp django-admin.py migrate --settings=graphite.settings --run-syncdb

I'm going to propose that this be done immediately following the creation of the database file or inside a file missing or zero length test in the entry point.

erez-rabih commented 7 years ago

Thanks for reporting this, your issue should be fixed by https://github.com/nanit/kubernetes-graphite-cluster/commit/0a9c2d1a4dd2bd40c586e6bfaf54ff1597cd6d8e Please Re-Open if you still experience problems