Files
openobserve/web
Shrinath RaoandClaude Opus 4.8 afd367bb78 fix: function test query ignores selected stream type (always queries logs) (#13163)
## Problem

Fixes #7228 (新建函数查询时数据流类型无效 — "Data stream type is invalid when creating
a new function query").

In the function editor's **Run query** test panel, selecting **Traces**
(or **Metrics**) as the stream type still queries **logs**. The
user-selected stream type is ignored.

## Root cause

`TestFunction.vue` → `getResults()` hardcoded `page_type: "logs"` when
calling `searchService.search()`:

```js
searchService.search({
  org_identifier: store.state.selectedOrganization.identifier,
  query,
  page_type: "logs",   // ignored the dropdown selection
})
```

`page_type` becomes the `type=` query param in `search.ts`
(`/api/{org}/_search?type=logs&...`), so the request always hit the logs
store regardless of the Stream Type dropdown.

## Fix

Pass the user-selected stream type instead — the same value the rest of
the component already uses for the stream list, field keywords, and
auto-suggest:

```diff
-  page_type: "logs",
+  page_type: selectedStream.value.type,
```

`selectedStream.value.type` is typed `"logs" | "metrics" | "traces"` and
is bound to the Stream Type `OSelect`.

## Blast radius (reviewed)

- **Only consumer of the hardcoded value:** `getResults()` (the "Run
query" button), which fetches sample events into the Events panel to
feed the VRL test. Line 636 was the only hardcoded `page_type`/`"logs"`
in the file — every other reference already uses
`selectedStream.value.type`.
- **Traces:** now correctly reaches the `page_type === "traces"` branch
in `search.ts`, which applies the nanosecond-timestamp response patch
(`patchNsFieldsInJson`) — previously never triggered from this panel.
- **Metrics:** SQL search against metrics streams via
`_search?type=metrics` is valid.
- **Not affected:** the toolbar "Test Function" button (runs the VRL
against the events JSON via the jstransform API — independent of stream
type), saving the function, and the multi-stream `_search_multi` branch
(unused here since `query.query.sql` is always a string).
- **Tests:** `TestFunction.spec.js` / `.spec.ts` mock
`searchService.search` and don't assert `page_type`, so no test changes
are required.

## How to verify

1. **Pipelines → Functions → Add Function** → expand the **Query**
section in the test panel.
2. Set **Stream Type → Traces**, pick a traces stream, enter a query,
click **Run query**.
3. Network tab: the request now goes to `POST
/api/{org}/_search?type=traces...` (was `type=logs`) and returns trace
data.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 03:46:13 +00:00
..
2025-12-04 13:58:09 +05:30
2026-05-28 11:00:49 +00:00
…
…
2024-04-03 12:49:25 +05:30

web

This template should help get you started developing with Vue 3 in Vite.

VSCode + Volar (and disable Vetur) + TypeScript Vue Plugin (Volar).

Type Support for .vue Imports in TS

TypeScript cannot handle type information for .vue imports by default, so we replace the tsc CLI with vue-tsc for type checking. In editors, we need TypeScript Vue Plugin (Volar) to make the TypeScript language service aware of .vue types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a Take Over Mode that is more performant. You can enable it by the following steps:

  1. Disable the built-in TypeScript Extension
    1. Run Extensions: Show Built-in Extensions from VSCode's command palette
    2. Find TypeScript and JavaScript Language Features, right click and select Disable (Workspace)
  2. Reload the VSCode window by running Developer: Reload Window from the command palette.

Customize configuration

See Vite Configuration Reference.

Project Setup

npm install

Compile and Hot-Reload for Development

For stand-alone UI development environment, create .env file and which contains below environment variable

VITE_OPENOBSERVE_ENDPOINT=http://localhost:5080/
npm run dev

Type-Check, Compile and Minify for Production

npm run build

Run Unit Tests with Vitest

npm run test:unit

Run End-to-End Tests with Cypress

npm run test:e2e:dev

This runs the end-to-end tests against the Vite development server. It is much faster than the production build.

But it's still recommended to test the production build with test:e2e before deploying (e.g. in CI environments):

npm run build
npm run test:e2e

Lint with ESLint

npm run lint