Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clickhouse] Event list #1787

Merged
merged 40 commits into from
Oct 1, 2020
Merged

[Clickhouse] Event list #1787

merged 40 commits into from
Oct 1, 2020

Conversation

timgl
Copy link
Collaborator

@timgl timgl commented Oct 1, 2020

Changes

Please describe.
If this affects the front-end, include screenshots.

Checklist

  • All querysets/queries filter by Team (if this PR affects any querysets/queries)
  • Backend tests (if this PR affects the backend)
  • Cypress E2E tests (if this PR affects the front and/or backend)

mariusandra and others added 30 commits September 29, 2020 16:39
…6-2-event-list

* origin/clickhouse-sessions-qa: (24 commits)
  remove reverse
  add default time to fix test, fix some any(*) filter issues
  fix test
  mypy
  fix pagination, timestamp calculation and ordering on pages 2 and beyond
  show seconds with two digits
  add person properties to sessions query response
  add elements to query results
  events in clickhouse sessions
  default limit to 50
  based offset is always 0
  load LIMIT+1 sessions in postgres, pop last and show load more sign. (was: show sign if exactly LIMIT fetched)
  support limit + offset
  indent sql
  initial limit/offset block
  rename offset to nextOffset
  date from filters
  throw error if failed instead of returning an empty list
  prevent multiple queries
  load sessions based on the URL, not after mount --> avoids duplicate query if opening an url with a filter
  ...
@timgl timgl changed the title 1736 2 event list [Clickhouse] Event list Oct 1, 2020
@timgl timgl had a problem deploying to posthog-1736-2-event-li-keekxx October 1, 2020 10:33 Failure
@timgl timgl temporarily deployed to posthog-1736-2-event-li-keekxx October 1, 2020 10:37 Inactive
@timgl timgl temporarily deployed to posthog-1736-2-event-li-9swjbp October 1, 2020 10:41 Inactive
@timgl timgl temporarily deployed to posthog-1736-2-event-li-8die7n October 1, 2020 10:48 Inactive
@@ -32,7 +32,7 @@ services:
CLICKHOUSE_VERIFY: 'False'
KAFKA_URL: 'kafka://kafka'
REDIS_URL: 'redis://redis:6379/'
SECRET_KEY: '<randomly generated secret key>'
SECRET_KEY: 'alsdfjiosdajfklalsdjkf'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, having errors thrown because of <randomly generated secret key> is annoying, but the point is that users then know they should update for their own safety. Perhaps moving towards @Twixes approach from #1704 is best, while keeping <randomly generated secret key> here for safety.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth only we will be using this docker-compose file. This is not for general consumption.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah that's true... I guess it's not a problem then

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yep I didn't mean to commit this but it was annoying. If James G is happy I can leave this in

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yep I didn't mean to commit this but it was annoying. If James G is happy I can leave this in

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah doesn't bother me any

@timgl timgl temporarily deployed to posthog-1736-2-event-li-12haks October 1, 2020 12:38 Inactive
Copy link
Member

@fuziontech fuziontech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome. Send it! (with comments lol)

@@ -3,4 +3,4 @@
set -e
python manage.py migrate

python manage.py runserver 0.0.0.0:8000 & ./bin/start-frontend 0.0.0.0
python manage.py runserver 0.0.0.0:8000 & ./bin/start-frontend 127.0.0.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing hits what yarn run start-http runs correct? If so this is great

Comment on lines +19 to +21
# install dev dependencies
RUN pip install -r requirements/dev.txt --compile

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

@@ -13,7 +13,7 @@ def parse_filter(filters: List[Property]) -> Tuple[str, Dict]:
result = ""
params = {}
for idx, prop in enumerate(filters):
result += "{cond}(ep.key = %(k{idx})s) AND (ep.value = %(v{idx})s)".format(
result += "{cond}(ep.key = %(k{idx})s) AND (trim(BOTH '\"' FROM ep.value) = %(v{idx})s)".format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave this out for now. It's better to add this to the materialized view on clickhouse so that we don't have to clean anything up in post.

Copy link
Collaborator Author

@timgl timgl Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm tests fail/you won't be able to filter without this. Is it easy to add it to materliazed view?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this in for now... but I'd like to get that solved at the source as quickly as possible. When we change serialization from JSON to Avro or Proto this will be cleaned up upstream

events_with_array_props_view ewap
INNER JOIN person_distinct_id as pid ON ewap.distinct_id = pid.distinct_id
INNER JOIN person ON pid.person_id = person.id
where ewap.team_id = %(team_id)s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inConSISTent CapS

from posthog.utils import convert_property_value


class ClickhouseEvents(EventViewSet):
def list(self, request):
def _get_elements(self, query_result: List[Dict], team: Team) -> Dict[str, Any]:
element_hashes = [event[6] for event in query_result]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like that we are pulling out hashes by index 6 here. Has a bit of a smell. Not a huge deal though. If we did this in a few spots it would make it really hard to refactor the query and reorder columns.

Would be better if we had event.element_hash on the row. Something we can work towards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agree, need to solve this. surprised the driver doesn't give you a dict or object

INNER JOIN person_distinct_id as pid ON ewap.distinct_id = pid.distinct_id
INNER JOIN person ON pid.person_id = person.id
where ewap.team_id = %(team_id)s
AND ewap.uuid IN (select uuid from events WHERE team_id = %(team_id)s {conditions})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inConSISTent CapS

) {conditions} {limit}
WHERE team_id = %(team_id)s AND {filters}
)
AND ewap.uuid IN (select uuid from events WHERE team_id = %(team_id)s {conditions})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inConSISTent CapS

)

with self.assertNumQueries(7):
def test_event_api_factory(event_factory, person_factory, action_factory):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 very nice

@timgl timgl temporarily deployed to posthog-1736-2-event-li-y5cgkf October 1, 2020 12:59 Inactive
@timgl timgl had a problem deploying to posthog-1736-2-event-li-nihomc October 1, 2020 13:20 Failure
@timgl timgl temporarily deployed to posthog-1736-2-event-li-nihomc October 1, 2020 13:25 Inactive
@timgl timgl temporarily deployed to posthog-1736-2-event-li-dnsz7t October 1, 2020 13:31 Inactive
@timgl timgl had a problem deploying to posthog-1736-2-event-li-wf3nf9 October 1, 2020 13:41 Failure
@timgl timgl temporarily deployed to posthog-1736-2-event-li-wf3nf9 October 1, 2020 13:42 Inactive
@timgl timgl merged commit 92e8bbd into master Oct 1, 2020
@timgl timgl deleted the 1736-2-event-list branch October 1, 2020 13:47
timgl added a commit that referenced this pull request Oct 1, 2020
* origin:
  Always limit events (#1794)
  Fix ambiguous timestamp ordering (#1792)
  Fix dev docker build (#1791)
  Create CODE_OF_CONDUCT.md (#1790)
  [Clickhouse] Event list (#1787)
  made shared_dashboards endpoint exempt from x-frame-options header (#1789)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants