forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5813 from nyaruka/prometheus_as_feature
Turn prometheus access into an org feature and grant to all orgs with existing token
- Loading branch information
Showing
6 changed files
with
85 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 5.1.4 on 2025-01-16 18:54 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def grant_prometheus_feature(apps, schema_editor): | ||
Org = apps.get_model("orgs", "Org") | ||
|
||
num_updated = 0 | ||
for org in Org.objects.exclude(prometheus_token=None): | ||
org.features += ["prometheus"] | ||
org.save(update_fields=("features",)) | ||
num_updated += 1 | ||
|
||
if num_updated: | ||
print(f"Granted prometheus feature to {num_updated} orgs with existing tokens") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("orgs", "0164_remove_viewers"), | ||
] | ||
|
||
operations = [migrations.RunPython(grant_prometheus_feature, migrations.RunPython.noop)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,46 +299,6 @@ def start_flow_via_api(): | |
|
||
mock_async_start.assert_called_once() | ||
|
||
def test_prometheus(self): | ||
# visit as editor, no prometheus section | ||
self.login(self.editor) | ||
settings_url = reverse("orgs.org_workspace") | ||
response = self.client.get(settings_url) | ||
|
||
self.assertNotContains(response, "Prometheus") | ||
|
||
# admin can see it though | ||
self.login(self.admin) | ||
|
||
response = self.client.get(settings_url) | ||
self.assertContains(response, "Prometheus") | ||
self.assertContains(response, "Enable") | ||
|
||
# enable it | ||
prometheus_url = reverse("orgs.org_prometheus") | ||
response = self.client.post(prometheus_url, {}, follow=True) | ||
self.assertContains(response, "Disable") | ||
|
||
# make sure our token is set | ||
self.org.refresh_from_db() | ||
self.assertIsNotNone(self.org.prometheus_token) | ||
|
||
# other admin sees it enabled too | ||
self.other_admin = self.create_user("[email protected]") | ||
self.org.add_user(self.other_admin, OrgRole.ADMINISTRATOR) | ||
self.login(self.other_admin) | ||
|
||
response = self.client.get(settings_url) | ||
self.assertContains(response, "Prometheus") | ||
self.assertContains(response, "Disable") | ||
|
||
# now disable it | ||
response = self.client.post(prometheus_url, {}, follow=True) | ||
self.assertContains(response, "Enable") | ||
|
||
self.org.refresh_from_db() | ||
self.assertIsNone(self.org.prometheus_token) | ||
|
||
def test_resthooks(self): | ||
resthook_url = reverse("orgs.org_resthooks") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from temba.tests import MigrationTest | ||
|
||
|
||
class GrantPrometheusFeatureTest(MigrationTest): | ||
app = "orgs" | ||
migrate_from = "0164_remove_viewers" | ||
migrate_to = "0165_grant_prometheus_feature" | ||
|
||
def setUpBeforeMigration(self, apps): | ||
self.org.prometheus_token = "sesame" | ||
self.org.save(update_fields=("prometheus_token",)) | ||
|
||
def test_migration(self): | ||
self.org.refresh_from_db() | ||
self.org2.refresh_from_db() | ||
|
||
self.assertIn("prometheus", self.org.features) | ||
self.assertNotIn("prometheus", self.org2.features) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters