Increase status report messages time resolution

We use DATETIME SQL type for created/updated columns
everywhere through the database. In SQL standard
DATETIME defaults to DATETIME(6) which is 6 digit
fraction second part. However MySQL defaults it
to DATETIME(0) for backward compatibility. In result
status messages timestamps get rounded to the
second boundary and if there are several status
messages were generated within a second
after table sort they might be shown in a different
order.

This commit adds MySQL migration that increases
resolution for the status table and adds subseconds
to the generated status repor timestamps.

Change-Id: Ice8c2d82c6a320c7f73c27f4c60c87bef55b8d95
Related-Bug: #1462270
This commit is contained in:
Stan Lagun 2016-04-29 00:33:34 -07:00
parent 21d10e4b7f
commit 89a4c4cb5a
2 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,61 @@
# Copyright 2016 OpenStack Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Increase time resolution for status reports
Revision ID: 014
Create Date: 2016-04-28
"""
# revision identifiers, used by Alembic.
revision = '014'
down_revision = '013'
from alembic import op
import sqlalchemy.dialects.mysql as sa_mysql
MYSQL_ENGINE = 'InnoDB'
MYSQL_CHARSET = 'utf8'
def _check_dbms(engine):
dialect = engine.dialect.dialect_description
version = engine.dialect.server_version_info
if dialect.startswith('mysql') and version >= (5, 6, 4):
return True
if 'MariaDB' in version and version >= (5, 3):
return True
return False
def upgrade():
engine = op.get_bind()
if _check_dbms(engine):
with op.batch_alter_table('status') as batch_op:
batch_op.alter_column(
'created', type_=sa_mysql.DATETIME(fsp=6), nullable=False)
batch_op.alter_column(
'updated', type_=sa_mysql.DATETIME(fsp=6), nullable=False)
def downgrade():
engine = op.get_bind()
if _check_dbms(engine):
with op.batch_alter_table('status') as batch_op:
batch_op.alter_column(
'created', type_=sa_mysql.DATETIME(), nullable=False)
batch_op.alter_column(
'updated', type_=sa_mysql.DATETIME(), nullable=False)

View File

@ -49,7 +49,7 @@ class StatusReporter(object):
'details': details,
'level': level,
'environment_id': self._environment_id,
'timestamp': timeutils.isotime()
'timestamp': timeutils.isotime(subsecond=True)
}
self._notifier.info({}, 'murano.report_notification', body)