Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agent): use default Loki datasource #186

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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