Ejemplo n.º 1
0
    def on_post(self, req, res):
        validation.validate_cross_tenant(
            tenant_id=req.get_header(*headers.X_TENANT_ID),
            cross_tenant_id=req.get_param('tenant_id'),
            roles=req.get_header(*headers.X_ROLES)
        )
        validation.validate_payload_size(req)
        validation.validate_content_type(req, Logs.SUPPORTED_CONTENT_TYPES)

        cross_tenant_id = req.get_param('tenant_id')
        tenant_id = req.get_header(*headers.X_TENANT_ID)

        log = self.get_log(request=req)
        envelope = self.get_envelope(
            log=log,
            tenant_id=tenant_id if tenant_id else cross_tenant_id
        )

        self._kafka_publisher.send_message(envelope)

        res.status = falcon.HTTP_204
        res.add_link(
            target=str(_get_v3_link(req)),
            rel='current',  # [RFC5005]
            title='V3 Logs',
            type_hint='application/json'
        )
        res.append_header('DEPRECATED', 'true')
Ejemplo n.º 2
0
    def on_post(self, req, res):
        with self._logs_processing_time.time(name=None):
            try:
                validation.validate_payload_size(req)
                validation.validate_content_type(req,
                                                 Logs.SUPPORTED_CONTENT_TYPES)

                cross_tenant_id = req.get_param('tenant_id')
                tenant_id = req.get_header(*headers.X_TENANT_ID)

                validation.validate_cross_tenant(
                    tenant_id=tenant_id,
                    cross_tenant_id=cross_tenant_id,
                    roles=req.get_header(*headers.X_ROLES)
                )

                request_body = helpers.read_json_msg_body(req)

                log_list = self._get_logs(request_body)
                global_dimensions = self._get_global_dimensions(request_body)

            except Exception as ex:
                LOG.error('Entire bulk package has been rejected')
                LOG.exception(ex)

                self._bulks_rejected_counter.increment(value=1)

                raise ex

            self._bulks_rejected_counter.increment(value=0)
            self._logs_size_gauge.send(name=None,
                                       value=int(req.content_length))

            try:
                self._processor.send_message(
                    logs=log_list,
                    global_dimensions=global_dimensions,
                    log_tenant_id=tenant_id if tenant_id else cross_tenant_id
                )
            except Exception as ex:
                res.status = getattr(ex, 'status', falcon.HTTP_500)
                return

            res.status = falcon.HTTP_204
Ejemplo n.º 3
0
    def validate(self, content_types):
        """Performs common request validation

        Validation checklist (in that order):

        * :py:func:`validation.validate_content_type`
        * :py:func:`validation.validate_payload_size`
        * :py:func:`validation.validate_cross_tenant`

        :param content_types: allowed content-types handler supports
        :type content_types: list
        :raises Exception: if any of the validation fails

        """
        validation.validate_content_type(self, content_types)
        validation.validate_payload_size(self)
        validation.validate_cross_tenant(tenant_id=self.project_id,
                                         roles=self.roles,
                                         cross_tenant_id=self.cross_project_id)
Ejemplo n.º 4
0
    def on_post(self, req, res):
        validation.validate_payload_size(req)
        validation.validate_content_type(req, Logs.SUPPORTED_CONTENT_TYPES)

        cross_tenant_id = req.get_param('tenant_id')
        tenant_id = req.get_header(*headers.X_TENANT_ID)
        validation.validate_cross_tenant(
            tenant_id=tenant_id,
            cross_tenant_id=cross_tenant_id,
            roles=req.get_header(*headers.X_ROLES)
        )

        request_body = helpers.read_json_msg_body(req)
        log_list = self._get_logs(request_body)
        global_dimensions = self._get_global_dimensions(request_body)

        envelopes = []
        for log_element in log_list:
            try:
                LOG.trace('Processing log %s', log_element)

                validation.validate_log_message(log_element)

                dimensions = self._get_dimensions(log_element,
                                                  global_dimensions)
                envelope = self._create_log_envelope(tenant_id,
                                                     cross_tenant_id,
                                                     dimensions,
                                                     log_element)
                envelopes.append(envelope)

                LOG.trace('Log %s processed into envelope %s',
                          log_element,
                          envelope)
            except Exception as ex:
                LOG.error('Failed to process log %s', log_element)
                LOG.exception(ex)
                res.status = getattr(ex, 'status', falcon.HTTP_500)
                return

        self._send_logs(envelopes)
        res.status = falcon.HTTP_204
Ejemplo n.º 5
0
    def on_post(self, req, res):
        with self._logs_processing_time.time(name=None):
            try:
                validation.validate_payload_size(req)
                validation.validate_content_type(req,
                                                 Logs.SUPPORTED_CONTENT_TYPES)

                cross_tenant_id = req.get_param('tenant_id')
                tenant_id = req.get_header(*headers.X_TENANT_ID)

                validation.validate_cross_tenant(
                    tenant_id=tenant_id,
                    cross_tenant_id=cross_tenant_id,
                    roles=req.get_header(*headers.X_ROLES))

                request_body = helpers.read_json_msg_body(req)

                log_list = self._get_logs(request_body)
                global_dimensions = self._get_global_dimensions(request_body)

            except Exception as ex:
                LOG.error('Entire bulk package has been rejected')
                LOG.exception(ex)

                self._bulks_rejected_counter.increment(value=1)

                raise ex

            self._bulks_rejected_counter.increment(value=0)
            self._logs_size_gauge.send(name=None,
                                       value=int(req.content_length))

            try:
                self._processor.send_message(
                    logs=log_list,
                    global_dimensions=global_dimensions,
                    log_tenant_id=tenant_id if tenant_id else cross_tenant_id)
            except Exception as ex:
                res.status = getattr(ex, 'status', falcon.HTTP_500)
                return

            res.status = falcon.HTTP_204
Ejemplo n.º 6
0
    def on_post(self, req, res):
        with self._logs_processing_time.time(name=None):
            try:
                validation.validate_payload_size(req)
                validation.validate_content_type(req,
                                                 Logs.SUPPORTED_CONTENT_TYPES)
                validation.validate_cross_tenant(
                    tenant_id=req.get_header(*headers.X_TENANT_ID),
                    cross_tenant_id=req.get_param('tenant_id'),
                    roles=req.get_header(*headers.X_ROLES)
                )

                cross_tenant_id = req.get_param('tenant_id')
                tenant_id = req.get_header(*headers.X_TENANT_ID)

                log = self.get_log(request=req)
                envelope = self.get_envelope(
                    log=log,
                    tenant_id=tenant_id if tenant_id else cross_tenant_id
                )

                self._logs_size_gauge.send(name=None,
                                           value=int(req.content_length))
                self._logs_in_counter.increment()
            except Exception:
                # any validation that failed means
                # log is invalid and rejected
                self._logs_rejected_counter.increment()
                raise

            self._kafka_publisher.send_message(envelope)

            res.status = falcon.HTTP_204
            res.add_link(
                target=str(_get_v3_link(req)),
                rel='current',  # [RFC5005]
                title='V3 Logs',
                type_hint='application/json'
            )
            res.append_header('DEPRECATED', 'true')