Skip to content

Commit

Permalink
feat(agent): use default Loki datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDemailly committed Jan 7, 2024
1 parent df26efd commit 1f7ce4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/agent/src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Import Third-party Dependencies
import { GrafanaApi } from "@myunisoft/loki";
import { GrafanaApi, Datasource as GrafanaDatasource } from "@myunisoft/loki";

export class Datasource {
#lokiApi: GrafanaApi;

private static datasource: Datasource;
private static cache: GrafanaDatasource;

private constructor(host: string) {
this.#lokiApi = new GrafanaApi({
Expand All @@ -17,10 +18,17 @@ export class Datasource {
}

static async Loki(host: string) {
if (this.cache !== undefined) {
return this.cache;
}

this.datasource ??= new Datasource(host);

const datasources = await this.datasource.fetchDatasources();
const lokiDatasources = datasources.filter((datasource) => datasource.type === "loki")!;
const datasource = datasources.find((datasource) => datasource.isDefault) ?? lokiDatasources.at(0)!;
this.cache = datasource;

return datasources.find((datasource) => datasource.type === "loki")!;
return datasource;
}
}
4 changes: 2 additions & 2 deletions src/agent/src/utils/getLokiUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { SigynInitializedRule, getConfig } from "@sigyn/config";
// Import Internal Dependencies
import { Datasource } from "../datasource";
import { durationOrCronToDate } from "./cron";
import { NotifierAlert } from "../notifier";
import { RuleNotifierAlert } from "../notifiers/rules.notifier";

export async function getLokiUrl(
rule: NotifierAlert["rule"],
rule: RuleNotifierAlert["rule"],
config: SigynInitializedRule
): Promise<string> {
const { loki } = getConfig();
Expand Down

0 comments on commit 1f7ce4f

Please sign in to comment.