Skip to content

Conversation

archef2000
Copy link

Add support for all operations of LogsQL in the Grafana Query Builder.
@Loori-R

#48

@Loori-R Loori-R requested review from Loori-R and arturminchukov July 4, 2025 16:46
Copy link
Contributor

@Loori-R Loori-R left a comment

Choose a reason for hiding this comment

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

Tested on Grafana 11.3.1.

An error occurs when adding filters:

  1. Open Explorer
  2. Go to OperationsFiltersWords
    This issue happens not only with Words, but also with other filters.

image

@archef2000
Copy link
Author

I am currently on 12.0.2 and everything is working will test version 11

@archef2000
Copy link
Author

The problem exists up to including v 11.4.6 and is fixed in 11.5.0.
The source problem is that the custom Field Editors get undefined as props

@Loori-R
Copy link
Contributor

Loori-R commented Jul 8, 2025

It looks like the issue is with the Combobox component - it doesn't work correctly with older versions of Grafana.
The Select component (which was its alternative) is now considered deprecated.

I think we should consider raising the minimum supported Grafana version.
What do you think, @dmitryk-dk, @hagen1778?

@Loori-R
Copy link
Contributor

Loori-R commented Jul 8, 2025

@archef2000, Could you please take a look at the tests and fix them?
Here’s the link to the failing workflow:
https://github.com/VictoriaMetrics/victorialogs-datasource/actions/runs/16075336610/job/45477811316?pr=329

@dk
Copy link

dk commented Jul 8, 2025

It looks like the issue is with the Combobox component - it doesn't work correctly with older versions of Grafana.
The Select component (which was its alternative) is now considered deprecated.

I think we should consider raising the minimum supported Grafana version.
What do you think, @dk, @roman?

In my experience query builders are fairly hard to use manually, - click click click hundred times, - I prefer plain old text for that. But what do I know, I am probably a wrong dk :)

@Loori-R
Copy link
Contributor

Loori-R commented Jul 8, 2025

In my experience query builders are fairly hard to use manually, - click click click hundred times, - I prefer plain old text for that. But what do I know, I am probably a wrong dk :)

Oops, looks like I tagged the wrong person 😅
Thanks a lot for sharing your thoughts - and sorry for the ping!

@dmitryk-dk
Copy link
Contributor

dmitryk-dk commented Jul 8, 2025

It looks like the issue is with the Combobox component - it doesn't work correctly with older versions of Grafana. The Select component (which was its alternative) is now considered deprecated.

I think we should consider raising the minimum supported Grafana version. What do you think, @dmitryk-dk, @hagen1778?

As for me, to up the version is ok, but we need to test everything properly

We could have another option to use, use the old Combobox, but I am not sure it would work in the newest versions.

11.3.1 as @Loori-R mentioned, is not an old version and many users are using versions 10-11.

@Loori-R
Copy link
Contributor

Loori-R commented Jul 8, 2025

  • There is no "old" Combobox - it was introduced as a new component and is currently marked as Alpha. View source

  • The Select component is marked as Deprecated. View source

As an option, we could use Select for now since it’s more stable, and plan to migrate to Combobox in the future.
Guide: Migrating from Select to Combobox

@dmitryk-dk
Copy link
Contributor

  • There is no "old" Combobox - it was introduced as a new component and is currently marked as Alpha. View source
  • The Select component is marked as Deprecated. View source

As an option, we could use Select for now since it’s more stable, and plan to migrate to Combobox in the future. Guide: Migrating from Select to Combobox

I think using Select instead of Combobox is a better idea. We do not need to change the supported version, and we do not need to use the Alpha component.

@archef2000
Copy link
Author

@Loori-R Can comfirm that with the Select component everything works.

@Loori-R
Copy link
Contributor

Loori-R commented Jul 8, 2025

@Loori-R Can comfirm that with the Select component everything works.

@archef2000 Would you mind replacing Combobox with Select?

@archef2000
Copy link
Author

Already on it

@Loori-R
Copy link
Contributor

Loori-R commented Jul 8, 2025

@archef2000
Copy link
Author

archef2000 commented Jul 8, 2025

I am not finished yet and will make a commit once all are changed and tested

@archef2000
Copy link
Author

This query should give me the value types of ClientPort right?
/select/logsql/field_values?query=_msg%3A*+%7C+uniq+by+ClientPort+%7C+block_stats+%7C+uniq+type&start=1751839200000&end=1752011999999&field=type

query: _msg:* | uniq by ClientPort | block_stats | uniq type
field: type

@Loori-R
Copy link
Contributor

Loori-R commented Jul 9, 2025

This query should give me the value types of ClientPort right? /select/logsql/field_values?query=_msg%3A*+%7C+uniq+by+ClientPort+%7C+block_stats+%7C+uniq+type&start=1751839200000&end=1752011999999&field=type

query: _msg:* | uniq by ClientPort | block_stats | uniq type field: type

Not sure, but it seems like uniq by ClientPort and uniq type might overlap.
@dmitryk-dk, could you please help clarify?

@Loori-R
Copy link
Contributor

Loori-R commented Jul 9, 2025

Seems like the query won’t return ClientPort types — it just gets unique type values from logs matching the full query as a text filter, because /field_values doesn’t run the pipeline logic.

@dmitryk-dk
Copy link
Contributor

dmitryk-dk commented Jul 9, 2025

_msg:* | uniq by ClientPort | block_stats | uniq type

Sorry guys missed you question

query _msg:* | uniq by ClientPort | block_stats will return

https://play-vmlogs.victoriametrics.com/select/vmui/#/?query=_msg%3A*+%7C+uniq+by+ClientPort+%7C+block_stats&g0.range_input=5m&g0.end_input=2025-07-09T11%3A56%3A01&g0.relative_time=last_5_minutes

field: ClientPorttype: constvalues_bytes: 0bloom_bytes: 0dict_items: 0dict_bytes: 0rows: 1part_path: inmemory

the next filter will get only type so the query like
_msg:* | uniq by ClientPort | block_stats | uniq type will return only type: const
https://play-vmlogs.victoriametrics.com/select/vmui/#/?query=_msg%3A*+%7C+uniq+by+ClientPort+%7C+block_stats+%7C+uniq+type&g0.range_input=5m&g0.end_input=2025-07-09T11%3A55%3A21&g0.relative_time=last_5_minutes

@archef2000
Copy link
Author

I was in the assumption that /field_values will return the values of the field that are available after the query. Just noticed it in the value_type operation, but then I will have to change the logic for all. Should I change the getFieldList function with an additional type?

@Loori-R
Copy link
Contributor

Loori-R commented Jul 9, 2025

I don't quite understand what you're trying to achieve.

For the expression:
_msg:* | uniq by ClientPort | block_stats | uniq type

/fields_values can only be used for _msg (I'm not sure how usable it is for _msg, but still).
To substitute values for uniq, you need to use /field_names

@archef2000
Copy link
Author

For the value_type operation I want to get the availabe value types of the field specified. The field_values is explained so that I get all field values of the specified field from the result of the query. The query gives me the correct result, but the endpoint seems to ignore the query.

@Loori-R
Copy link
Contributor

Loori-R commented Jul 9, 2025

Maybe we could just hardcode the supported value types (like const, dict, string, int64, float64, etc.) and allow users to enter a custom type if needed - that might be a simpler and more flexible solution.

@archef2000
Copy link
Author

@arturminchukov @Loori-R I am now finished with implementing all the operations and fixed all errors I could find.

@arturminchukov
Copy link
Contributor

arturminchukov commented Sep 29, 2025

  1. Should Stream operation work?
image

I cannot set stream via builder, but can do it via code input, and when I switched back to builder, I had predefined fields in stream operation. Is it expected behavior?

  1. Should we not to wrap with ` the stream field? Cause when I tried to use exact filter with stream field I got an error.
image

So it looks like now I don't have the opportunity to set the stream field.
Tested it on VL playground data.

@arturminchukov
Copy link
Contributor

One more strange behavior of filter for me provided in the video

Screen.Recording.2025-09-29.at.17.46.37.mov

@archef2000
Copy link
Author

@arturminchukov

  1. I get the same problem and traced it to the request select/logsql/stream_field_names just returning Hello from VM data source!
  2. The stream field does not work with the exact query. It fails because of the = not the "`"


export type SplitString = SplitStringValue | SplitStringBracket | SplitStringComment;

export const splitString = (str: string): SplitString[] => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add some JS Doc for this function with description what this function do? Cause I didn't guess the functionality just by the name. And maybe add some examples to description.

Comment on lines +28 to +40
if (prevFieldsName !== fieldName) { // change all defaultFields in the visQuery to the new fieldName
const oldVisQueryOps = visQuery.operations.map((v) => ({ ...v, disabled: false })); // render all operations even when disabled
const oldQueryModeller = createQueryModellerWithDefaultField(prevFieldsName, [VictoriaLogsQueryOperationCategory.Filters, VictoriaLogsQueryOperationCategory.Operators]);
const oldExpr = oldQueryModeller.renderQuery({ operations: oldVisQueryOps }); // old so that old defaultField doesn't get rendered
const newVisQuery = parseExprToVisualQuery(oldExpr, fieldName, queryModeller).query;
for (let i = 0; i < visQuery.operations.length; i++) {
const op = visQuery.operations[i];
if (op.disabled) {
newVisQuery.operations[i].disabled = op.disabled; // keep disabled operations disabled
}
}
onChange(index, { expr, visQuery: newVisQuery, fieldName } as unknown as string);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we should wrap it with useEffect() hook here

Copy link
Author

@archef2000 archef2000 Oct 1, 2025

Choose a reason for hiding this comment

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

The entire if block only runs if the field name of the logic operation gets changed. And the useEffect would need all the dependencies of that block.

Copy link
Contributor

@arturminchukov arturminchukov Sep 29, 2025

Choose a reason for hiding this comment

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

Should I just create one helper file or split it up even more?

I prefer group util functions into files by their functionality, because I think it improves readability.

@arturminchukov
Copy link
Contributor

I get the same problem and traced it to the request select/logsql/stream_field_names just returning Hello from VM data source!

Yeah, you're right! Right now VL datasource doesn't have such endpoints. Created the issue to add it. So could you wait until I add these endpoints and after it check if stream operation is working?

@archef2000
Copy link
Author

@arturminchukov It did exist and the filter did work.

@arturminchukov
Copy link
Contributor

Yeah, you're right! Right now VL datasource doesn't have such endpoints. Created the issue to add it. So could you wait until I add these endpoints and after it check if stream operation is working?

Looks like just need to add

mux.HandleFunc("/select/logsql/streams", ds.VLAPIQuery)
mux.HandleFunc("/select/logsql/stream_field_names", ds.VLAPIQuery)
mux.HandleFunc("/select/logsql/stream_field_values", ds.VLAPIQuery)

to here. Could you add this code to your pr?

@arturminchukov
Copy link
Contributor

arturminchukov commented Oct 1, 2025

Yeah, you're right! Right now VL datasource doesn't have such endpoints. Created the issue to add it. So could you wait until I add these endpoints and after it check if stream operation is working?

Looks like just need to add

mux.HandleFunc("/select/logsql/streams", ds.VLAPIQuery)
mux.HandleFunc("/select/logsql/stream_field_names", ds.VLAPIQuery)
mux.HandleFunc("/select/logsql/stream_field_values", ds.VLAPIQuery)

to here. Could you add this code to your pr?

UPD. @archef2000 , I merged pr with these changes. Could you just make rebase on updated main branch?

@arturminchukov
Copy link
Contributor

/build

Copy link

github-actions bot commented Oct 6, 2025

## 🚀 Build Started

**PR:** #329
**Source:** Fork (`archef2000/victorialogs-datasource`)
**Triggered by:** @arturminchukov

[⏳ View build progress](https://github.com/VictoriaMetrics/victorialogs-datasource/actions/runs/18283109893)

Copy link

github-actions bot commented Oct 6, 2025

✅ Preview Build Completed!

Version: v0.21.0-pr329-20251006-135624-55f7fbe
PR: #329
Source: Fork (archef2000/victorialogs-datasource)
Commit: 55f7fbe9b0b28cadd15274035f8d74d45d69ab24
Triggered by: @arturminchukov

📦 Build Artifacts

  • 📦 victoriametrics-logs-datasource-heads-main-0-g55f7fbe.zip (67.42 MB)

📥 Download

⬇️ Download from Actions Run

Artifact name: victoriametrics-logs-datasource-pr329-20251006-135624

🔐 Attestation

Build provenance attestation: View details

🧪 How to test this build
  1. Download the artifact from the Actions run link above
  2. Unzip the downloaded file
  3. Copy the plugin to your Grafana plugins directory:
    # Local Grafana
    unzip victoriametrics-logs-datasource-*.zip
    cp -r victoriametrics-logs-datasource /var/lib/grafana/plugins/
    
    # Docker Grafana
    docker cp victoriametrics-logs-datasource grafana:/var/lib/grafana/plugins/
  4. Restart Grafana:
    # Systemd
    sudo systemctl restart grafana-server
    
    # Docker
    docker restart grafana
  5. Verify the plugin in Grafana: ConfigurationPlugins
📋 Build Details

⚠️ Note: This is a preview build for testing only. Artifacts will be automatically deleted after 14 days.

@arturminchukov
Copy link
Contributor

/build

Copy link

github-actions bot commented Oct 6, 2025

## 🚀 Build Started

**PR:** #329
**Source:** Fork (`archef2000/victorialogs-datasource`)
**Triggered by:** @arturminchukov

[⏳ View build progress](https://github.com/VictoriaMetrics/victorialogs-datasource/actions/runs/18288559359)

Copy link

github-actions bot commented Oct 6, 2025

✅ Preview Build Completed!

Version: v0.21.0-pr329-20251006-171143-55f7fbe
PR: #329
Source: Fork (archef2000/victorialogs-datasource)
Commit: 55f7fbe9b0b28cadd15274035f8d74d45d69ab24
Triggered by: @arturminchukov

📦 Build Artifacts

  • 📦 victoriametrics-logs-datasource-heads-main-0-g55f7fbe.tar.gz (67.43 MB) 🔐 Signed ✓ SHA1

  • 📦 victoriametrics-logs-datasource-heads-main-0-g55f7fbe.zip (67.42 MB) 🔐 Signed ✓ SHA1

    📥 Download

    ⬇️ Download from Actions Run

    Artifact name: victoriametrics-logs-datasource-pr329-20251006-171143

    🔐 Attestation

    Build provenance attestation: View details

    🧪 How to test this build
    1. Download the artifact from the Actions run link above
    2. Unzip the downloaded file
    3. Copy the plugin to your Grafana plugins directory:
      # Local Grafana
      unzip victoriametrics-logs-datasource-*.zip
      cp -r victoriametrics-logs-datasource /var/lib/grafana/plugins/
      
      # Docker Grafana
      docker cp victoriametrics-logs-datasource grafana:/var/lib/grafana/plugins/
    4. Restart Grafana:
      # Systemd
      sudo systemctl restart grafana-server
      
      # Docker
      docker restart grafana
    5. Verify the plugin in Grafana: ConfigurationPlugins
    📋 Build Details

    ⚠️ Note: This is a preview build for testing only. Artifacts will be automatically deleted after 14 days.

@AndrewChubatiuk
Copy link
Contributor

AndrewChubatiuk commented Oct 7, 2025

for stats functions stats word is not prepended to result query, is it a bug?

@archef2000
Copy link
Author

The stats word is only prepended when the stats pipe is used.

@AndrewChubatiuk
Copy link
Contributor

can stats pipe be excluded on a stage, when no filters were selected yet?
i mean in general query builder should help to build query for those who is not familiar with logsql, but it confuses instead by allowing to select building blocks, which produce query that 100% fails

@archef2000
Copy link
Author

archef2000 commented Oct 8, 2025

No as the OperationList component provided by grafana/ui just asks the queryModeller for all operation categories without any context.

@szibis
Copy link

szibis commented Oct 16, 2025

Quick question how far we are with releasing this version of datasource officially?

@arturminchukov
Copy link
Contributor

Quick question how far we are with releasing this version of datasource officially?

@szibis Right now I don't have the exact ETA for releasing this feature. If I have any updates, I will let you know.

@AndrewChubatiuk
Copy link
Contributor

AndrewChubatiuk commented Oct 16, 2025

@szibis
in a current state query builder doesn't simplify procedure of building logsql expressions.
we've evaluated it internally and despite logsql syntax knowledge some people failed to build successful query during the first attempt to use it and only reverse conversion from raw expression to builder mode helped to understand why it failed. In my opinion builder should not allow to select options that produce absolutely invalid query. For example here value query.expr should impact a subset of categories that is passed to QueryModeller, which are allowed to choose on the next step (don't allow to select pipes, when filter is not set, don't allow setting filter, when pipes are set, etc)

@szibis Have you tried it already?

@archef2000
Copy link
Author

The QueryModeller is pretty heavy to create and it would need more than just this change as there are many places where a full QueryModeller is used. Then there is the problem that nearly all operations that are placed result in a query that fails. You first need to fill it with information so that also requires knowledge. It also means limiting advanced users that might create a query out of order. And what happens when I drag a pipe to the start? The error code of vl-select is very informative and should be very easy to understand. There is always a learning curve of a new tool and after the first failed query it should be clear what is allowed.

@AndrewChubatiuk
Copy link
Contributor

understand your concerns since it's a huge feature and it took significant time to implement, but i cannot agree with your statement regarding "learning curve". Builder is an intuitive tool, which should require no learning at all. by the way have you checked loki builder? it has required non-draggable filter, reusing this approach in current PR could improve UX a lot

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants