monasca_log_api.v2.common package¶
Submodules¶
monasca_log_api.v2.common.error_handlers module¶
monasca_log_api.v2.common.log_publisher module¶
-
class
LogPublisher
[source]¶ Bases:
object
Publishes log data to Kafka
LogPublisher is able to send single message to multiple configured topic. It uses following configuration written in conf file
[log_publisher] topics = 'logs' kafka_url = 'localhost:8900'
- Note:
- Uses
monasca_common.kafka.producer.KafkaProducer
to ship logs to kafka. For more details see monasca_common github repository.
monasca_log_api.v2.common.model module¶
-
class
Envelope
(log, meta)[source]¶ Bases:
dict
-
creation_time
¶
-
log
¶
-
meta
¶
-
classmethod
new_envelope
(log, tenant_id, region, dimensions=None)[source]¶ Creates new log envelope
Log envelope is combined ouf of following properties
- log - dict
- creation_time - timestamp
- meta - meta block
Example output json would like this:
{ "log": { "message": "Some message", "dimensions": { "hostname": "devstack" } }, "creation_time": 1447834886, "meta": { "tenantId": "e4bd29509eda473092d32aadfee3e7b1", "region": "pl" } }
Parameters: - log (dict) – original log element (containing message and other params
- tenant_id (str) – tenant id to be put in meta field
- region (str) – region to be put in meta field
- dimensions (dict) – additional dimensions to be appended to log object dimensions
-
monasca_log_api.v2.common.validation module¶
-
APPLICATION_TYPE_CONSTRAINTS
= {'PATTERN': <_sre.SRE_Pattern object at 0x7f2275343350>, 'MAX_LENGTH': 255}¶ Application type constraint used in validation.
See
Validations.validate_application_type()
-
DIMENSION_NAME_CONSTRAINTS
= {'PATTERN': <_sre.SRE_Pattern object at 0x7f227531f9f0>, 'MAX_LENGTH': 255}¶ Constraint for name of single dimension.
See
Validations.validate_dimensions()
-
DIMENSION_VALUE_CONSTRAINTS
= {'MAX_LENGTH': 255}¶ Constraint for value of single dimension.
See
Validations.validate_dimensions()
-
validate_application_type
(application_type=None)[source]¶ Validates application type.
Validation won’t take place if application_type is None. For details see:
APPLICATION_TYPE_CONSTRAINTS
Parameters: application_type (str) – application type
-
validate_content_type
(req, allowed)[source]¶ Validates content type.
Method validates request against correct content type.
If content-type cannot be established (i.e. header is missing),
falcon.HTTPMissingHeader
is thrown. If content-type is not application/json or text/plain,falcon.HTTPUnsupportedMediaType
is thrown.Parameters: - req (falcon.Request) – current request
- allowed (iterable) – allowed content type
Exception: falcon.HTTPMissingHeader
Exception: falcon.HTTPUnsupportedMediaType
-
validate_dimensions
(dimensions)[source]¶ Validates dimensions type.
Empty dimensions are not being validated. For details see:
Parameters: dimensions (dict) – dimensions to validate
-
validate_log_message
(log_object)[source]¶ Validates log property.
Log property should have message property.
- Args:
- log_object (dict): log property
-
validate_payload_size
(req)[source]¶ Validates payload size.
Method validates sent payload size. It expects that http header Content-Length is present. If it does not, method raises
falcon.HTTPLengthRequired
. Otherwise values is being compared with[service] max_log_size = 1048576
max_log_size refers to the maximum allowed content length. If it is exceeded
falcon.HTTPRequestEntityTooLarge
is thrown.Parameters: req (falcon.Request) – current request Exception: falcon.HTTPLengthRequired
Exception: falcon.HTTPRequestEntityTooLarge