oncall-engine/grafana-plugin
Dominik Broj 96b88ed917
improve error handling and notifications for labels (#3446)
https://github.com/grafana/oncall-private/issues/2304


# What this PR does
- introduce @WithGlobalNotifiaction decorator to simplify setting
notifications
- use it for alert group labels
- add npm commands to simplify linking gops-labels package 

## 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] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-11-29 05:40:19 +00:00
..
e2e-tests stabilize e2e tests (#3349) 2023-11-17 10:07:12 +00:00
src improve error handling and notifications for labels (#3446) 2023-11-29 05:40:19 +00:00
tools Merge dev to main (#54) 2022-06-13 16:39:58 -06:00
.dockerignore WIP: Direct paging improvements (#3064) 2023-09-28 03:57:49 +00:00
.eslintignore generate types, create http client and add exemplary usage (#3384) 2023-11-29 05:16:13 +00:00
.eslintrc.js Webhook labels (#3383) 2023-11-22 11:17:41 +00:00
.gitignore add a couple of tests for users screen (#2612) 2023-08-02 15:42:48 +03:00
.prettierrc.js World, meet OnCall! 2022-06-03 08:09:47 -06:00
.stylelintrc add selector-max-type stylelint rule 2022-11-02 11:44:42 +00:00
babel.config.json add precommit rules for markdown/json files (#915) 2022-12-01 14:26:54 +01:00
Dockerfile.dev Feat(Dev): Improve Building of Grafana Plugin in Development Env + update node version (#1890) 2023-05-17 16:12:51 -04:00
jest.config.js generate types, create http client and add exemplary usage (#3384) 2023-11-29 05:16:13 +00:00
jest.setup.ts Get rid of installation token + add a bunch of tests (#624) 2022-11-21 16:26:00 +01:00
LICENSE World, meet OnCall! 2022-06-03 08:09:47 -06:00
package.json improve error handling and notifications for labels (#3446) 2023-11-29 05:40:19 +00:00
playwright.config.ts Alert group payload labels (#3434) 2023-11-27 17:53:54 +00:00
plopfile.js Merge dev to main (#54) 2022-06-13 16:39:58 -06:00
README.md generate types, create http client and add exemplary usage (#3384) 2023-11-29 05:16:13 +00:00
tsconfig.json generate types, create http client and add exemplary usage (#3384) 2023-11-29 05:16:13 +00:00
webpack.config.js increase mobile app verification token TTL from 1 minute to 5 minutes (#2859) 2023-08-22 17:09:59 +02:00
yarn.lock generate types, create http client and add exemplary usage (#3384) 2023-11-29 05:16:13 +00:00

Grafana OnCall

Developer-Friendly Alert Management with Brilliant Slack Integration

  • Connect monitoring systems
  • Collect and analyze data
  • On-call rotation
  • Automatic escalation
  • Never miss alerts with calls and SMS

Documentation

Development

Autogenerating TS types based on OpenAPI schema

⚠️ WARNING
Transition to this approach is in progress

Overview

In order to automate types creation and prevent API usage pitfalls, OnCall project is using the following approach:

  1. OnCall Engine (backend) exposes OpenAPI schema
  2. OnCall Grafana Plugin (frontend) autogenerates TS type definitions based on it
  3. OnCall Grafana Plugin (frontend) uses autogenerated types as a single source of truth for any backend-related interactions (url paths, request bodies, params, response payloads)

Instruction

  1. Whenever API contract changes, run yarn generate-types from grafana-plugin directory

  2. Then you can start consuming types and you can use fully typed http client:

    import { ApiSchemas } from 'network/oncall-api/api.types';
    import onCallApi from 'network/oncall-api/http-client';
    
    const {
      data: { results },
    } = await onCallApi.GET('/alertgroups/');
    const alertGroups: Array<ApiSchemas['AlertGroup']> = results;
    
  3. [Optional] If there is any property that is not yet exposed in OpenAPI schema and you already want to use it, you can append missing properties to particular schemas by editing grafana-plugin/src/network/oncall-api/types-generator/custom-schemas.ts file:

    export type CustomApiSchemas = {
      Alert: {
        propertyMissingInOpenAPI: string;
      };
      AlertGroup: {
        anotherPropertyMissingInOpenAPI: number[];
      };
    };
    

    Then add their names to CUSTOMIZED_SCHEMAS array in grafana-plugin/src/network/oncall-api/types-generator/generate-types.ts:

    const CUSTOMIZED_SCHEMAS = ['Alert', 'AlertGroup'];
    

    The outcome is that autogenerated schemas will be modified as follows:

    import type { CustomApiSchemas } from './types-generator/custom-schemas';
    
    export interface components {
        schemas: {
            Alert: CustomApiSchemas['Alert'] & {
                readonly id: string;
                ...
            };
            AlertGroup: CustomApiSchemas['AlertGroup'] & {
                readonly pk: string;
                ...
            },
            ...
        }
    }