Skip to content

Commit

Permalink
Merge branch 'master' into dn-fix/properties-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin committed Aug 9, 2024
2 parents 2cb463e + fe376e8 commit ad4ed28
Show file tree
Hide file tree
Showing 738 changed files with 13,701 additions and 7,090 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ jobs:
OBJECT_STORAGE_SECRET_ACCESS_KEY=object_storage_root_password
GITHUB_ACTION_RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
CELERY_METRICS_PORT=8999
CLOUD_DEPLOYMENT=1
CLOUD_DEPLOYMENT=E2E
EOT
- name: Start PostHog
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Go Test (for livestream service)

on:
pull_request:
paths:
- 'livestream/**'

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.22

- name: Run tests
run: cd livestream && go test -v
35 changes: 35 additions & 0 deletions .github/workflows/replay-capture.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Vector Replay Capture Tests

on:
workflow_dispatch:
pull_request:
paths:
- vector/**
- .github/workflows/replay-capture.yml

workflow_call:

jobs:
vector-test:
name: Vector test
runs-on: ubuntu-20.04
env:
QUOTA_LIMITED_TEAMS_PATH: vector/replay-capture/tests/quota_limited_teams.csv
OVERFLOW_SESSIONS_PATH: vector/replay-capture/tests/overflow_sessions.csv
KAFKA_BOOSTRAP_SERVERS: dummy:9092
KAFKA_EVENTS_TOPIC: session_recording_snapshot_item_events
KAFKA_OVERFLOW_TOPIC: session_recording_snapshot_item_overflow
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Vector
run: |
wget https://github.com/vectordotdev/vector/releases/download/v0.40.0/vector-0.40.0-x86_64-unknown-linux-gnu.tar.gz
tar xzvf vector-0.40.0-x86_64-unknown-linux-gnu.tar.gz ./vector-x86_64-unknown-linux-gnu/bin/vector
sudo mv ./vector-x86_64-unknown-linux-gnu/bin/vector /usr/bin/vector
- name: Run vector tests
run: |
yq -i e 'explode(.)' vector/replay-capture/vector.yaml
vector test vector/replay-capture/*.yaml
104 changes: 104 additions & 0 deletions .github/workflows/vector-docker-build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Build and deploy replay capture container images

on:
workflow_dispatch:
push:
paths:
- 'vector/**'
- '.github/workflows/vector-docker-build-deploy.yml'
branches:
- 'master'

jobs:
build:
name: Build and publish container image
runs-on: depot-ubuntu-22.04-4
permissions:
id-token: write # allow issuing OIDC tokens for this workflow run
contents: read # allow reading the repo contents
packages: write # allow push to ghcr.io

outputs:
digest: ${{ steps.docker_build.outputs.digest }}

defaults:
run:
working-directory: vector/

steps:
- name: Check Out Repo
# Checkout project code
# Use sparse checkout to only select files in vector directory
# Turning off cone mode ensures that files in the project root are not included during checkout
uses: actions/checkout@v4
with:
sparse-checkout: 'vector/'
sparse-checkout-cone-mode: false

- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: false

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/posthog/posthog/replay-capture
tags: |
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Build and push image
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./vector/replay-capture/
file: ./vector/replay-capture/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/arm64

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: get deployer token
id: deployer
uses: getsentry/action-github-app-token@v3
with:
app_id: ${{ secrets.DEPLOYER_APP_ID }}
private_key: ${{ secrets.DEPLOYER_APP_PRIVATE_KEY }}

- name: Trigger livestream deployment
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.deployer.outputs.token }}
repository: PostHog/charts
event-type: commit_state_update
client-payload: |
{
"values": {
"image": {
"sha": "${{ needs.build.outputs.digest }}"
}
},
"release": "replay-capture-vector",
"commit": ${{ toJson(github.event.head_commit) }},
"repository": ${{ toJson(github.repository) }},
"labels": []
}
2 changes: 1 addition & 1 deletion .run/Celery Threads.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/manage.py" />
<option name="PARAMETERS" value="run_autoreload_celery" />
<option name="PARAMETERS" value="run_autoreload_celery --type=worker" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
},
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": ["run_autoreload_celery"],
"args": ["run_autoreload_celery", "--type=worker"],
"console": "integratedTerminal",
"python": "${workspaceFolder}/env/bin/python",
"cwd": "${workspaceFolder}",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ We <3 contributions big and small. In priority order (although everything is app

Our mission is to increase the number of successful products in the world. To do that, we build product and data tools that help you understand user behavior without losing control of your data.

In our view, third-party analytics tools do not work in a world of cookie deprecation, GDPR, HIPAA, CCPA, and many other four-letter acronyms. PostHog is the alternative to sending all of your customers' personal information and usage data to third-parties.
In our view, third-party analytics tools do not work in a world of cookie deprecation, GDPR, HIPAA, CCPA, and many other four-letter acronyms. PostHog is the alternative to sending all of your customers' personal information and usage data to third parties.

PostHog gives you every tool you need to understand user behavior, develop and test improvements, and release changes to make your product more successful.

PostHog operates in public as much as possible. We detail how we work and our learning on building and running a fast-growing, product-focused startup in our [handbook](https://posthog.com/handbook/getting-started/start-here).

## Open-source vs. paid

This repo is available under the [MIT expat license](https://github.com/PostHog/posthog/blob/master/LICENSE), except for the `ee` directory (which has it's [license here](https://github.com/PostHog/posthog/blob/master/ee/LICENSE)) if applicable.
This repo is available under the [MIT expat license](https://github.com/PostHog/posthog/blob/master/LICENSE), except for the `ee` directory (which has its [license here](https://github.com/PostHog/posthog/blob/master/ee/LICENSE)) if applicable.

Need *absolutely 💯% FOSS*? Check out our [posthog-foss](https://github.com/PostHog/posthog-foss) repository, which is purged of all proprietary code and features.

Expand Down
13 changes: 7 additions & 6 deletions bin/e2e-test-runner
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ do
fi
done

export DEBUG=1
export NO_RESTART_LOOP=1
export CYPRESS_BASE_URL=http://localhost:8080
export SECURE_COOKIES=0
export SKIP_SERVICE_VERSION_REQUIREMENTS=1
export KAFKA_HOSTS=kafka:9092
export CLICKHOUSE_DATABASE=posthog_test
export TEST=1 # Plugin server and kafka revert to 'default' Clickhouse database if TEST is not set
export CLICKHOUSE_SECURE=0
export JS_URL=http://localhost:8234
export E2E_TESTING=1
export SECRET_KEY=e2e_test
export EMAIL_HOST=email.test.posthog.net
Expand All @@ -66,7 +64,9 @@ export PGUSER="${PGUSER:=posthog}"
export PGPASSWORD="${PGPASSWORD:=posthog}"
export PGPORT="${PGPORT:=5432}"
export DATABASE_URL="postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${DATABASE}"
export CLOUD_DEPLOYMENT=1
export CLOUD_DEPLOYMENT=E2E

source ./bin/celery-queues.env

trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

Expand All @@ -92,8 +92,7 @@ setupDev() {
python manage.py setup_dev &
}

nc -z localhost 9092 || ( echo -e "\033[0;31mKafka isn't running. Please run\n\tdocker compose -f docker-compose.dev.yml up zookeeper kafka clickhouse db redis\nI'll wait while you do that.\033[0m" ; bin/check_kafka_clickhouse_up )
wget -nv -t1 --spider 'http://localhost:8123/' || ( echo -e "\033[0;31mClickhouse isn't running. Please run\n\tdocker compose -f docker-compose.dev.yml up zookeeper kafka clickhouse db redis.\nI'll wait while you do that.\033[0m" ; bin/check_kafka_clickhouse_up )
bin/check_kafka_clickhouse_up

$SKIP_RECREATE_DATABASE || recreateDatabases
$SKIP_MIGRATE || migrateDatabases
Expand All @@ -103,4 +102,6 @@ $SKIP_SETUP_DEV || setupDev
# Only start webpack if not already running
nc -vz 127.0.0.1 8234 2> /dev/null || ./bin/start-frontend &
pnpm dlx cypress open --config-file cypress.e2e.config.ts &
uv pip install -r requirements.txt -r requirements-dev.txt
python manage.py run_autoreload_celery --type=worker &
python manage.py runserver 8080
4 changes: 2 additions & 2 deletions bin/start-worker
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ trap 'kill $(jobs -p)' EXIT
source ./bin/celery-queues.env

# start celery worker with heartbeat (-B)
SKIP_ASYNC_MIGRATIONS_SETUP=0 CELERY_WORKER_QUEUES=$CELERY_WORKER_QUEUES celery -A posthog worker --without-heartbeat --without-mingle --pool=threads -Ofair -n node@%h &
celery -A posthog beat -S redbeat.RedBeatScheduler &
python manage.py run_autoreload_celery --type=worker &
python manage.py run_autoreload_celery --type=beat &

if [[ "$PLUGIN_SERVER_IDLE" != "1" && "$PLUGIN_SERVER_IDLE" != "true" ]]; then
./bin/plugin-server
Expand Down
13 changes: 7 additions & 6 deletions cypress.e2e.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ export default defineConfig({
const redisClient = await createClient()
.on('error', (err) => console.log('Redis client error', err))
.connect()
for await (const key of redisClient.scanIterator({
TYPE: 'string',
MATCH: '*cache*',
COUNT: 100,
})) {
// Clear cache
for await (const key of redisClient.scanIterator({ TYPE: 'string', MATCH: '*cache*', COUNT: 500 })) {
await redisClient.del(key)
}
// Also clear the more ephemeral async query statuses
for await (const key of redisClient.scanIterator({ TYPE: 'string', MATCH: 'query_async*', COUNT: 500 })) {
await redisClient.del(key)
}
await redisClient.quit()
return null
return null // Cypress requires _some_ return value
},
})

Expand Down
70 changes: 57 additions & 13 deletions cypress/e2e/alerts.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { decideResponse } from '../fixtures/api/decide'
import { createInsight } from '../productAnalytics'

describe('Alerts', () => {
it('Should allow create and delete an alert', () => {
beforeEach(() => {
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
Expand All @@ -11,29 +11,45 @@ describe('Alerts', () => {
)
)
createInsight('insight')
})

const createAlert = (
name: string = 'Alert name',
email: string = '[email protected]',
lowerThreshold: string = '100',
upperThreshold: string = '200'
): void => {
cy.get('[data-attr=more-button]').click()
// Alerts should be disabled for trends represented with graphs
cy.get('[data-attr=disabled-alerts-button]').should('exist')
cy.contains('Alerts').click()
cy.contains('New alert').click()

cy.get('[data-attr=alert-name]').clear().type(name)
cy.get('[data-attr=alert-notification-targets').clear().type(email)
cy.get('[data-attr=alert-lower-threshold').clear().type(lowerThreshold)
cy.get('[data-attr=alert-upper-threshold').clear().type(upperThreshold)
cy.contains('Create alert').click()
cy.url().should('not.include', '/new')

cy.get('[aria-label="close"]').click()
}

const setInsightDisplayTypeAndSave = (displayType: string): void => {
// Only the Number representation supports alerts, so change the insight
cy.get('[data-attr=insight-edit-button]').click()
cy.get('[data-attr=chart-filter]').click()
cy.contains('Number').click()
cy.contains(displayType).click()
cy.get('[data-attr=insight-save-button]').contains('Save').click()
cy.url().should('not.include', '/edit')
}

it('Should allow create and delete an alert', () => {
cy.get('[data-attr=more-button]').click()
cy.contains('Alerts').click()
cy.contains('New alert').click()
// Alerts should be disabled for trends represented with graphs
cy.get('[data-attr=disabled-alerts-button]').should('exist')

cy.get('[data-attr=alert-name]').clear().type('Alert name')
cy.get('[data-attr=alert-notification-targets').clear().type('[email protected]')
cy.get('[data-attr=alert-lower-threshold').clear().type('100')
cy.get('[data-attr=alert-upper-threshold').clear().type('200')
cy.contains('Create alert').click()
cy.url().should('not.include', '/new')
setInsightDisplayTypeAndSave('Number')

cy.get('[aria-label="close"]').click()
createAlert()
cy.reload()

// Check the alert has the same values as when it was created
Expand All @@ -50,4 +66,32 @@ describe('Alerts', () => {
cy.reload()
cy.contains('Alert name').should('not.exist')
})

it('Should warn about an alert deletion', () => {
setInsightDisplayTypeAndSave('Number')

createAlert('Alert to be deleted because of a changed insight')

cy.get('[data-attr=insight-edit-button]').click()
cy.get('[data-attr=chart-filter]').click()
cy.contains('Line chart').click()

cy.contains('the existing alerts will be deleted').should('exist')

cy.get('[data-attr=chart-filter]').click()
cy.contains('Number').click()

// Assert that reverting the display type removes the banner
cy.contains('the existing alerts will be deleted').should('not.exist')

cy.get('[data-attr=insight-cancel-edit-button]').click()
setInsightDisplayTypeAndSave('Line chart')
setInsightDisplayTypeAndSave('Number')

// Assert that saving an insight in an incompatible state removes alerts
cy.get('[data-attr=more-button]').click()
cy.contains('Alerts').click()
cy.contains('Manage alerts').click()
cy.contains('Alert to be deleted because of a changed insight').should('not.exist')
})
})
Loading

0 comments on commit ad4ed28

Please sign in to comment.