@pagerduty/backstage-plugin-entity-processor 0.1.0-next.0 → 0.1.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/dist/index.cjs.js +60 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -14
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
**Bring the power of PagerDuty to Backstage!**
|
|
8
8
|
The PagerDuty plugin reduces the cognitive load on developers responsible for maintaining services in production. Instead of having to go to PagerDuty's console, you can now access the necessary information directly within Backstage. This includes finding active incidents or opening a new incident, reviewing recent changes made to the service, and checking who is on-call.
|
|
9
9
|
|
|
10
|
-
The PagerDuty
|
|
10
|
+
The PagerDuty Entity Processor package allows users to map their existing PagerDuty services to existing Backstage entities by leveraging point and click instead of updating all configuration files on every single service. With this we want to ease the path for existing PagerDuty customers to integrate easily with Backstage and smoothly transition to a configuration based approach.
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
- **
|
|
15
|
-
|
|
14
|
+
- **Entity processor** This feature augments Backstage entities with the appropiate PagerDuty annotations to allow easy mapping between Backstage entities and existing PagerDuty services.
|
|
16
15
|
|
|
17
16
|
## Getting Started
|
|
18
17
|
|
|
@@ -25,18 +24,17 @@ The installation of the PagerDuty plugin for Backstage is done with *yarn* as al
|
|
|
25
24
|
To install this plugin run the following command from the Backstage root folder.
|
|
26
25
|
|
|
27
26
|
```bash
|
|
28
|
-
yarn add --cwd packages/backend @pagerduty/backstage-plugin-
|
|
27
|
+
yarn add --cwd packages/backend @pagerduty/backstage-plugin-entity-processor
|
|
29
28
|
```
|
|
30
29
|
|
|
31
30
|
### Configuration
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
...
|
|
34
33
|
|
|
35
34
|
## Support
|
|
36
35
|
|
|
37
|
-
If you need help with this plugin, please open an issue in [GitHub](https://github.com/PagerDuty/backstage-plugin-
|
|
36
|
+
If you need help with this plugin, please open an issue in [GitHub](https://github.com/PagerDuty/backstage-plugin-entity-provider), reach out on the [Backstage Discord server](https://discord.gg/backstage-687207715902193673) or [PagerDuty's community forum](https://community.pagerduty.com).
|
|
38
37
|
|
|
39
38
|
## Contributing
|
|
40
39
|
|
|
41
40
|
If you are interested in contributing to this project, please refer to our [Contributing Guidelines](https://github.com/PagerDuty/backstage-plugin-backend/blob/main/CONTRIBUTING.md).
|
|
42
|
-
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
var alpha = require('@backstage/plugin-catalog-node/alpha');
|
|
7
|
+
|
|
5
8
|
var __defProp = Object.defineProperty;
|
|
6
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
10
|
var __publicField = (obj, key, value) => {
|
|
@@ -9,12 +12,14 @@ var __publicField = (obj, key, value) => {
|
|
|
9
12
|
return value;
|
|
10
13
|
};
|
|
11
14
|
class PagerDutyEntityProcessor {
|
|
12
|
-
|
|
13
|
-
// return entity.kind === 'Component';
|
|
14
|
-
// }
|
|
15
|
-
constructor(logger) {
|
|
15
|
+
constructor({ logger, store }) {
|
|
16
16
|
__publicField(this, "logger");
|
|
17
|
+
__publicField(this, "store");
|
|
18
|
+
__publicField(this, "shouldProcessEntity", (entity) => {
|
|
19
|
+
return entity.kind === "Component";
|
|
20
|
+
});
|
|
17
21
|
this.logger = logger;
|
|
22
|
+
this.store = store;
|
|
18
23
|
}
|
|
19
24
|
getProcessorName() {
|
|
20
25
|
return "PagerDutyEntityProcessor";
|
|
@@ -22,17 +27,60 @@ class PagerDutyEntityProcessor {
|
|
|
22
27
|
// static fromConfig(): PagerDutyEntityProcessor {
|
|
23
28
|
// return new PagerDutyEntityProcessor();
|
|
24
29
|
// }
|
|
25
|
-
async
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
entity.metadata.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
async postProcessEntity(entity) {
|
|
31
|
+
if (this.shouldProcessEntity(entity)) {
|
|
32
|
+
this.logger.info(`Processing entity: ${JSON.stringify(entity)}`);
|
|
33
|
+
const entityRef = `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase();
|
|
34
|
+
this.logger.info(`Looking for entity mapping with ref: ${entityRef}`);
|
|
35
|
+
try {
|
|
36
|
+
const mapping = await this.store.findEntityMappingByEntityRef("e4657ba9-bdc4-4375-b46c-fd7dc188090e");
|
|
37
|
+
if (mapping) {
|
|
38
|
+
this.logger.info(`Found mapping for entity: ${entity.metadata.name}`);
|
|
39
|
+
entity.metadata.annotations["pagerduty.com/service-id"] = mapping.serviceId;
|
|
40
|
+
} else {
|
|
41
|
+
this.logger.info(`No mapping found for entity: ${entity.metadata.name}`);
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
this.logger.error(`Error processing entity: ${entity.metadata.name}`);
|
|
45
|
+
this.logger.error(JSON.stringify(error));
|
|
46
|
+
}
|
|
32
47
|
}
|
|
33
48
|
return entity;
|
|
34
49
|
}
|
|
35
50
|
}
|
|
36
51
|
|
|
37
|
-
|
|
52
|
+
class PagerDutyBackendDatabase {
|
|
53
|
+
constructor(db) {
|
|
54
|
+
this.db = db;
|
|
55
|
+
}
|
|
56
|
+
static async create(knex) {
|
|
57
|
+
return new PagerDutyBackendDatabase(knex);
|
|
58
|
+
}
|
|
59
|
+
async findEntityMappingByEntityRef(entityRef) {
|
|
60
|
+
const rawEntity = await this.db("pagerduty_entity_mapping").where("entityRef", entityRef).first();
|
|
61
|
+
return rawEntity;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const pagerDutyEntityProcessor = backendPluginApi.createBackendModule({
|
|
66
|
+
pluginId: "catalog",
|
|
67
|
+
moduleId: "pagerduty-entity-processor",
|
|
68
|
+
register(env) {
|
|
69
|
+
env.registerInit({
|
|
70
|
+
deps: {
|
|
71
|
+
logger: backendPluginApi.coreServices.logger,
|
|
72
|
+
database: backendPluginApi.coreServices.database,
|
|
73
|
+
catalog: alpha.catalogProcessingExtensionPoint
|
|
74
|
+
},
|
|
75
|
+
async init({ logger, database, catalog }) {
|
|
76
|
+
const store = await PagerDutyBackendDatabase.create(
|
|
77
|
+
await database.getClient()
|
|
78
|
+
);
|
|
79
|
+
catalog.addProcessor(new PagerDutyEntityProcessor({ logger, store }));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
exports["default"] = pagerDutyEntityProcessor;
|
|
38
86
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/processor/PagerDutyEntityProcessor.ts"],"sourcesContent":["import { LoggerService } from \"@backstage/backend-plugin-api\";\nimport { Entity } from \"@backstage/catalog-model\";\nimport { CatalogProcessor } from \"@backstage/plugin-catalog-node\";\n\n/**\n * A function which given an entity, determines if it should be processed for linguist tags.\n * @public\n */\
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/processor/PagerDutyEntityProcessor.ts","../src/db/PagerDutyBackendDatabase.ts","../src/module.ts"],"sourcesContent":["import { LoggerService } from \"@backstage/backend-plugin-api\";\nimport { Entity } from \"@backstage/catalog-model\";\nimport { CatalogProcessor } from \"@backstage/plugin-catalog-node\";\nimport { PagerDutyBackendStore } from \"../db\";\n\n/**\n * A function which given an entity, determines if it should be processed for linguist tags.\n * @public\n */\nexport type ShouldProcessEntity = (entity: Entity) => boolean;\n\nexport interface PagerDutyEntityProcessorOptions {\n logger: LoggerService;\n store: PagerDutyBackendStore;\n};\n\nexport class PagerDutyEntityProcessor implements CatalogProcessor {\n private logger: LoggerService;\n private store: PagerDutyBackendStore;\n private shouldProcessEntity: ShouldProcessEntity = (entity: Entity) => {\n return entity.kind === 'Component';\n }\n\n constructor({ logger, store }: PagerDutyEntityProcessorOptions) {\n this.logger = logger;\n this.store = store;\n }\n\n getProcessorName(): string {\n return \"PagerDutyEntityProcessor\";\n }\n\n // static fromConfig(): PagerDutyEntityProcessor {\n // return new PagerDutyEntityProcessor();\n // }\n\n async postProcessEntity(entity: Entity): Promise<Entity> {\n if (this.shouldProcessEntity(entity)) {\n this.logger.info(`Processing entity: ${JSON.stringify(entity)}`);\n\n const entityRef = `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase();\n this.logger.info(`Looking for entity mapping with ref: ${entityRef}`);\n\n try{\n const mapping = await this.store.findEntityMappingByEntityRef(\"e4657ba9-bdc4-4375-b46c-fd7dc188090e\");\n if (mapping) {\n this.logger.info(`Found mapping for entity: ${entity.metadata.name}`);\n entity.metadata.annotations![\"pagerduty.com/service-id\"] = mapping.serviceId;\n } else {\n this.logger.info(`No mapping found for entity: ${entity.metadata.name}`);\n }\n } catch (error) {\n this.logger.error(`Error processing entity: ${entity.metadata.name}`);\n this.logger.error(JSON.stringify(error));\n } \n }\n\n return entity;\n }\n}","import { Knex } from 'knex';\n\nexport type RawDbEntityResultRow = {\n id: string;\n entityRef: string;\n serviceId: string;\n processedDate?: Date;\n};\n\n/** @public */\nexport interface PagerDutyBackendStore {\n findEntityMappingByEntityRef(entityRef: string): Promise<RawDbEntityResultRow | undefined>\n}\n\n\n/** @public */\nexport class PagerDutyBackendDatabase implements PagerDutyBackendStore {\n static async create(knex: Knex): Promise<PagerDutyBackendStore> {\n \n return new PagerDutyBackendDatabase(knex);\n }\n\n constructor(private readonly db: Knex) { }\n\n async findEntityMappingByEntityRef(entityRef: string): Promise<RawDbEntityResultRow | undefined> {\n const rawEntity = await this.db<RawDbEntityResultRow>('pagerduty_entity_mapping')\n .where('entityRef', entityRef)\n .first();\n\n return rawEntity;\n }\n}","import { coreServices, createBackendModule } from \"@backstage/backend-plugin-api\";\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\nimport { PagerDutyEntityProcessor } from \"./processor\";\nimport { PagerDutyBackendDatabase, PagerDutyBackendStore } from \"./db/PagerDutyBackendDatabase\";\n\n\n\n/** @public */\nexport const pagerDutyEntityProcessor = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'pagerduty-entity-processor',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n database: coreServices.database,\n catalog: catalogProcessingExtensionPoint,\n },\n async init({ logger, database, catalog }) {\n\n const store: PagerDutyBackendStore = await PagerDutyBackendDatabase.create(\n await database.getClient(),\n );\n\n catalog.addProcessor(new PagerDutyEntityProcessor({ logger, store}));\n },\n });\n },\n});\n"],"names":["createBackendModule","coreServices","catalogProcessingExtensionPoint"],"mappings":";;;;;;;;;;;;;AAgBO,MAAM,wBAAqD,CAAA;AAAA,EAO9D,WAAY,CAAA,EAAE,MAAQ,EAAA,KAAA,EAA0C,EAAA;AANhE,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,qBAAA,EAA2C,CAAC,MAAmB,KAAA;AACnE,MAAA,OAAO,OAAO,IAAS,KAAA,WAAA,CAAA;AAAA,KAC3B,CAAA,CAAA;AAGI,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AACd,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AAAA,GACjB;AAAA,EAEA,gBAA2B,GAAA;AACvB,IAAO,OAAA,0BAAA,CAAA;AAAA,GACX;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,kBAAkB,MAAiC,EAAA;AACrD,IAAI,IAAA,IAAA,CAAK,mBAAoB,CAAA,M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node';
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
4
2
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
declare class PagerDutyEntityProcessor implements CatalogProcessor {
|
|
10
|
-
private logger;
|
|
11
|
-
constructor(logger: LoggerService);
|
|
12
|
-
getProcessorName(): string;
|
|
13
|
-
preProcessEntity(entity: Entity): Promise<Entity>;
|
|
14
|
-
}
|
|
3
|
+
/** @public */
|
|
4
|
+
declare const pagerDutyEntityProcessor: _backstage_backend_plugin_api.BackendFeatureCompat;
|
|
15
5
|
|
|
16
|
-
export {
|
|
6
|
+
export { pagerDutyEntityProcessor as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagerduty/backstage-plugin-entity-processor",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.10",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,21 +24,18 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@backstage/backend-common": "^0.21.6",
|
|
26
26
|
"@backstage/backend-defaults": "^0.2.16",
|
|
27
|
-
"@backstage/backend-plugin-api": "^0.6.
|
|
27
|
+
"@backstage/backend-plugin-api": "^0.6.20",
|
|
28
28
|
"@backstage/config": "^1.2.0",
|
|
29
29
|
"@backstage/plugin-catalog-node": "^1.12.2",
|
|
30
|
+
"@pagerduty/backstage-plugin-common": "0.1.5-next.8",
|
|
30
31
|
"@rjsf/core": "^5.14.3",
|
|
31
32
|
"node-fetch": "^2.6.7",
|
|
32
33
|
"winston": "^3.2.1",
|
|
33
34
|
"yn": "^4.0.0",
|
|
34
35
|
"zod": "^3.22.4"
|
|
35
36
|
},
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"@pagerduty/backstage-plugin-common": "^0.1.4"
|
|
38
|
-
},
|
|
39
37
|
"devDependencies": {
|
|
40
38
|
"@backstage/cli": "^0.24.0",
|
|
41
|
-
"@pagerduty/backstage-plugin-common": "^0.1.4",
|
|
42
39
|
"@types/node": "^20.9.2",
|
|
43
40
|
"@types/node-fetch": "2.6.11",
|
|
44
41
|
"@types/supertest": "^2.0.12",
|