From b2f5eb1d8708128fcac17d8755c57697773c56a2 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:51:26 +0200 Subject: [PATCH] [v11.0.x] LLMApp: Skip 404 requests to know if the plugin exists (#85269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LLMApp: Skip 404 requests to know if the plugin exists (#85226) --------- Co-authored-by: Ivan Ortega (cherry picked from commit 61e67423ff21185a75f69cfbe5a423f816184fac) Co-authored-by: Torkel Ödegaard --- .../features/dashboard/components/GenAI/utils.test.ts | 10 ++++++++++ .../app/features/dashboard/components/GenAI/utils.ts | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/public/app/features/dashboard/components/GenAI/utils.test.ts b/public/app/features/dashboard/components/GenAI/utils.test.ts index 48d6dfafc08..95ffa9a4e9b 100644 --- a/public/app/features/dashboard/components/GenAI/utils.test.ts +++ b/public/app/features/dashboard/components/GenAI/utils.test.ts @@ -16,6 +16,16 @@ jest.mock('@grafana/experimental', () => ({ }, })); +jest.mock('@grafana/runtime', () => ({ + ...jest.requireActual('@grafana/runtime'), + config: { + ...jest.requireActual('@grafana/runtime').config, + apps: { + 'grafana-llm-app': true, + }, + }, +})); + describe('getDashboardChanges', () => { it('should correctly split user changes and migration changes', () => { // Mock data for testing diff --git a/public/app/features/dashboard/components/GenAI/utils.ts b/public/app/features/dashboard/components/GenAI/utils.ts index d195d289a0b..a0caf3065b4 100644 --- a/public/app/features/dashboard/components/GenAI/utils.ts +++ b/public/app/features/dashboard/components/GenAI/utils.ts @@ -1,6 +1,7 @@ import { pick } from 'lodash'; import { llms } from '@grafana/experimental'; +import { config } from '@grafana/runtime'; import { Panel } from '@grafana/schema'; import { DashboardModel, PanelModel } from '../../state'; @@ -63,6 +64,10 @@ export function getDashboardChanges(dashboard: DashboardModel): { * @returns true if the LLM plugin is enabled. */ export async function isLLMPluginEnabled() { + if (!config.apps['grafana-llm-app']) { + return false; + } + // Check if the LLM plugin is enabled. // If not, we won't be able to make requests, so return early. return llms.openai.health().then((response) => response.ok);