Commit graph

1455 commits

Author SHA1 Message Date
Michael Derynck
d1cb862125
Make sync settings configurable (#5002)
# What this PR does
Add settings for how sync jobs get split up to control throughput of
requests.
- `SYNC_V2_MAX_TASKS ` controls how many tasks can run concurrently
- `SYNC_V2_PERIOD_SECONDS` controls the time offset before starting
another set of tasks each time `SYNC_V2_MAX_TASKS` is reached
- `SYNC_V2_BATCH_SIZE` controls how many organizations will be sync'd
per task

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-09-10 14:17:46 +00:00
Matias Bordese
e93858e136
Add manual trigger support for webhooks (#4934)
Related to https://github.com/grafana/oncall/issues/4748

- Added support for additional filters when getting webhooks:
- `GET
/api/plugins/grafana-oncall-app/resources/webhooks/?integration=CALBFV7RRDH93`
  (filter webhooks that are enabled for the specified integration)
- `GET
/api/plugins/grafana-oncall-app/resources/webhooks/?trigger_type=0`
  (filter webhooks with the given trigger type)
- Allow triggering a Manual webhook using an alert group as context:
`POST /api/plugins/grafana-oncall-app/resources/webhooks/<webhook public
ID>/trigger_manual`
Example payload: `{"alert_group": "I4A4I1UPSA7IC"}`
(will return a 200 OK on success)

---------

Co-authored-by: Rares Mardare <rares.mardare@grafana.com>
2024-09-09 12:17:23 +00:00
Matias Bordese
dbba664a1f
Check for user.is_active during mobile app auth (#4990)
Related to https://github.com/grafana/support-escalations/issues/12253
2024-09-06 12:25:23 +00:00
Vadim Stepanov
bb2113db58
Make cloud email domain configurable (#4982)
# What this PR does

Fixes https://github.com/grafana/oncall-private/issues/2889

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-09-04 14:46:52 +00:00
Michael Derynck
cf69289888
Relax sync team serializer validation to match underlying model (#4976)
# What this PR does
- Teams do not require valid email addresses to be sync'd
- AvatarURL can be blank

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-09-03 18:47:54 +00:00
Matias Bordese
22cd4b86fc
Handle Slack invalid_auth error when posting alert group notification (#4970)
Also, make telegram error check more flexible (case insensitive, e.g. we
got some of these recently: `telegram.error.Unauthorized: Forbidden: bot
was blocked by the user`)
2024-09-02 16:37:27 +00:00
Vadim Stepanov
7b74b65168
Fix direct paging ack (#4957)
# What this PR does

Fixes https://github.com/grafana/oncall/issues/4760 (also provides a
workaround for https://github.com/grafana/oncall/issues/4761)

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-30 09:17:09 +00:00
Michael Derynck
962cc34432
Compress sync data (#4951)
# What this PR does
- Compresses sync data being sent to engine
- Minor fix to log messages when JSON parse errors occur

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-29 18:36:35 +00:00
Matias Bordese
f5be809b47
Improve schedule filters before generating user calendar export (#4950)
Avoid checking all schedules in an organization when filtering user
events during export.
This should help with some slow requests we are noticing.
2024-08-29 11:56:03 +00:00
Matias Bordese
c281813125
Check for incident enabled before making mobile app request (#4947)
Related to some issues we have noticed in our logs
([example](https://ops.grafana-ops.net/goto/8sa28TqIR?orgId=1)).
Also make sure unexpected responses are logged too.
2024-08-28 17:56:59 +00:00
Michael Derynck
586205368e
Sync process and backend plugin tweaks (#4939)
- Split up sync requests into batches to run concurrently
- Add more logging for when API calls to Grafana fail to parse
- Call sync from backend plugin when status is called
- Lock sync from backend plugin to only run every 5 mins
- Add timer display for API call to sync to return remaining time before
sync can execute
- Remove locks from celery task since it's work is low cost and we lock
in the backend plugin anyways.
2024-08-28 16:34:30 +00:00
Matias Bordese
d3f034b218
Handle a deleted organization triggering auth (#4937)
Related to https://github.com/grafana/oncall-private/issues/2203
2024-08-28 16:32:24 +00:00
Michael Derynck
9655a90f23
Fix plugin sync issues (#4930)
# What this PR does
- Fix incorrect response for error message on sync
- Remove sleep delay from sync (natural latency provides enough delay)

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-26 19:12:18 +00:00
Matias Bordese
0ac7c40671
Update org creation to use DB uniqueness constraint (#4926)
Fix issue related to
[logs](https://ops.grafana-ops.net/explore?schemaVersion=1&panes=%7B%2257p%22:%7B%22datasource%22:%22000000193%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22expr%22:%22%7Bnamespace%3D%5C%22amixr-prod%5C%22,%20cluster%3D%5C%22prod-us-central-0%5C%22,%20job%3D%5C%22amixr-prod%2Famixr-engine%5C%22%7D%20%7C%3D%20%5C%22user_management_organization.user_management_organization_stack_id_org_id_727b4929_uniq%5C%22%22,%22queryType%22:%22range%22,%22datasource%22:%7B%22type%22:%22loki%22,%22uid%22:%22000000193%22%7D,%22editorMode%22:%22code%22%7D%5D,%22range%22:%7B%22from%22:%22now-2d%22,%22to%22:%22now%22%7D%7D%7D&orgId=1)
(check for existing org using the unique DB index)
2024-08-26 15:03:26 +00:00
Yulya Artyukhina
c87d3018b9
Handle TimeoutError on sending message to Slack (#4916)
# What this PR does

## Which issue(s) this PR closes

Related to https://github.com/grafana/oncall-private/issues/2758

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-26 10:27:07 +00:00
Michael Derynck
a25d44da1a
Move validate_grafana_token_format to common location, use in sync_v2 (#4919)
# What this PR does
Moves validate_grafana_token_format to GrafanaAPIClient, use it in
sync_v2 to improve logging and skip requests that would not work.

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-23 19:52:53 +00:00
Michael Derynck
a5770309d9
Add more validation when updating api_token (#4918)
# What this PR does
Skip updating stored api_token for Grafana if it does not look like one.
Note: Exact format is not checked (prefix) since there are some
differences between versions for what API tokens might look like and
this should tolerate those differences.

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-23 18:21:57 +00:00
Michael Derynck
b2b64da86c
Fix api_token not being updated (#4912)
# What this PR does
Fixes organization api_token not being updated when it differs from what
is stored in the DB.

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-23 13:22:54 +00:00
Michael Derynck
042fb49aaf
Add logging for invalid api_tokens during sync (#4905)
# What this PR does
Add logging for when we skip an organization for sync if it is missing
its api token.

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-22 20:40:18 +00:00
Matias Bordese
66925366a6
Fix flaky test depending on DB ordering (#4907)
See
https://github.com/grafana/oncall/actions/runs/10513279782/job/29128524241
2024-08-22 18:56:59 +00:00
Matias Bordese
cd5e9955b9
Make sure organization token is valid before sync (#4904)
Since we will be triggering sync for orgs without a `last_time_synced`
set, we need to make sure the token is valid (previously both,
`last_time_synced` and the token, were updated from the frontend plugin)
2024-08-22 17:49:22 +00:00
Matias Bordese
87dd5c6623
Update sync task to consider never synced orgs (#4901) 2024-08-22 15:09:28 +00:00
Alyssa Wada
070abb9d4f
docs: unified slack (#4844)
# What this PR does
Adds documentation to support the Unified IRM Slack integration

## Which issue(s) this PR closes

Related to
[issue](https://github.com/grafana/technical-documentation/issues/961)

---------

Co-authored-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
2024-08-22 07:58:26 +00:00
Joey Orlando
0020c22143
add start_rotation_from_user_index field to /oncall_shifts internal API response (#4854)
# What this PR does

## Which issue(s) this PR closes

Closes https://github.com/grafana/support-escalations/issues/11866

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.

---------

Co-authored-by: Rares Mardare <rares.mardare@grafana.com>
2024-08-21 08:13:51 -04:00
Innokentii Konstantinov
5d92db18b1
Make root command configurable (#4863)
Makes IRM root command configurable via env
2024-08-21 06:54:47 +00:00
Michael Derynck
a16525ea45
Push sync from backend plugins (#4861)
# What this PR does
Change push sync to have a lock to ensure only 1 instance runs at a
time. Also adds argument to optionally specify which orgs to sync. Added
some more log messages.

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-20 16:20:33 +00:00
Vadim Stepanov
68caa12d5b
Fix SSR push notifications for deleted orgs (#4868)
following up on https://github.com/grafana/oncall/pull/4813, stop
sending SSR reminders for on-call schedules from deleted orgs
2024-08-20 11:32:20 +00:00
Innokentii Konstantinov
a3684a8ddc
Add stack_id to Tenant dataclass (#4864)
Fix retrying chatops_proxy tasks

---------

Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
2024-08-20 11:24:53 +00:00
Joey Orlando
b54384dee6
second AlertGroup.slack_log_message migration (#4862)
# What this PR does

Follow up to https://github.com/grafana/oncall/pull/4858

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-20 11:11:25 +00:00
Joey Orlando
82410429b4
remove leftofter/deprecated slack log report tasks (#4858)
# What this PR does

Follow up to https://github.com/grafana/oncall/pull/4686

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-19 19:10:46 -04:00
Ildar Iskhakov
48725888d1
Move slack log report from message thread to button (#4686)
# What this PR does

Continuation of [Add slack button to show log report
#4641](https://github.com/grafana/oncall/pull/4641)

## Which issue(s) this PR closes

Closes https://github.com/grafana/oncall/issues/3849

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.

---------

Co-authored-by: Joey Orlando <joseph.t.orlando@gmail.com>
Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2024-08-19 20:17:06 +00:00
Joey Orlando
0c96427cfc
fix apps.telegram.tasks.send_log_and_actions_message retrying tasks (#4851)
# What this PR does

It _appears_ like Telegram may have changed one of the error messages
they return for `telegram.error.BadRequest`. This _may_ be causing us to
infinitely retry some of these tasks.

Previously we were checking for two variants of the same type of error
message:
- "Message to reply not found"
- "Replied message not found"

_However_, if I search for the following [in the
logs](https://ops.grafana-ops.net/goto/hMgBb8CSR?orgId=1):
```logql
{namespace="amixr-prod"} |~ `(Message to be replied not found|Message to reply not found|Replied message not found)`
````
I _only_ see references to "Message to be replied not found". I have
updated references to the former to this new error log message we are
seeing.

Also:
- deduplicate some of the words we check for in
`telegram.error.BadRequest` and `telegram.error.Unauthorized` into
`apps.telegram.client.TelegramClient.BadRequestMessage` and
`apps.telegram.client.TelegramClient.UnauthorizedMessage` respectively
- deduplicate some of the wording we use in the `reason` arg passed to
`TelegramToUserConnector.create_telegram_notification_error` into
`apps.telegram.models.connectors.personal.TelegramToUserConnector.NotificationErrorReason`
- standardize how we check the `message` attribute of
`telegram.error.TelegramError`s into a new `error_message_is` static
method on `apps.telegram.client.TelegramClient`
- previously we would check these error messages in two different ways:
  ```python3
  # style 1
  if "error message to check" in e.message:
    # do something

  # style 2
  if error.message == "error message to check":
    # do something
  ```

## Which issue(s) this PR closes

Closes https://github.com/grafana/oncall-private/issues/2868

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-19 14:05:40 -04:00
Michael Derynck
f79445fbcb
Fix pagination behavior when page # exceeds search results (#4817)
# What this PR does
Change pagination to return last available page if the page number
exceeds the pages available instead of returning 404. This came up from
if the user is on a page other than the first and they enter a search
and the number of search results are smaller than what would be needed
to reach the current page number it would give a blank page and 404.

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.

---------

Co-authored-by: Rares Mardare <rares.mardare@grafana.com>
2024-08-19 13:59:01 +00:00
Dominik Broj
06d19bf6e9
New OnCall plugin initialization process (#4657)
# What this PR does

New OnCall plugin initialization process

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.

---------

Co-authored-by: Michael Derynck <michael.derynck@grafana.com>
Co-authored-by: Matias Bordese <mbordese@gmail.com>
2024-08-16 16:43:52 +00:00
Matias Bordese
a416863a28
Update alert groups public API filters support (#4832)
Related to https://github.com/grafana/oncall/issues/4747

- include labels in response
- allow filtering by labels
- allow filtering by started_at
- update docs
2024-08-15 19:58:25 +00:00
Joey Orlando
67fc52d56a
add POST /escalation public API endpoint + add public API docs for teams/organization endpoints (#4815)
# What this PR does

- Adds a `POST /escalation` public endpoint (equivalent to the internal
direct paging API endpoint)
- Adds public API documentation for teams and organization endpoints

<img width="1140" alt="Screenshot 2024-08-15 at 12 49 40"
src="https://github.com/user-attachments/assets/e0e8d6bb-f3ac-4f9e-bdf7-e8926949cc3b">

## Which issue(s) this PR closes

Closes https://github.com/grafana/oncall-private/issues/2859
Closes https://github.com/grafana/oncall/issues/2448

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-15 18:31:35 +00:00
Yulya Artyukhina
64bf1e5096
Speed up internal api endpoints (#4830)
# What this PR does
Reduces number of calls to db for `/schedules`, `/alertgroups` and
`/users` endpoints.
Fixes the issue when there was an additional call to db to get
organization url to build user avatar full link.

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-15 14:20:55 +00:00
Innokentii Konstantinov
27c741213f
Escalate deprecation messages (#4811)
# What this PR does
Add two deprecations messages for /escalate command
1. If integration is not yet upgraded to Grafana IRM Slack integration -
just ephemeral message asking to upgrade
2. If integration is already upgraded - deprecation message, command
will not work, but ask to use /grafana-irm escalate
2024-08-15 08:34:33 +00:00
Joey Orlando
eb777f5415
address Google OAuth2 issues where user didn't grant us the https://www.googleapis.com/auth/calendar.events.readonly scope (#4802)
# What this PR does

Follow up PR to https://github.com/grafana/oncall/pull/4792

Basically if when communicating with Google Calendar's API we encounter
an HTTP 403, or the Google client throws a
`google.auth.exceptions.RefreshError` this means one of three things:
1. the refresh token we have persisted for the user is missing the
`https://www.googleapis.com/auth/calendar.events.readonly` scope (HTTP
403)
2. the Google user has been deleted
(`google.auth.exceptions.RefreshError`)
3. the refresh token has expired (`google.auth.exceptions.RefreshError`)

To prevent scenario 1 above from happening in the future we now will
check that the token has been granted the required scopes. If the user
doesn't grant us all the necessary scopes, we will show them an error
message in the UI:
https://www.loom.com/share/0055ef03192b4154b894c2221cecbd5f

For tokens that were granted prior to this PR and which are missing the
required scope, we will show the user a dismissible warning banner in
the UI letting them know that they will need to reconnect their account
and grant us the missing permissions (see [this second demo
video](https://www.loom.com/share/bf2ee8b840864a64893165370a892bcd)
showing this).

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.

---------

Co-authored-by: Dominik <dominik.broj@grafana.com>
2024-08-14 18:02:34 -04:00
Yulya Artyukhina
29bd42c0b1
Fix collecting metrics (#4822)
# What this PR does
Reverts the accidental removal of the ApplicationMetricsCollector from
the metric register

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-14 13:53:43 +00:00
Matias Bordese
a1c67cdfe7
Address deprecation warnings in tests (#4681)
Related to https://github.com/grafana/oncall/issues/4496

[No
warnings](https://github.com/grafana/oncall/actions/runs/10359091611/job/28674729718?pr=4681#step:5:305)!
2024-08-13 20:51:18 +00:00
Vadim Stepanov
4528dc1d5c
Better logging for send_message_to_fcm_device (#4814) 2024-08-13 17:47:43 +00:00
Vadim Stepanov
01f7007f8c
Deleted organization fixes (#4813)
# What this PR does

Makes it so that:
* Shift swap requests are not created from Google Calendar for deleted
orgs
* On-call shift mobile app notifications are not sent to users from
deleted orgs

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-13 16:27:39 +00:00
Yulya Artyukhina
18726432af
Reduce a number of requests to db on alert_receive_channel internal api endpoint (#4805)
# What this PR does
Reduce a number of requests to db on `alert_receive_channel` internal
api endpoint
from
<img width="348" alt="Screenshot 2024-08-12 at 14 55 05"
src="https://github.com/user-attachments/assets/fcbadfaf-4f01-40ae-879a-86115e13984d">
to
<img width="341" alt="Screenshot 2024-08-12 at 14 55 13"
src="https://github.com/user-attachments/assets/4fbdc3f8-297a-44ed-acfa-41f6245b2a5e">

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-13 09:24:30 +00:00
Innokentii Konstantinov
b3119e5266
chore: return 422 on slack step not found (#4810)
# What this PR does
Return 422 instead of 500 when the handler for the slack incoming event
was not found to gracefully omit events on call not subscribed to.
2024-08-13 07:57:17 +00:00
Yulya Artyukhina
503939783f
Add settings var to choose application metrics to collect (#4781)
# What this PR does
Adds settings var `METRICS_TO_COLLECT` to choose what metrics should be
collected by `ApplicationMetricsCollector`.
It allows to collect different application metrics using different
exporters.

## Which issue(s) this PR closes

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-12 10:37:48 +00:00
dependabot[bot]
f68b954b72
Bump djangorestframework from 3.14.0 to 3.15.2 in /engine (#4593)
Bumps
[djangorestframework](https://github.com/encode/django-rest-framework)
from 3.14.0 to 3.15.2.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/encode/django-rest-framework/releases">djangorestframework's
releases</a>.</em></p>
<blockquote>
<h2>Version 3.15.1</h2>
<h2>What's Changed</h2>
<ul>
<li>Update the message to be consistent with the Django `HttpResponseBa…
by <a href="https://github.com/maycuatroi"><code>@​maycuatroi</code></a>
in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9287">encode/django-rest-framework#9287</a></li>
<li>Make <code>inflection</code> package truly optional by <a
href="https://github.com/browniebroke"><code>@​browniebroke</code></a>
in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9303">encode/django-rest-framework#9303</a></li>
<li>Fix broken links in release notes for 3.15 by <a
href="https://github.com/browniebroke"><code>@​browniebroke</code></a>
in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9305">encode/django-rest-framework#9305</a></li>
<li>TokenAdmin.autocomplete_fields Breaks Some Use Cases, Revert by <a
href="https://github.com/alexdlaird"><code>@​alexdlaird</code></a> in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9301">encode/django-rest-framework#9301</a></li>
<li>Add drf-sendables to third-party-packages.md by <a
href="https://github.com/amikrop"><code>@​amikrop</code></a> in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9261">encode/django-rest-framework#9261</a></li>
<li>Revert &quot;feat: Add some changes to ValidationError to support
django style vad…&quot; by <a
href="https://github.com/auvipy"><code>@​auvipy</code></a> in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9326">encode/django-rest-framework#9326</a></li>
<li>Revert &quot;Re-prefetch related objects after updating&quot; by <a
href="https://github.com/auvipy"><code>@​auvipy</code></a> in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9327">encode/django-rest-framework#9327</a></li>
<li>Revert <a
href="https://redirect.github.com/encode/django-rest-framework/issues/8863">#8863</a>
by <a
href="https://github.com/tomchristie"><code>@​tomchristie</code></a> in
<a
href="https://redirect.github.com/encode/django-rest-framework/pull/9330">encode/django-rest-framework#9330</a></li>
<li>Revert <a
href="https://redirect.github.com/encode/django-rest-framework/issues/8009">#8009</a>
by <a
href="https://github.com/tomchristie"><code>@​tomchristie</code></a> in
<a
href="https://redirect.github.com/encode/django-rest-framework/pull/9332">encode/django-rest-framework#9332</a></li>
<li>Revert <a
href="https://redirect.github.com/encode/django-rest-framework/issues/9030">#9030</a>
by <a
href="https://github.com/tomchristie"><code>@​tomchristie</code></a> in
<a
href="https://redirect.github.com/encode/django-rest-framework/pull/9333">encode/django-rest-framework#9333</a></li>
<li>Revert &quot;Fix NamespaceVersioning ignoring DEFAULT_VERSION on
non-None namespaces&quot; by <a
href="https://github.com/auvipy"><code>@​auvipy</code></a> in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9335">encode/django-rest-framework#9335</a></li>
<li><code>SearchFilter.get_search_terms</code> returns list. by <a
href="https://github.com/tomchristie"><code>@​tomchristie</code></a> in
<a
href="https://redirect.github.com/encode/django-rest-framework/pull/9338">encode/django-rest-framework#9338</a></li>
<li>Version 3.15.1 by <a
href="https://github.com/tomchristie"><code>@​tomchristie</code></a> in
<a
href="https://redirect.github.com/encode/django-rest-framework/pull/9339">encode/django-rest-framework#9339</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/maycuatroi"><code>@​maycuatroi</code></a> made
their first contribution in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9287">encode/django-rest-framework#9287</a></li>
<li><a
href="https://github.com/alexdlaird"><code>@​alexdlaird</code></a> made
their first contribution in <a
href="https://redirect.github.com/encode/django-rest-framework/pull/9301">encode/django-rest-framework#9301</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/encode/django-rest-framework/compare/3.15.0...3.15.1">https://github.com/encode/django-rest-framework/compare/3.15.0...3.15.1</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="c7a7eae551"><code>c7a7eae</code></a>
Version 3.15.2 (<a
href="https://redirect.github.com/encode/django-rest-framework/issues/9439">#9439</a>)</li>
<li><a
href="3b41f01241"><code>3b41f01</code></a>
Fix potential XSS vulnerability in break_long_headers template filter
(<a
href="https://redirect.github.com/encode/django-rest-framework/issues/9435">#9435</a>)</li>
<li><a
href="fe92f0dd0d"><code>fe92f0d</code></a>
Add <code>__hash__</code> method for
<code>permissions.OperandHolder</code> class (<a
href="https://redirect.github.com/encode/django-rest-framework/issues/9417">#9417</a>)</li>
<li><a
href="fbdab09c77"><code>fbdab09</code></a>
docs: Correct some evaluation results and a httpie option in Tutorial1
(<a
href="https://redirect.github.com/encode/django-rest-framework/issues/9421">#9421</a>)</li>
<li><a
href="36d5c0e74f"><code>36d5c0e</code></a>
tests: Check urlpatterns after cleanups (<a
href="https://redirect.github.com/encode/django-rest-framework/issues/9400">#9400</a>)</li>
<li><a
href="9d4ed054bf"><code>9d4ed05</code></a>
Don't use Windows line endings</li>
<li><a
href="b34bde47d7"><code>b34bde4</code></a>
Fix typo in setup.cfg setting</li>
<li><a
href="ab681f2d5e"><code>ab681f2</code></a>
Update requirements in docs</li>
<li><a
href="22377241a8"><code>2237724</code></a>
bump pygments (security hygiene)</li>
<li><a
href="d58b8da591"><code>d58b8da</code></a>
Update deprecation hints</li>
<li>Additional commits viewable in <a
href="https://github.com/encode/django-rest-framework/compare/3.14.0...3.15.2">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=djangorestframework&package-manager=pip&previous-version=3.14.0&new-version=3.15.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/grafana/oncall/network/alerts).

</details>

> **Note**
> Automatic rebases have been disabled on this pull request as it has
been open for over 30 days.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Joey Orlando <joseph.t.orlando@gmail.com>
Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2024-08-09 19:06:43 +00:00
Joey Orlando
6eac05abaf
apps.webhooks.tasks.trigger_webhook.execute_webhook task - don't retry on requests.exceptions.SSLError (#4796)
# Which issue(s) this PR closes

Address retrying `apps.webhooks.tasks.trigger_webhook.execute_webhook`
task when `requests.exceptions.SSLError` is raised
([logs](https://ops.grafana-ops.net/goto/vqrouqrIR?orgId=1)). Don't
retry the task on these exceptions as retrying will not help. From the
[`request`'s
docs](https://requests.readthedocs.io/en/latest/user/advanced/#ssl-cert-verification):
> By default, SSL verification is enabled, and Requests will throw a
SSLError if it’s unable to verify the certificate

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-09 17:45:09 +00:00
Joey Orlando
92ac1d884f
address occasional missing nextCursor data key from GCOM GET /instances (#4794)
# What this PR does

Addressing this task exception
([logs](https://ops.grafana-ops.net/goto/rkVAurrSR?orgId=1)):
```
2024-08-08 16:30:49,455 source=engine:celery worker=ForkPoolWorker-18 task_id=969226be-64a8-4616-ac32-3909d1f0cb60 task_name=apps.grafana_plugin.tasks.sync.start_sync_organizations name=celery.app.trace level=ERROR Task apps.grafana_plugin.tasks.sync.start_sync_organizations[969226be-64a8-4616-ac32-3909d1f0cb60] raised unexpected: KeyError('nextCursor')
```

[This
conversation](https://raintank-corp.slack.com/archives/C0K031RP1/p1723158123932529)
in `#grafana-com-dev` has more context. The _tldr;_ takeaway after
chatting w/ the GCOM team was lets simply retry requests in this case.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-09 15:42:10 +00:00
Joey Orlando
c6a5c8ef10
add better logging for Google Calendar task (#4792)
# What this PR does

Attempting to solve some Celery retry errors we're seeing around
`apps.google.tasks.sync_out_of_office_calendar_events_for_user`. This PR
adds better logging and documents some findings so far.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-08-09 14:51:20 +00:00