@studion/infra-code-blocks
Version:
Studion common infra components
96 lines (95 loc) • 3.38 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GrafanaBuilder = void 0;
const connections_1 = require("./connections");
const grafana_1 = require("./grafana");
const slo_1 = require("./dashboards/slo");
const logs_and_traces_1 = require("./dashboards/logs-and-traces");
class GrafanaBuilder {
name;
connectionBuilders = [];
dashboardBuilders = [];
scopes = [];
plugins = [];
stackSlug;
folderName;
serviceAccountTokenRotation;
accessPolicyTokenRotation;
constructor(name) {
this.name = name;
}
withStackSlug(stackSlug) {
this.stackSlug = stackSlug;
return this;
}
withFolderName(folderName) {
this.folderName = folderName;
return this;
}
withServiceAccountTokenRotation(rotation) {
this.serviceAccountTokenRotation = rotation;
return this;
}
withAccessPolicyTokenRotation(rotation) {
this.accessPolicyTokenRotation = rotation;
return this;
}
addScope(...scopes) {
this.scopes.push(...scopes);
return this;
}
addPlugin(plugin) {
this.plugins.push(plugin);
return this;
}
addAmp(name, args) {
this.connectionBuilders.push((ctx, opts) => new connections_1.AMPConnection(name, { ...args, ...ctx }, opts));
return this;
}
addCloudWatchLogs(name, args) {
this.connectionBuilders.push((ctx, opts) => new connections_1.CloudWatchLogsConnection(name, { ...args, ...ctx }, opts));
return this;
}
addXRay(name, args) {
this.connectionBuilders.push((ctx, opts) => new connections_1.XRayConnection(name, { ...args, ...ctx }, opts));
return this;
}
addConnection(builder) {
this.connectionBuilders.push(builder);
return this;
}
addSloDashboard(config) {
this.dashboardBuilders.push((0, slo_1.createSloDashboard)(config));
return this;
}
addLogsAndTracesDashboard(config) {
this.dashboardBuilders.push((0, logs_and_traces_1.createLogsAndTracesDashboard)(config));
return this;
}
addDashboard(dashboard) {
this.dashboardBuilders.push(dashboard);
return this;
}
build(opts = {}) {
if (!this.stackSlug) {
throw new Error('Stack slug not provided. Make sure to call GrafanaBuilder.withStackSlug().');
}
if (!this.connectionBuilders.length) {
throw new Error('At least one connection is required. Call addConnection() to add a custom connection or use one of the existing connection builders.');
}
if (!this.dashboardBuilders.length) {
throw new Error('At least one dashboard is required. Call addDashboard() to add a custom dashboard or use one of the existing dashboard builders.');
}
return new grafana_1.Grafana(this.name, {
stackSlug: this.stackSlug,
connectionBuilders: this.connectionBuilders,
dashboardBuilders: this.dashboardBuilders,
folderName: this.folderName,
scopes: this.scopes,
plugins: this.plugins,
serviceAccountTokenRotation: this.serviceAccountTokenRotation,
accessPolicyTokenRotation: this.accessPolicyTokenRotation,
}, opts);
}
}
exports.GrafanaBuilder = GrafanaBuilder;