diff --git a/greptimedb/package.json b/greptimedb/package.json index d7ec211b8..071c2fd7f 100644 --- a/greptimedb/package.json +++ b/greptimedb/package.json @@ -22,7 +22,6 @@ "@perses-dev/components": "^0.54.0-beta.1", "@perses-dev/core": "^0.53.0", "@perses-dev/dashboards": "^0.54.0-beta.1", - "@perses-dev/explore": "^0.54.0-beta.1", "@perses-dev/plugin-system": "^0.54.0-beta.1", "@tanstack/react-query": "^4.39.1", "date-fns": "^4.1.0", diff --git a/greptimedb/rsbuild.config.ts b/greptimedb/rsbuild.config.ts index 5618a0cc1..6eb97d4ab 100644 --- a/greptimedb/rsbuild.config.ts +++ b/greptimedb/rsbuild.config.ts @@ -36,7 +36,6 @@ export default createConfigForPlugin({ lodash: { singleton: true }, '@perses-dev/components': { singleton: true }, '@perses-dev/plugin-system': { singleton: true }, - '@perses-dev/explore': { singleton: true }, '@perses-dev/dashboards': { singleton: true }, '@emotion/react': { requiredVersion: '^11.11.3', singleton: true }, '@emotion/styled': { singleton: true }, diff --git a/greptimedb/src/explore/GreptimeDBTraceExplorer.tsx b/greptimedb/src/explore/GreptimeDBTraceExplorer.tsx deleted file mode 100644 index 0b032ccf2..000000000 --- a/greptimedb/src/explore/GreptimeDBTraceExplorer.tsx +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright The Perses Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import { Box, Stack } from '@mui/material'; -import { ErrorAlert, ErrorBoundary, LoadingOverlay, NoDataOverlay } from '@perses-dev/components'; -import { QueryDefinition } from '@perses-dev/core'; -import { Panel } from '@perses-dev/dashboards'; -import { useExplorerManagerContext } from '@perses-dev/explore'; -import { DataQueriesProvider, MultiQueryEditor, useDataQueries } from '@perses-dev/plugin-system'; -import { ReactElement, useEffect, useState } from 'react'; -import { GreptimeDBTraceQuerySpec } from '../queries/greptimedb-trace-query/greptimedb-trace-query-types'; -import { isLikelyTraceDetailSQL } from '../queries/greptimedb-trace-query/trace-query-sql'; -import { linkToSpan, linkToTrace, resolveTraceLinkTemplate } from './links'; - -interface TraceExplorerQueryParams { - queries?: QueryDefinition[]; - spanId?: string; -} - -interface SearchResultsPanelProps { - queries: QueryDefinition[]; -} - -function SearchResultsPanel({ queries }: SearchResultsPanelProps): ReactElement { - const { isFetching, isLoading, queryResults } = useDataQueries('TraceQuery'); - - if (queryResults.length === 0) { - return <>; - } - if (isLoading || isFetching) { - return ; - } - - const queryError = queryResults.find((d) => d.error); - if (queryError) { - throw queryError.error; - } - - const tracesFound = queryResults.some((traceData) => (traceData.data?.searchResult ?? []).length > 0); - if (!tracesFound) { - return ; - } - - const firstQuery = (queries[0]?.spec.plugin.spec as GreptimeDBTraceQuerySpec | undefined)?.query ?? ''; - const resolvedTraceLink = resolveTraceLinkTemplate(linkToTrace, firstQuery); - - return ( - - ); -} - -interface TracingGanttChartPanelProps { - queries: QueryDefinition[]; - selectedSpanId?: string; -} - -function TracingGanttChartPanel(props: TracingGanttChartPanelProps): ReactElement { - const { queries, selectedSpanId } = props; - const firstQuery = (queries[0]?.spec.plugin.spec as GreptimeDBTraceQuerySpec | undefined)?.query; - const resolvedTraceLink = resolveTraceLinkTemplate(linkToTrace, firstQuery ?? ''); - const resolvedSpanLink = resolveTraceLinkTemplate(linkToSpan, firstQuery ?? ''); - - return ( - - ); -} - -export function GreptimeDBTraceExplorer(): ReactElement { - const { data, setData } = useExplorerManagerContext(); - const { queries = [], spanId: selectedSpanId } = data; - - const [queryDefinitions, setQueryDefinitions] = useState(queries); - useEffect(() => { - setQueryDefinitions(queries); - }, [queries]); - - const definitions = queries.length - ? queries.map((query: QueryDefinition) => { - return { - kind: query.spec.plugin.kind, - spec: query.spec.plugin.spec, - }; - }) - : []; - - const firstQuery = (queries[0]?.spec.plugin.spec as GreptimeDBTraceQuerySpec | undefined)?.query ?? ''; - const isSingleTrace = isLikelyTraceDetailSQL(firstQuery); - - return ( - - setQueryDefinitions(state)} - queries={queryDefinitions} - onQueryRun={() => setData({ ...data, queries: queryDefinitions })} - /> - - - - - {isSingleTrace ? ( - - ) : ( - - )} - - - - - ); -} diff --git a/greptimedb/src/explore/index.ts b/greptimedb/src/explore/index.ts deleted file mode 100644 index 0660b06d3..000000000 --- a/greptimedb/src/explore/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright The Perses Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -export * from './GreptimeDBTraceExplorer'; -export * from './links'; diff --git a/greptimedb/src/explore/links.ts b/greptimedb/src/explore/links.ts deleted file mode 100644 index 293ca946c..000000000 --- a/greptimedb/src/explore/links.ts +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright The Perses Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -const traceQuerySQL = "SELECT * FROM TRACETABLE WHERE trace_id = 'TRACEID' ORDER BY timestamp ASC"; - -const linkToTraceParams = new URLSearchParams({ - explorer: 'GreptimeDB-GreptimeDBTraceExplorer', - data: JSON.stringify({ - queries: [ - { - kind: 'TraceQuery', - spec: { - plugin: { - kind: 'GreptimeDBTraceQuery', - spec: { - query: traceQuerySQL, - datasource: { - kind: 'GreptimeDBDatasource', - name: 'DATASOURCENAME', - }, - }, - }, - }, - }, - ], - }), -}); - -const linkToSpanParams = new URLSearchParams({ - explorer: 'GreptimeDB-GreptimeDBTraceExplorer', - data: JSON.stringify({ - queries: [ - { - kind: 'TraceQuery', - spec: { - plugin: { - kind: 'GreptimeDBTraceQuery', - spec: { - query: traceQuerySQL, - datasource: { - kind: 'GreptimeDBDatasource', - name: 'DATASOURCENAME', - }, - }, - }, - }, - }, - ], - spanId: 'SPANID', - }), -}); - -// add ${...} syntax after URL encoding so placeholder markers remain valid template variables. -export const linkToTrace = `/explore?${linkToTraceParams}` - .replace('DATASOURCENAME', '${datasourceName}') - .replace('TRACETABLE', '${trace_table}') - .replace('TRACEID', '${traceId}'); - -export const linkToSpan = `/explore?${linkToSpanParams}` - .replace('DATASOURCENAME', '${datasourceName}') - .replace('TRACETABLE', '${trace_table}') - .replace('TRACEID', '${traceId}') - .replace('SPANID', '${spanId}'); - -export function extractTraceTableFromSQL(query: string): string | undefined { - // Handles common forms: - // FROM schema.table - // FROM "schema"."table" - // FROM `schema`.`table` - const match = query.match( - /\bfrom\s+((?:[`"'][^`"']+[`"']|\[[^\]]+\]|[a-zA-Z_][\w$]*)(?:\s*\.\s*(?:[`"'][^`"']+[`"']|\[[^\]]+\]|[a-zA-Z_][\w$]*))?)/i - ); - return match?.[1]?.replace(/\s+/g, ''); -} - -export function resolveTraceLinkTemplate(template: string, query: string): string { - const table = extractTraceTableFromSQL(query); - if (!table) return template; - return template.replaceAll('${trace_table}', table); -} - -export function buildGreptimeTraceLinkFromQuery(query: string): string { - return resolveTraceLinkTemplate(linkToTrace, query); -} diff --git a/package-lock.json b/package-lock.json index ca1f4fa4d..36eaf888e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -202,7 +202,7 @@ }, "greptimedb": { "name": "@perses-dev/greptimedb-plugin", - "version": "0.1.0-beta.0", + "version": "0.1.0-beta.1", "peerDependencies": { "@emotion/react": "^11.7.1", "@emotion/styled": "^11.6.0", @@ -210,7 +210,6 @@ "@perses-dev/components": "^0.54.0-beta.1", "@perses-dev/core": "^0.53.0", "@perses-dev/dashboards": "^0.54.0-beta.1", - "@perses-dev/explore": "^0.54.0-beta.1", "@perses-dev/plugin-system": "^0.54.0-beta.1", "@tanstack/react-query": "^4.39.1", "date-fns": "^4.1.0",