Commit graph

191 commits

Author SHA1 Message Date
Vadim Stepanov
070eb6e538
Enable mobile app backend by default on OSS (#1286)
# What this PR does
Enables mobile app backend by default on OSS.

## Checklist
- [x] `CHANGELOG.md` updated
2023-02-03 12:44:22 +00:00
Ildar Iskhakov
710f7755c0
Fix bug with root/dependant alert groups list api endpoint (#1284)
# What this PR does

## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated
2023-02-03 19:53:35 +08:00
Vadim Stepanov
08dbab73d2
Remove mobile_app_settings DynamicSetting (#1268)
# What this PR does
Remove checks for `mobile_app_settings` DynamicSetting, so changing
`FEATURE_MOBILE_APP_INTEGRATION_ENABLED` is enough for toggling the
mobile app backend (aka remove per-org feature flag)

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2023-02-02 13:21:04 +00:00
Ildar Iskhakov
df1517573e
Cache web template rendered fields for alert and alertgroup endpoints (#1261)
# What this PR does
This PR adds same approach as introduced
[here](https://github.com/grafana/oncall/pull/1236) to all alert and
alertgroup endpoints

## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated

---------

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2023-02-02 11:37:52 +08:00
Matias Bordese
3e15b8cd85
Add default slack channel info to direct paging dialog (#1263) 2023-02-01 10:03:54 -03:00
Matias Bordese
b1fc123d9f
Add a filter by involved users to alert groups page (#1240)
Related to #1119 

It also adds a shortcut to filter current user's related alert groups
(alert groups user was notified by, or in which user participated). Make
the filter visible by default, with a false value.
2023-01-30 14:08:18 +02:00
Vadim Stepanov
f80271a1f4
Return alert group ID in direct paging API (#1241)
# What this PR does
Make direct paging internal API endpoint return an alert group ID.

## Which issue(s) this PR fixes
Related to https://github.com/grafana/oncall/issues/823

## Checklist

- [x] Tests updated
2023-01-30 11:48:25 +00:00
Ildar Iskhakov
ae44ee5652
Cache render_for_web field for alertgroups list serializer (#1236)
# What this PR does
This PR caches the field `render_for_web` with lifetime 1 day and cache
becomes invalid if it was created before
* last alert received
* template changed


## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated
2023-01-28 12:50:41 +08:00
Joey Orlando
3cf2fcf660
optimize GET /schedules internal API endpoint (#1169)
# What this PR does

Fixes slow internal`GET /schedules` endpoints. Using the fake-data
generation script in #1128, I generated 65 calendar schedules in my
local setup. This resulted in the following endpoint performance:
![Screenshot 2023-01-24 at 12 03
16](https://user-images.githubusercontent.com/9406895/214276618-1a9848ba-eb84-49ec-a099-fdd96beac93f.png)

The responses which show ~76 queries were run on the latest `dev`
branch. Responses w/ ~26 queries were run on this branch.

Additionally:
- add typing to a few methods in `apps/schedules/ical_utils.py`
- document `apps/api/permissions/__init__.py:user_is_authorized`
function

## Which issue(s) this PR fixes

https://github.com/grafana/oncall-private/issues/1552

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated

Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
2023-01-25 11:08:09 +01:00
Ildar Iskhakov
46b39b2c87
Remove resolved and acknowledged filters as we switched to status (#1201)
# What this PR does

## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated
2023-01-24 18:13:21 +08:00
Ildar Iskhakov
b90fe433c9
Optimize alertgroups endpoint (#1189)
# What this PR does

Changing query to retrieve alert group in two completely different
queries instead of one with `join`

new queries
```
SELECT alerts_alertreceivechannel.id
FROM alerts_alertreceivechannel
WHERE (alerts_alertreceivechannel.deleted_at IS NULL
       AND alerts_alertreceivechannel.organization_id = 8
       AND alerts_alertreceivechannel.team_id IS NULL)


SELECT `alerts_alertgroup`.`id`
FROM `alerts_alertgroup`
WHERE (`alerts_alertgroup`.`channel_id` IN (2,33,34,35,36,40,52,59,61,62,63,70,76,89,93,94,03,08,09,10,12,13,16,18,20,22,23,24,26,27,28,30,31,33,34,35,36,40,41,42,43,45,48,53,56,57,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,86,87,88,89,91,93,23,27,29,31,32,33,55,56,57,58,65,69,72,75,81,13,17,20,22,33,34,38,39,41,44,45,46,51,52,55,56,58,59,60,63,68,70,71)
       AND NOT `alerts_alertgroup`.`is_archived`
       AND NOT `alerts_alertgroup`.`is_archived`
       AND `alerts_alertgroup`.`root_alert_group_id` IS NULL
       AND ((NOT `alerts_alertgroup`.`silenced`
             AND NOT `alerts_alertgroup`.`acknowledged`
             AND NOT `alerts_alertgroup`.`resolved`)
            OR (`alerts_alertgroup`.`acknowledged`
                AND NOT `alerts_alertgroup`.`resolved`))
       AND NOT `alerts_alertgroup`.`is_archived`)
ORDER BY `alerts_alertgroup`.`id` DESC
LIMIT 26
```

## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated
2023-01-22 00:53:11 +08:00
Ildar Iskhakov
c9b83906a0
Optimize alertgroups endpoint (#1188)
# What this PR does

Changing query to retrieve alert group in two requests instead of one
with `join`

old query:
```
SELECT `alerts_alertgroup`.`id`
FROM `alerts_alertgroup`
INNER JOIN `alerts_alertreceivechannel` ON (`alerts_alertgroup`.`channel_id` = `alerts_alertreceivechannel`.`id`)
WHERE (`alerts_alertreceivechannel`.`organization_id` = 1
       AND `alerts_alertreceivechannel`.`team_id` IS NULL
       AND NOT `alerts_alertgroup`.`is_archived`
       AND NOT `alerts_alertgroup`.`is_archived`
       AND `alerts_alertgroup`.`root_alert_group_id` IS NULL
       AND ((NOT `alerts_alertgroup`.`silenced`
             AND NOT `alerts_alertgroup`.`acknowledged`
             AND NOT `alerts_alertgroup`.`resolved`)
            OR (`alerts_alertgroup`.`acknowledged`
                AND NOT `alerts_alertgroup`.`resolved`))
       AND NOT `alerts_alertgroup`.`is_archived`)
ORDER BY `alerts_alertgroup`.`id` DESC
LIMIT 26
```

new query:
```
SELECT "alerts_alertgroup"."id"
FROM "alerts_alertgroup"
WHERE ("alerts_alertgroup"."channel_id" IN
         (SELECT U0."id"
          FROM "alerts_alertreceivechannel" U0
          WHERE (NOT (U0."integration" = maintenance)
                 AND U0."deleted_at" IS NULL
                 AND U0."organization_id" = 1
                 AND U0."team_id" IS NULL))
       AND NOT "alerts_alertgroup"."is_archived"
       AND NOT "alerts_alertgroup"."is_archived"
       AND "alerts_alertgroup"."root_alert_group_id" IS NULL
       AND ((NOT "alerts_alertgroup"."silenced"
             AND NOT "alerts_alertgroup"."acknowledged"
             AND NOT "alerts_alertgroup"."resolved")
            OR ("alerts_alertgroup"."acknowledged"
                AND NOT "alerts_alertgroup"."resolved"))
       AND NOT "alerts_alertgroup"."is_archived")
ORDER BY "alerts_alertgroup"."id" DESC
LIMIT 26
```


## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated
2023-01-22 00:14:48 +08:00
Ildar Iskhakov
83b1f069d0
Optimize alertgroups endpoint (#1186)
# What this PR does

## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated
2023-01-21 21:59:20 +08:00
Vadim Stepanov
2b0abf018c
Hide direct paging integrations (#1162)
# What this PR does
Hide direct paging integrations from the web UI. Related to
https://github.com/grafana/oncall/issues/823

## Checklist

- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-01-20 13:29:57 +00:00
Joey Orlando
98241b9a10
fake-data generation script + fixes for django-silk and django-debug-toolbar (#1128)
# What this PR does

## Main stuff

- add Python script to populate local Grafana/OnCall setup w/ large
amounts of fake data. Right now the data types that can be generated
are:
- teams and Admin users via the Grafana API (must be synced manually by
going into the UI before going onto the next step)
- Calendar Schedules which have three 8h oncall-shifts, via the OnCall
public API
- fixes `django-debug-toolbar` when being run in `docker-compose`
locally

## Other stuff
- documents how to easily modify the Grafana `docker-compose` container
provisioning configuration
- document solutions for two backend setup related issues encountered
when running the engine/celery workers locally, outside of
`docker-compose`, on an Apple silicon Mac
- fixes small bug in `grafana_plugin.helpers.client.APIClient.call_api`
where it would call `response.json()` for all requests, regardless of
whether or not the response actually contained data or not
- in `engine/settings/dev.py`, properly setup `django-silk` and document
the steps to use it locally
- make it possible to log out debug SQL queries by specifying
`DEV_DEBUG_VIEW_SQL_QUERIES` env var, rather than having to uncomment
out a section of `settings/dev.py`

## Which issue(s) this PR fixes

- Some local setup issues when trying to use `django-silk` and
`django-debug-toolbar`
- Makes it much easier to populate your local setup with a lot of fake
data
- Makes it possible to easily modify your local grafana's provisioning
configuration

## Checklist

- [ ] Tests updated (N/A)
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-01-20 09:19:41 +01:00
Vadim Stepanov
ccae9d86b3
Add an ability to use an escalation chain for direct paging (#1161)
# What this PR does
Adds an ability to page an escalation chain for a newly created direct
paging alert group using the internal API. Also [adds a forgotten
migration](32fc44e744)
related to the direct paging backend.
Related to https://github.com/grafana/oncall/issues/823

## Checklist

- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-01-19 18:51:57 +00:00
Vadim Stepanov
b8d78fd6bb
Allow messaging backends to be enabled/disabled per organization (#1151)
# What this PR does
Allows messaging backends to be enabled/disabled per organization when
getting a list of available personal notification channels.

## Checklist

- [x] Tests updated
- [ ] Documentation added (N/A)
- [x] `CHANGELOG.md` updated
2023-01-18 15:52:25 +00:00
Matias Bordese
d3062b56fd
Draft initial logic for user/schedule paging (#1098)
Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
2023-01-17 12:19:08 -03:00
Yulya Artyukhina
9129a720ef
Integration with grafana incident (#1081)
Check if Grafana Incident is enabled. If it is, add a button with a link
to declare Grafana Incident from Alert group in Slack and on Web.

Co-authored-by: Yulia Shanyrova <yulia.shanyrova@grafana.com>
2023-01-17 13:04:50 +01:00
Tommy
5bd8fbdef8
Add alert groups state filter (#1133)
# What this PR does
This PR added a new parameter (state) into the alert_group public API to
filter the state of the alert groups

## Which issue(s) this PR fixes
https://github.com/grafana/oncall/issues/684

## Checklist

- [x] Tests updated
- [x] Documentation added
- [x] `CHANGELOG.md` updated

Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
2023-01-17 10:28:29 +00:00
Matias Bordese
0d38fe2a7f
Web schedules overrides are the higher priority level (#1115)
Related to https://github.com/grafana/oncall-private/issues/1550
2023-01-13 08:58:35 -03:00
Matias Bordese
abbb5a8381
Update schedules query not to defer ical fields used for on-call check (#1114)
Do not defer cached ical fields which are later needed for calculating
on-call users listed in the schedules list page.
2023-01-09 14:10:23 -03:00
Matias Bordese
87fad5eec1
Add select_related to fetch schedules user group information (#1109) 2023-01-09 13:15:27 -03:00
Vadim Stepanov
7a1f176cb5
Schedule score backend (#338)
This PR adds an endpoint returning a schedule quality score, overloaded
users and comments on the existing issues (e.g. balance issues or gaps).

## Limitations
- Since working hours editor is not implemented yet, there are only two
scores taken into account: balance score and a score representing the
ratio of time when someone is on-call to the whole time period.
- Time period is now set to be constant (90 days from today), so **in
some cases the results will be inaccurate** (when rotations don't align
with the time period)
- It only takes primary rotations into account (overrides are ignored)

## Usage
`GET /api/internal/v1/schedules/<pk>/quality?date=<TOMORROW_DATE>`

Note that `date` should be tomorrow date, because we can only be sure
about changing tomorrow's shifts (some of the shifts for current day
could be "deleted" but still show up in the UI).

## Example response
```json
{
  "total_score": 90,
  "comments": ["Schedule has no gaps", "Schedule is well-balanced, but still can be improved"],
  "overloaded_users": ["USSZ5WRH2CUA9", "U74XJZSSQGBIH"]
}
```

Issue: #118
2023-01-04 16:49:58 +00:00
Matias Bordese
374f32f489 Handle no start date when calculating by day ical shift events 2023-01-02 11:53:49 -03:00
Joey Orlando
5967d5af63
remove apns + fix django-push-notifications migrations (#984)
- removes APNS support
- changes the `django-push-notification` library from the `iskhakov`
fork to the [`grafana`
fork](https://github.com/grafana/django-push-notifications). This new
fork basically just patches an issue which affected the database
migrations of this django app (previously the library would not respect
the `USER_MODEL` setting when creating its tables and would instead
reference the `auth_user` table.. which we don't want)
- add `--no-cache` flag to the `make build` command

**NOTE**
A migration should be applied as follows:
```bash
# remove the four push_notifications tables, which have improper foreign key references
python manage.py migrate push_notifications zero

# recreate the tables with the proper foreign key references
python manage.py migrate
```
2022-12-13 13:00:59 +01:00
Matias Bordese
67ac47ff32 Update SCHEDULES_WRITE fallback role to EDITOR 2022-12-09 12:56:35 -03:00
Innokentii Konstantinov
7341641b3f
Introduce org uuid (#947)
* Introduce org uuid

* Rename uuid_with_org_id to uuid_with_org_uuid

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2022-12-06 22:42:58 +08:00
Joey Orlando
f8c8ceb2f6
only grant admins read/write access to public api keys (#952) 2022-12-06 13:02:53 +01:00
Joey Orlando
9a7b8acd5a
centralize timezone validation + add serializer validation for on call shifts and schedules (#924)
* Centralize timezone validation into one spot + add serializer validation
for schedules and oncall shifts (both public and internal API)

* add engine-manage make command
2022-12-01 14:13:39 +01:00
Joey Orlando
9e598385f4
Add RBAC Support (#777)
* Modify plugin.json to support RBAC role registration

* defines 26 new custom roles in plugin.json. The main roles are:

- Admin: read/write access to everything in OnCall
- Reader: read access to everything in OnCall
- OnCaller : read access to everything in OnCall + edit access to Alert Groups and Schedules
- <object-type> Editor: read/write access to everything related to <object-type>
- <object-type> Reader: read access for <object-type>
- User Settings Admin: read/write access to all user's settings, not just own settings. This is in comparison to User Settings Editor which can only read/write own settings

* update changelog and documentation (#686)

* implement RBAC for OnCall backend

This commit refactors backend authorization. It trys to use RBAC authorization if the org's grafana instance supports it, otherwise it falls back to basic role authorization.

* update RBAC backend tests

* add tests for RBAC changes
- run backend tests as matrix where RBAC is enabled/disabled. When RBAC is enabled, the permissions granted are read from the role grants in the frontend's plugin.json file (instead of relying what we specify in RBACPermission.Permissions)
- remove --reuse-db --nomigrations flags from engine/tox.ini
- minor autoformatting changes to docker-compose-developer.yml

* remove --ds=settings.ci-test from pytest CI command

DJANGO_SETTINGS_MODULE is already specified as an env var so this is just unecessary duplication

* update gitignore

* update github action job name for "test"

* RBAC frontend changes

* refactors the use of basic roles (ex. Viewer, Editor, Admin) use RBAC permissions (when supported), or falling back to basic roles when RBAC is not supported.

- updates the UserAction enum in grafana-plugin/src/state/userAction.ts. Previously this was hardcoded to a list of strings that were being returned by the OnCall API. Now the values here correspond to the permissions in plugin.json (plus a fallback role)

* changes per Gabriel's comments:
- get rid of group attribute in rbac roles
- remove displayName role attribute
- remove hidden role attribute
- add back role to includes section

* don't try to update user timezone if they don't have permission
2022-11-29 09:41:56 +01:00
Michael Derynck
3582f9b08f
Improve Jinja Template feedback and error handling (#884)
* Improve feedback so template errors are given to user

* Add security error logging

* Add limits for templates, payloads, results

* Show popup error notification for webhook errors and template errors that don't have a result

* Update tests

* Split exceptions into warnings/errors to give more control when previewing, rendering, saving templates

* Limit title lengths

* Make TypeError a warning

* Adjust title length limit

* Remove length limiting on urlize since it is being done on template render

* Fix tests

* Add KeyError and ValueError to warnings

* No longer enforcing json result when saving webhook in case it is dependent on payload

* Add tests for expected exceptions coming from apply_jinja_template

* Update changelog

* Send raw post if template result is not JSON
2022-11-28 09:46:51 -07:00
Vadim Stepanov
dc6fcf5c05
Add internal API fields for the mobile app (#910)
* add permalinks list to internal API alertgroup view

* add user's name and full avatar URL to the user view

* make avatar_full_url a property

* fix tests

* fix user connection criteria
2022-11-28 15:52:31 +00:00
Vadim Stepanov
54d14d1025
Move MobileAppAuthToken view to mobile_app (#902) 2022-11-28 12:50:58 +00:00
Innokentii Konstantinov
3b73522f5a
Fix saving source link template (#898)
* Add test for update integration templates

* Fix saving source link template
2022-11-24 16:26:12 +08:00
Vadim Stepanov
255964ceaf
Mobile app messaging backend (#874)
* move mobile notifications to a separate backend, remove critical notification

* remove outdated mobile app code

* MOBILE_APP_PUSH_NOTIFICATIONS_ENABLED -> FEATURE_MOBILE_APP_INTEGRATION_ENABLED

* create error log if no devices are set up

* move mobile auth related code to the mobile_app Django app

* move mobile auth related code to the mobile_app Django app

* move mobile auth related code to the mobile_app Django app

* fix typing

* add GCMDevice todos

* add user connection capabilities

* add user connect/disconnect to the messaging backend

* move APNS endpoint to mobile_app Django app

* restore critical notifications

* support hackathon app

* tweak migrations so mobile app auth tokens are preserved

* reuse notify_by IDs

* use mobile app template to render push notification

* add GCM/FCM (Android) support

* fix unlink user

* logger.error -> logger.info
2022-11-23 15:56:43 +00:00
Joey Orlando
fd4877408a
remove grafana_plugin_management django app (#812)
* remove grafana_plugin_management django app

it seems to be no longer used or referenced. In addition apps.api.serializers.organization.PluginOrganizationSerializer was only
referenced from within grafana_plugin_management and is thereby safe
to remove.
2022-11-09 13:53:59 +01:00
Michael Derynck
fc78dd98da
Merge pull request #707 from grafana/add-region-to-organization
Add region info to organizations
2022-11-08 10:30:53 -07:00
Michael Derynck
f01d754851 Merge dev 2022-11-08 10:14:35 -07:00
Matias Bordese
a349d39f31 Enforce until on override shifts 2022-11-07 12:35:57 -03:00
Michael Derynck
25826690a8 Use common environment for templates 2022-11-05 00:31:51 -06:00
Maxim Mordasov
387b334d2a
Merge pull request #720 from grafana/matiasb/daily-shifts-by-day
Enable daily/by-day shifts option for web schedules
2022-11-04 14:23:09 +00:00
Michael Derynck
81702ba52d Merge dev 2022-11-03 12:42:36 -06:00
Michael Derynck
369a23551b Merge branch 'dev' into add-region-to-organization 2022-11-03 12:41:07 -06:00
Matias Bordese
b1a664df3b
Merge pull request #742 from grafana/matiasb/web-schedules-all-day-as-datetime
Update web schedule events to return all-day start/end as datetimes
2022-11-03 14:54:28 -03:00
Vadim Stepanov
e2456315af
Allow no-auth SMTP connection for email notifications (#759)
* DEFAULT_FROM_EMAIL -> EMAIL_FROM

* add EMAIL_FROM live setting

* EMAIL_FROM -> EMAIL_FROM_ADDRESS

* merge dev

* add test for get_from_email

* allow live settings to be null on internal API

* remove redundant tests
2022-11-03 16:18:37 +00:00
Matias Bordese
3e2d52ad51 Update web schedule events to return all-day as datetimes 2022-11-02 16:12:37 -03:00
Matias Bordese
98b187acd9 Add support for daily/by-day and custom interval 2022-11-02 16:12:16 -03:00
Matias Bordese
4bc3ed17a8 Make interval check more explicit 2022-11-02 16:12:16 -03:00
Matias Bordese
241283959a Enable daily/by-day shifts option for web schedules 2022-11-02 16:12:16 -03:00