"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "monasca_log_api/app/base/log_publisher.py" between
monasca-log-api-2.7.0.tar.gz and monasca-log-api-2.9.0.tar.gz

About: OpenStack Monasca Log API is a RESTful API server acting as gateway for logs collected from log-agents.
The "Stein" series (maintained release).

log_publisher.py  (monasca-log-api-2.7.0):log_publisher.py  (monasca-log-api-2.9.0)
skipping to change at line 22 skipping to change at line 22
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import time import time
import falcon import falcon
from monasca_common.kafka import producer from monasca_common.kafka import producer
from monasca_common.rest import utils as rest_utils from monasca_common.rest import utils as rest_utils
from oslo_log import log from oslo_log import log
from oslo_utils import encodeutils
from monasca_log_api.app.base import model from monasca_log_api.app.base import model
from monasca_log_api import conf from monasca_log_api import conf
from monasca_log_api.monitoring import client from monasca_log_api.monitoring import client
from monasca_log_api.monitoring import metrics from monasca_log_api.monitoring import metrics
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
CONF = conf.CONF CONF = conf.CONF
_RETRY_AFTER = 60 _RETRY_AFTER = 60
skipping to change at line 149 skipping to change at line 150
* truncating message if necessary * truncating message if necessary
(:py:func:`.LogPublisher._truncate`) (:py:func:`.LogPublisher._truncate`)
:param model.Envelope message: instance of message :param model.Envelope message: instance of message
:return: serialized message :return: serialized message
:rtype: str :rtype: str
""" """
if not self._is_message_valid(message): if not self._is_message_valid(message):
raise InvalidMessageException() raise InvalidMessageException()
truncated = self._truncate(message) truncated = self._truncate(message)
proper = self._ensure_type_bytes(truncated) return encodeutils.safe_encode(truncated, incoming='utf-8')
return proper
def _ensure_type_bytes(self, message):
"""Ensures that message will have proper type.
Kafka client expects that messages being
posted have certain data type (:py:func:`six.binary_type`).
This method ensures by the means of encoding that such type
will always be a case regardless if codebase runs under
:py:data:`six.PY2` or :py:data:`six.PY3`
"""
message = message.encode('utf-8')
return message
def _truncate(self, envelope): def _truncate(self, envelope):
"""Truncates the message if needed. """Truncates the message if needed.
Each message send to kafka is verified. Each message send to kafka is verified.
Method checks if message serialized to json Method checks if message serialized to json
exceeds maximum allowed size that can be posted to kafka exceeds maximum allowed size that can be posted to kafka
queue. If so, method truncates message property of the log queue. If so, method truncates message property of the log
by difference between message and allowed size. by difference between message and allowed size.
 End of changes. 2 change blocks. 
15 lines changed or deleted 2 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)