From 6238c72400accb360e648196c5dd123348ffd761 Mon Sep 17 00:00:00 2001 From: Michaela Wheeler Date: Mon, 6 Jan 2025 10:55:34 +1100 Subject: [PATCH] remove comment --- .gitignore | 5 ++++- Makefile | 4 ++-- dev/prometheus.yml | 2 +- docker-compose-developer.yml | 8 ++++--- ..._migrate_channelfilter_slack_channel_id.py | 22 ++++++++++++------- ...lutionnoteslackmessage_slack_channel_id.py | 21 +++++++++++++----- engine/apps/metrics_exporter/helpers.py | 3 --- .../migrations/0019_auto_20241021_1735.py | 20 ++++++++++++----- .../migrations/0026_auto_20241017_1919.py | 18 ++++++++++----- grafana-plugin/Dockerfile.dev | 5 +++++ grafana-plugin/package.json | 2 +- grafana-plugin/tsconfig.json | 1 + 12 files changed, 75 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 3235688aab..76ed801e8f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ venv pnpm.lock node_modules -test-results \ No newline at end of file +test-results +.pnpm +.pnpm/* +.pnpm-store diff --git a/Makefile b/Makefile index 9498a0f4ce..cc2f636c21 100644 --- a/Makefile +++ b/Makefile @@ -141,7 +141,7 @@ init: ## build the frontend plugin code then run make start # this makes sure that it will be available when the grafana container starts up without the need to # restart the grafana container initially ifeq ($(findstring $(UI_PROFILE),$(COMPOSE_PROFILES)),$(UI_PROFILE)) - $(call run_ui_docker_command,pnpm install && pnpm build:dev) + $(call run_ui_docker_command,pnpm install && pnpm build:dev && pnpm mage:build-dev) endif stop: # stop all of the docker containers @@ -225,7 +225,7 @@ ui-command: ## run any command, inside of a UI docker container, passing `$CMD` $(call run_ui_docker_command,$(CMD)) exec-engine: ## exec into engine container's bash - docker exec -it oncall_engine bash + docker exec -it oncallengine bash _backend-debug-enable: ## enable Django's debug mode and Silk profiling (this is disabled by default for performance reasons) $(shell ./dev/add_env_var.sh DEBUG True $(DEV_ENV_FILE)) diff --git a/dev/prometheus.yml b/dev/prometheus.yml index 5b53a77f14..26ce29838b 100644 --- a/dev/prometheus.yml +++ b/dev/prometheus.yml @@ -5,4 +5,4 @@ global: scrape_configs: - job_name: prometheus static_configs: - - targets: ["host.docker.internal:8080"] + - targets: ["oncallengine:8080"] diff --git a/docker-compose-developer.yml b/docker-compose-developer.yml index ee668df794..bd55cf7079 100644 --- a/docker-compose-developer.yml +++ b/docker-compose-developer.yml @@ -59,7 +59,7 @@ services: - oncall_ui oncall_engine: - container_name: oncall_engine + container_name: oncallengine labels: *oncall-labels build: *oncall-build-args restart: always @@ -323,7 +323,7 @@ services: GF_SECURITY_ADMIN_PASSWORD: oncall GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: grafana-oncall-app GF_FEATURE_TOGGLES_ENABLE: externalServiceAccounts - ONCALL_API_URL: http://host.docker.internal:8080 + ONCALL_API_URL: http://oncallengine:8080 GF_AUTH_MANAGED_SERVICE_ACCOUNTS_ENABLED: true env_file: - ./dev/.env.${DB}.dev @@ -341,7 +341,7 @@ services: - grafanadata_dev:/var/lib/grafana - ./grafana-plugin:/var/lib/grafana/plugins/grafana-plugin - ./dev/grafana/provisioning:/etc/grafana/provisioning - - ${GRAFANA_DEV_PROVISIONING:-/dev/null}:/etc/grafana/grafana.ini + - ./dev/grafana/grafana.dev.ini:/etc/grafana/grafana.ini depends_on: postgres: condition: service_healthy @@ -370,3 +370,5 @@ networks: default: name: oncall_dev labels: *oncall-labels + + diff --git a/engine/apps/alerts/migrations/0063_migrate_channelfilter_slack_channel_id.py b/engine/apps/alerts/migrations/0063_migrate_channelfilter_slack_channel_id.py index dab5a45943..9b5890240c 100644 --- a/engine/apps/alerts/migrations/0063_migrate_channelfilter_slack_channel_id.py +++ b/engine/apps/alerts/migrations/0063_migrate_channelfilter_slack_channel_id.py @@ -15,14 +15,20 @@ def populate_slack_channel(apps, schema_editor): logger.info("Starting migration to populate slack_channel field.") sql = f""" - UPDATE {ChannelFilter._meta.db_table} AS cf - JOIN {AlertReceiveChannel._meta.db_table} AS arc ON arc.id = cf.alert_receive_channel_id - JOIN {Organization._meta.db_table} AS org ON org.id = arc.organization_id - JOIN {SlackChannel._meta.db_table} AS sc ON sc.slack_id = cf._slack_channel_id - AND sc.slack_team_identity_id = org.slack_team_identity_id - SET cf.slack_channel_id = sc.id - WHERE cf._slack_channel_id IS NOT NULL - AND org.slack_team_identity_id IS NOT NULL; + + with temp as ( + SELECT cf_s.slack_channel_id as slack_channel_id, sc.id as id + FROM {ChannelFilter._meta.db_table} AS cf_s + JOIN {AlertReceiveChannel._meta.db_table} AS arc ON arc.id = cf_s.alert_receive_channel_id + JOIN {Organization._meta.db_table} AS org ON org.id = arc.organization_id + JOIN {SlackChannel._meta.db_table} AS sc ON sc.slack_id = cf_s._slack_channel_id + AND sc.slack_team_identity_id = org.slack_team_identity_id + WHERE org.slack_team_identity_id IS NOT NULL and cf_s._slack_channel_id IS NOT NULL + ) + UPDATE {ChannelFilter._meta.db_table} as update_cf + SET slack_channel_id = temp.id + FROM temp + where update_cf.slack_channel_id = temp.slack_channel_id """ with schema_editor.connection.cursor() as cursor: diff --git a/engine/apps/alerts/migrations/0064_migrate_resolutionnoteslackmessage_slack_channel_id.py b/engine/apps/alerts/migrations/0064_migrate_resolutionnoteslackmessage_slack_channel_id.py index 4f492e31c4..a59254ca39 100644 --- a/engine/apps/alerts/migrations/0064_migrate_resolutionnoteslackmessage_slack_channel_id.py +++ b/engine/apps/alerts/migrations/0064_migrate_resolutionnoteslackmessage_slack_channel_id.py @@ -17,15 +17,24 @@ def populate_slack_channel(apps, schema_editor): logger.info("Starting migration to populate slack_channel field.") sql = f""" - UPDATE {ResolutionNoteSlackMessage._meta.db_table} AS rsm - JOIN {AlertGroup._meta.db_table} AS ag ON ag.id = rsm.alert_group_id + + with temp as ( + SELECT rsm_t._slack_channel_id as _slack_channel_id, sc.id as id + FROM {ResolutionNoteSlackMessage._meta.db_table} AS rsm_t + JOIN {AlertGroup._meta.db_table} AS ag ON ag.id = rsm_t.alert_group_id JOIN {AlertReceiveChannel._meta.db_table} AS arc ON arc.id = ag.channel_id JOIN {Organization._meta.db_table} AS org ON org.id = arc.organization_id - JOIN {SlackChannel._meta.db_table} AS sc ON sc.slack_id = rsm._slack_channel_id + JOIN {SlackChannel._meta.db_table} AS sc ON sc.slack_id = rsm_t._slack_channel_id AND sc.slack_team_identity_id = org.slack_team_identity_id - SET rsm.slack_channel_id = sc.id - WHERE rsm._slack_channel_id IS NOT NULL - AND org.slack_team_identity_id IS NOT NULL; + WHERE rsm_t._slack_channel_id IS NOT NULL + AND org.slack_team_identity_id IS NOT NULL + ) + + + UPDATE {ResolutionNoteSlackMessage._meta.db_table} AS rsm + SET slack_channel_id = temp.id + FROM temp + WHERE rsm._slack_channel_id = temp._slack_channel_id """ with schema_editor.connection.cursor() as cursor: diff --git a/engine/apps/metrics_exporter/helpers.py b/engine/apps/metrics_exporter/helpers.py index 50e0dc413e..0abbae9394 100644 --- a/engine/apps/metrics_exporter/helpers.py +++ b/engine/apps/metrics_exporter/helpers.py @@ -241,9 +241,6 @@ def metrics_bulk_update_team_label_cache(teams_updated_data: dict, organization_ metric_alert_groups_total = cache.get(metric_alert_groups_total_key, {}) metric_alert_groups_response_time = cache.get(metric_alert_groups_response_time_key, {}) - - # TODO need to work out how to handle team changes... or if we need to. - for team_id, team_data in teams_updated_data.items(): for index in metric_alert_groups_total: if metric_alert_groups_total[index]["team_id"] == team_id: diff --git a/engine/apps/schedules/migrations/0019_auto_20241021_1735.py b/engine/apps/schedules/migrations/0019_auto_20241021_1735.py index edc89366b3..518f16ed3a 100644 --- a/engine/apps/schedules/migrations/0019_auto_20241021_1735.py +++ b/engine/apps/schedules/migrations/0019_auto_20241021_1735.py @@ -14,13 +14,21 @@ def populate_slack_channel(apps, schema_editor): logger.info("Starting migration to populate slack_channel field.") sql = f""" + with temp as ( + SELECT ocs_t.slack_channel_id as slack_channel_id, sc.id as id + FROM {OnCallSchedule._meta.db_table} AS ocs_t + JOIN {Organization._meta.db_table} AS org ON org.id = ocs_t.organization_id + JOIN {SlackChannel._meta.db_table} AS sc ON sc.slack_id = ocs_t.channel + AND sc.slack_team_identity_id = org.slack_team_identity_id + WHERE ocs_t.channel IS NOT NULL + AND org.slack_team_identity_id IS NOT NULL + ) + UPDATE {OnCallSchedule._meta.db_table} AS ocs - JOIN {Organization._meta.db_table} AS org ON org.id = ocs.organization_id - JOIN {SlackChannel._meta.db_table} AS sc ON sc.slack_id = ocs.channel - AND sc.slack_team_identity_id = org.slack_team_identity_id - SET ocs.slack_channel_id = sc.id - WHERE ocs.channel IS NOT NULL - AND org.slack_team_identity_id IS NOT NULL; + SET slack_channel_id = temp.id + FROM temp + WHERE ocs.slack_channel_id = temp.slack_channel_id + """ with schema_editor.connection.cursor() as cursor: diff --git a/engine/apps/user_management/migrations/0026_auto_20241017_1919.py b/engine/apps/user_management/migrations/0026_auto_20241017_1919.py index df28b02603..9006d0f863 100644 --- a/engine/apps/user_management/migrations/0026_auto_20241017_1919.py +++ b/engine/apps/user_management/migrations/0026_auto_20241017_1919.py @@ -14,12 +14,20 @@ def populate_default_slack_channel(apps, schema_editor): logger.info("Starting migration to populate default_slack_channel field.") sql = f""" + with temp as ( + SELECT org_t.default_slack_channel_id as default_slack_channel_id, sc.id as id + FROM {Organization._meta.db_table} AS org_t + JOIN {SlackChannel._meta.db_table} AS sc ON sc.slack_id = org_t.general_log_channel_id + AND sc.slack_team_identity_id = org_t.slack_team_identity_id + WHERE org_t.general_log_channel_id IS NOT NULL + AND org_t.slack_team_identity_id IS NOT NULL + ) + + UPDATE {Organization._meta.db_table} AS org - JOIN {SlackChannel._meta.db_table} AS sc ON sc.slack_id = org.general_log_channel_id - AND sc.slack_team_identity_id = org.slack_team_identity_id - SET org.default_slack_channel_id = sc.id - WHERE org.general_log_channel_id IS NOT NULL - AND org.slack_team_identity_id IS NOT NULL; + SET default_slack_channel_id = temp.id + FROM temp + WHERE org.default_slack_channel_id = temp.default_slack_channel_id """ with schema_editor.connection.cursor() as cursor: diff --git a/grafana-plugin/Dockerfile.dev b/grafana-plugin/Dockerfile.dev index 03a79c084e..576df71d27 100644 --- a/grafana-plugin/Dockerfile.dev +++ b/grafana-plugin/Dockerfile.dev @@ -2,5 +2,10 @@ FROM node:20.15.1-alpine WORKDIR /etc/app ENV PATH /etc/app/node_modules/.bin:$PATH +RUN npm install -g pnpm +RUN apk add go git && git clone https://github.com/magefile/mage && \ + cd mage && mkdir /root/go/ && \ + go run bootstrap.go +ENV PATH="/root/go/bin/:$PATH" CMD ["pnpm", "start"] \ No newline at end of file diff --git a/grafana-plugin/package.json b/grafana-plugin/package.json index a960904928..b4f9ba11f1 100644 --- a/grafana-plugin/package.json +++ b/grafana-plugin/package.json @@ -30,7 +30,7 @@ "serve": "serve -p 3001 ./dist", "dev:serve": "concurrently --names \"serve,dev\" --prefix-colors \"blue,green\" \"pnpm serve\" \"pnpm dev\"", "sign": "npx --yes @grafana/sign-plugin@latest", - "start": "pnpm watch", + "start": "pnpm mage:build-dev; pnpm dev:serve", "setversion": "setversion", "type-check": "tsc --noEmit", "type-check:watch": "pnpm type-check --watch --preserveWatchOutput false", diff --git a/grafana-plugin/tsconfig.json b/grafana-plugin/tsconfig.json index d49344db43..d73f11892d 100644 --- a/grafana-plugin/tsconfig.json +++ b/grafana-plugin/tsconfig.json @@ -3,6 +3,7 @@ "include": ["src", "e2e-tests", "playwright.config.ts"], "types": ["node", "@emotion/core"], "compilerOptions": { + "jsx": "react", "composite": true, "declaration": true, "rootDir": "",