コード例 #1
0
        def do_POST(self):
            print("INGEST POST: %s" % self.path)
            body = self.rfile.read(int(self.headers.get("Content-Length")))
            is_json = "application/json" in self.headers.get("Content-Type")

            if "gzip" in self.headers.get("Content-Encoding", ""):
                body = gzip.decompress(body)

            if "datapoint" in self.path:
                dp_upload = sf_pbuf.DataPointUploadMessage()
                if is_json:
                    json_format.Parse(body, dp_upload)
                else:
                    dp_upload.ParseFromString(body)
                datapoints.extend(dp_upload.datapoints)  # pylint: disable=no-member
            elif "event" in self.path:
                event_upload = sf_pbuf.EventUploadMessage()
                if is_json:
                    json_format.Parse(body, event_upload)
                else:
                    event_upload.ParseFromString(body)
                events.extend(event_upload.events)  # pylint: disable=no-member
            elif "trace" in self.path:
                spans.extend(json.loads(body))
            else:
                self.send_response(404)
                self.end_headers()
                return

            self.send_response(200)
            self.send_header("Content-Type", "text/ascii")
            self.send_header("Content-Length", "4")
            self.end_headers()
            self.wfile.write('"OK"'.encode("utf-8"))
コード例 #2
0
        def do_POST(self):
            body = self.rfile.read(int(self.headers.get('Content-Length')))
            is_json = "application/json" in self.headers.get("Content-Type")

            if "gzip" in self.headers.get("Content-Encoding", ""):
                body = gzip.decompress(body)

            if 'datapoint' in self.path:
                dp_upload = sf_pbuf.DataPointUploadMessage()
                if is_json:
                    json_format.Parse(body, dp_upload)
                else:
                    dp_upload.ParseFromString(body)
                datapoints.extend(dp_upload.datapoints)
            elif 'event' in self.path:
                event_upload = sf_pbuf.EventUploadMessage()
                if is_json:
                    json_format.Parse(body, event_upload)
                else:
                    event_upload.ParseFromString(body)
                events.extend(event_upload.events)
            else:
                self.send_response(404)
                self.end_headers()
                return

            self.send_response(200)
            self.send_header("Content-Type", "text/ascii")
            self.send_header("Content-Length", "4")
            self.end_headers()
            self.wfile.write("\"OK\"".encode("utf-8"))
コード例 #3
0
 def events(self):
     """
     Fetch the events from the fake ingest and deserialize them
     """
     resp = requests.get(self.local_url + "/events")
     event_message = sf_pbuf.EventUploadMessage()
     event_message.ParseFromString(resp.content)
     return event_message.events
コード例 #4
0
    async def handle_event(request):
        is_json = "application/json" in request.headers.get("content-type")

        event_upload = sf_pbuf.EventUploadMessage()
        if is_json:
            json_format.Parse(request.body, event_upload)
        else:
            event_upload.ParseFromString(request.body)
        events.extend(event_upload.events)  # pylint: disable=no-member
        return response.json("OK")
コード例 #5
0
        def do_GET(self):
            """
            Dump out the received datapoints and events in a pickled byte
            encoding.
            """
            obj = None
            if 'datapoint' in self.path:
                obj = sf_pbuf.DataPointUploadMessage()
                obj.datapoints.extend(datapoints)
            elif 'event' in self.path:
                obj = sf_pbuf.EventUploadMessage()
                obj.events.extend(events)
            else:
                self.send_response(404)
                self.end_headers()
                return

            out = obj.SerializeToString()
            self.send_response(200)
            self.send_header("Content-Type", "application/octet-stream")
            self.send_header("Content-Length", len(out))
            self.end_headers()
            self.wfile.write(out)