0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 09:16:49 +01:00
posthog/ee/clickhouse/middleware.py
Eric Duong a71e899605
Yeetcode (#7830)
* remove django query tests

* remove funnel and caching check

* remove ee available var

* remove is_clickhouse_enabled

* remove abstract tests

* change primary db

* missing func

* unnecessary test

* try new e2e ci

* func arg

* remove param

* ci

* remove plugins in docker

* background

* change ur;

* add kafka url

* add step

* update docker

* primary docker file

* mount volumes correctly

* one more

* remove postgres tests

* remove foss

* remove all  is_clickhouse_neabled

* remove irrelelvant test

* remove extra arg

* remove var

* arg

* add foss comment

* add foss comment

* plugin server config

* Update posthog/utils.py

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>

* migrate commands

* comment

* add clickhouse to pg tests

* change script

* change ordering

* deepsource

* restore foss tests

* test remove KAFKA_ENABLED from CI

* always wait

* up proper resources

* use one conftest

* restore

* remove unnecessary tests

* remove more pg

* log event tests

* fix more tests

* more tests

* type

* fix more tests

* last test

* typing

* account for shared class setup

* temp test cloud

* restore cloud master checkout

* adjust contexts

* backwards

Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>
Co-authored-by: yakkomajuri <yakko.majuri@gmail.com>
2022-01-18 14:32:28 -05:00

39 lines
1.2 KiB
Python

from django.conf import settings
from django.http import HttpRequest, HttpResponse
from django.urls.base import resolve
from loginas.utils import is_impersonated_session
from posthog.internal_metrics import incr
class CHQueries(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request: HttpRequest):
""" Install monkey-patch on demand.
If monkey-patch has not been run in for this process (assuming multiple preforked processes),
then do it now.
"""
from ee.clickhouse import client
route = resolve(request.path)
route_id = f"{route.route} ({route.func.__name__})"
client._request_information = {
"save": (request.user.pk and (request.user.is_staff or is_impersonated_session(request) or settings.DEBUG)),
"user_id": request.user.pk,
"kind": "request",
"id": route_id,
}
response: HttpResponse = self.get_response(request)
if "api/" in route_id and "capture" not in route_id:
incr("http_api_request_response", tags={"id": route_id, "status_code": response.status_code})
client._request_information = None
return response