Skip to content

refactor: change how grafana plugins are installed#211

Open
mandryllo wants to merge 8 commits intomasterfrom
refactor/grafana-plugins
Open

refactor: change how grafana plugins are installed#211
mandryllo wants to merge 8 commits intomasterfrom
refactor/grafana-plugins

Conversation

@mandryllo
Copy link
Copy Markdown
Collaborator

No description provided.

@mandryllo mandryllo requested review from bornast and droguljic May 5, 2026 15:07
@mandryllo mandryllo added the Don't merge Do not merge this PR label May 5, 2026
@droguljic droguljic added this to the v2 milestone May 5, 2026
Comment thread src/components/grafana/plugin-ready.ts Outdated
Comment on lines +4 to +7
type PluginReadyInputs = {
grafanaToken: pulumi.Input<string>;
pluginSlug: string;
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not export namespace PluginReady { export type Args = { ... } }?

Comment thread src/components/grafana/plugin-ready.ts Outdated
Comment on lines +13 to +20
const grafanaConfig = new pulumi.Config('grafana');
const grafanaUrl = grafanaConfig.get('url') ?? process.env.GRAFANA_URL;

if (!grafanaUrl) {
throw new Error(
'Grafana URL is not configured. Set it via Pulumi config (grafana:url) or GRAFANA_URL env var.',
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already doing this validation inside of Grafana component. No need for duplication; just pass the Grafana URL as a parameter.

Comment thread src/components/grafana/plugin-ready.ts Outdated
);
}

const url = `${grafanaUrl.replace(/\/$/, '')}/api/plugins/${pluginSlug}/settings`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the URL,

const url = (new URL(`/api/plugins/${pluginSlug}/settings`, grafanaUrl)).href;

Comment thread src/components/grafana/plugin-ready.ts Outdated
Comment on lines +24 to +43
for (let attempt = 0; attempt < 60; attempt++) {
const { statusCode, body } = await request(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${grafanaToken}`,
'Content-Type': 'application/json',
},
});

if (statusCode === 200) {
const data = (await body.json()) as { id: string };
return { id: data.id, outs: {} };
}

if (statusCode !== 404) {
throw new Error('Unexpected error');
}

await new Promise(r => setTimeout(r, 5000));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the exponential backOff library with the cap for max wait time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Don't merge Do not merge this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants