Query like a pro: story about designing query input in Visum

Query like a pro: story about designing query input in Visum

Share: Share on LinkedIn Share on X (Twitter)

At the last VictoriaMetrics Virtual Meetup, we announced the start of alpha testing of our new project called Visum. Visum is our unified UI for VictoriaStack with support for dashboards, observability notebooks, AI tooling, and other exciting features.

We’ve been working on it for a while, and during that time I’ve accumulated several stories/reflections about the UX of Observability tools. Here’s one of the stories I’d like to share.

But before we start, I would like to say that we are planning to launch beta testing of Visum in VictoriaMetrics Cloud, so if in doubt, it’s time to join, get $200 in credits for free and request beta access.

What is the story about?

#

When I was working on Visum, our observability UI for VictoriaStack (VictoriaMetrics, VictoriaLogs and VictoriaTraces), I spent a surprising amount of time on what looked, at first glance, like one component: the query input - a box where you enter a query. At that first glance… it was just a text field.

Query input in visum

But in practice, once I started thinking seriously about use cases, this small part of the screen turned out to involve a substantial amount of code, research, and decisions about how people work with their data.

Along the way I kept coming back to the same questions. Surprisingly, the difficult questions were less about syntax and more about people:

  • How many users still write queries by hand every day?
  • How many of them prefer to build queries visually in query builders?
  • How many just need a good example or template they can adapt?
  • And how many would rather describe what they want and let AI write the query expression on their behalf?
  • And how do you make writing queries convenient for all of them at once?

This post is about those questions and the answers I arrived at. Some are opinions rather than facts, and I’d be glad to hear where you disagree.

Who writes queries how?

#

I don’t have a reliable percentage for any of these groups, and I don’t think they are fixed groups where people stay forever:

  • The same engineer can write metrics queries from memory but still be a beginner when it comes to logs or traces.
  • Someone who knows a query language well might want a template for a complex histogram query that comes up once a quarter.
  • Someone starting with a builder might switch to code to make one precise change.
  • The same person might write a familiar query by hand, use a template for an unfamiliar function, and ask AI for a starting point during the same investigation.

That became the central design problem: how do these ways of working fit together? I didn’t want four separate tools. I wanted one query input with several ways of getting to a query and easy movement between them: usable without knowing the VictoriaStack query languages, while leaving room for the person who already knows exactly what to type. That goal shaped one input with three modes: Manual, Visual and AI. In Explore, the query library is one click away, with your history, ready-made examples and patterns, together with the language docs.

Visum's MetricsQL query input in Visual mode: Manual, Visual and AI tabs, six chips from vm_http_requests_total to topk, and the book icon

The query input: Manual, Visual and AI tabs on the left, the query as a row of steps, and the book icon for the query library on the right.

If you…Start withWhat helps you
write queries every dayManualautocomplete (including autocomplete from your own data), inline docs, history
know what you want, but not the syntaxVisualseparate steps with small forms instead of syntax
want a proven starting pointExamplespatterns with placeholders you fill in
prefer natural languageAIgenerated query you review and run

Every path ends in the same place: a query you can read and edit. And it’s the same input, working the same way, whether you’re working with metrics, logs, or traces. Query input opens in the visual builder mode the first time, and then Visum remembers the mode you chose. But the query itself never disappears: the code is always one click away.

Query builders: where is the balance?

#

Before writing the visual builder, I researched and reviewed a lot of query builders in different products, across a broad range of approaches:

  • At one end are very simple ones that only let you build basic things like sum(rate(metric)). They are easy to start with, until the next question needs something beyond its controls - they don’t cover many things from the real world.
  • At the other end are monsters that try to repeat the entire syntax of the language and support any construction at all. The builder can become a second programming language, expressed through menus and nested forms. They can express anything, but you have to learn the builder almost as well as the language syntax.
PromLens query builder

An example of a query builder (PromLens) that tries to support the entire syntax of the language

I wanted to find a balance: a builder should cover all the popular patterns and help people understand the choices involved while keeping the result readable and the next step understandable. The rest is better left to code - supporting every possible expression was never a useful goal by itself. I didn’t want completeness of syntax coverage to become the main measure of success.

For metrics, the popular patterns fit one pipeline: pick a metric, narrow it with label filters, apply a rollup over a time window, aggregate by labels, transform the result, and keep the top or bottom series. In my experience, that shape covers most everyday queries. You can add the steps in any order, and the builder puts each one where it belongs. A rollup form, for instance, can explain the function and ask for its range, rather than expecting someone to remember where [5m] belongs.

For example, this expression calculates a per-second request rate over a five-minute window, then combines the series by job:

sum(rate(vm_http_requests_total[5m])) by (job)

Someone familiar with the language can write it quickly. Someone new to it has several things to figure out: which metric to use, how to turn a counter into a rate, how to combine series, and how to retain a separate result for each job.

The builder can guide those decisions one at a time: select a metric, add a rate over a five-minute window, add an aggregation grouped by job.

In Visum, the result in the builder is presented as three compact, editable parts:

  • the metric,
  • rollup: rate[5m],
  • and aggregation: sum by job.
Animation: building sum(rate(vm_http_requests_total[5m])) by (job) in the Visum metrics builder by picking a metric, adding a rollup and an aggregation, then switching to Manual mode and back to Visual.

The builder introduces an operation through a focused form, while keeping the rest of the query visible.

Guidance matters just as much. A person who doesn’t know the language needs help choosing the next operation. Presenting a complete catalog of functions leaves them with much of the original problem. Categories such as filtering, aggregation, and ranking give them a more useful starting point.

The compact representation matters too. After editing, I want to read the query as a short sequence of meaningful parts. I don’t want a straightforward expression to expand into two screens of permanently open controls. The forms should be available when needed, then get out of the way. The query should leave space for the results and the rest of the investigation.

What if you need something beyond this pipeline?

So, binary (and more complex) expressions get their own tool, the formula. Inside one query, you build sub-queries A and B, each a row of steps, and combine them with something like A / B * 100. Visum turns it all back into one query expression.

Metrics formula popover

Metrics formula form

What a good query builder has to do

#

Beyond scope, three things seemed extremely important to me.

Switching between code and the builder has to be easy and work both ways.

A builder is much less useful if using code feels like a one-way trip. A builder you can’t leave without losing your work is a trap. A code editor you can’t come back from turns the builder into a one-time wizard. In Visum, switching back to Visual mode takes one click, reconstructs the parts the builder understands, but never rewrites your query: the query text is the source of truth, and the builder is a view of it.

Animation showing the same metrics query in Visual mode, Manual mode and Visual mode again.

The expression connects the two views. Switching modes preserves the work.

You can use the builder for the parts of your work it handles well and still have the full language available. There is a limit: some expressions don’t fit the structured forms. In the metrics builder they stay as a Manual expression, in the logs query builder as editable Custom stages. Either way, the query stays intact, without silently being rewritten into something simpler.

The result has to be easy to read.

As I said earlier, I didn’t want a builder that takes two screens of permanently open controls to show one query. In Visum, each chip sums up its step in a few words, like rate[5m], sum by job or topk 5, and the chips read in the order the query is evaluated. Take a typical latency query:

histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))

In code, you start from the outermost function and work your way in. In the builder, you read it from left to right: http_request_duration_seconds_bucket › rate[5m] › sum by le › histogram_quantile(0.95, …), where … marks the spot the previous step flows into.

The histogram_quantile query as chips read left to right, above the same query as MetricsQL code

The same query as builder steps (top) and as code (bottom).

It has to guide, not drop a catalog.

MetricsQL has hundreds of functions. Dropping all of them on someone who doesn’t know the language just makes them search through the list. So the builder goes level by level. The Add menu offers six kinds of steps, each with a one-line description.

The Add menu of the metrics builder: Filter, Rollup, Aggregation, Transform, Rank and Formula, each with a one-line description

Level one: six kinds of steps, each with a one-line description.

Pick Rollup, Aggregation, Transform, or Rank, and you get a searchable list of only that kind of function, each with a short description. Pick a function, and you get its documentation, its signature and a field for each argument, named after the signature. Transform steps also preview the expression they produce.

Transform form for round: documentation, the signature, a nearest field set to 0.01 and a preview of the full expression

A transform step: documentation, signature, a named argument field and a live preview.

All of it comes from the official MetricsQL reference, most functions are available in steps. The rest work in a formula or in code. The pickers use your own data: when metadata is available, you can tell a counter from a gauge before you wrap it in rate. In logs, every stage previews the query it will produce.

Different signals, familiar interactions

#

This becomes more interesting (and complicated) when there are several signals. Visum works with metrics (from VictoriaMetrics), logs/events (from VictoriaLogs) and traces/spans (from VictoriaTraces). Those signals have different shapes and natures, and you query them in different ways.

A metric query often works with application state over time: their questions often involve functions with rollup on lookbehind windows and aggregation across series. Log queries often start with matching records, then pass them through a sequence of operations like filtering and transformation stages and limits.

Does this really mean that I have to implement completely different query builders? Completely unrelated builders would introduce a different cost: users would have to learn a new interaction model repeatedly whenever they changed signals.

Using the same query language for all types of signals seems like a good idea at first glance, but it’s highly likely that this language (like SQL, for example) will be equally bad for all types of signals at the same time (or at least for one of them).

What’s left? I saw three ways to deal with that:

ApproachWhat you learnThe catch
One universal language for every signalOne syntaxLikely equally bad for all signals at once
A completely different builder per signalA new tool per signalEach one has to be learned separately
A language per signal, with builders that work alikeA language per signal, one set of habitsNot as easy as it seems

I went with the third: keep the languages suited to the underlying systems (MetricsQL for metrics, LogsQL for logs and traces) and make their interfaces feel related and the interactions familiar. It’s less obvious, but it seems to me the more correct way.

The builders reflect those different structures, while sharing ideas: compact parts, click to edit, contextual suggestions, focused forms, familiar editing and mode controls, and access to the underlying code.

The Visum LogsQL builder showing a pipeline and an open operation form.

A logs pipeline has a different structure from a metrics expression. The editing interaction can still feel familiar.

The metrics pipeline is fixed, so the order you add steps in doesn’t matter.

For logs, you set the order yourself, because each stage works on the output of the one before. The builder reads from left to right. The stages are Filter, Modify, Aggregate, Sort, Limit, Combine, and Custom. The order is part of the meaning, so the interface should make that sequence easy to follow. Combine joins or appends another query, much like the metrics formula, and Custom holds any LogsQL the forms don’t cover.

The habits, though, are the same. Every input starts with the same mode tabs. A query is a row of chips with an Add button at the end. A click on a chip opens a small form with Apply and Cancel, and function and operator pickers describe every option. In Explore, the same book icon opens the same kind of library. Learn one builder, and the other feels familiar.

The aim is to let familiarity carry across signals, even when the queries themselves differ.

Natural language, without the black box

#

Natural language provides another starting point, and it brings its own design questions.

In AI mode you just describe what you want, for example “how many rows per second does vminsert ingest, per instance”, and press Enter. It can be very useful when you know the question but cannot yet express it in the query language.

There I noticed two possible problems, and I wanted to avoid both.

The first is doing anything without a preview and confirmation. You write a sentence, the AI turns it into a query under the hood and runs it right away. Perhaps this is convenient for someone, but to me it’s an antipattern. At the very least, you should see the query in a form you can read, as code or in the builder, and click Run yourself.

In Visum, AI mode produces a query and switches back to Manual, where you can inspect it, change it, open it in the builder, and run it yourself. That review is useful even when the answer is correct: seeing how a question maps to an expression helps you learn the language.

AI mode running list_metric_names, then the generated vm_rows_inserted_total query waiting in the code editor next to the Execute button

The assistant looks up metric names, then leaves the generated query in the code editor. The results below are still from the previous query.

The assistant is told to check before it writes. It has read-only tools to look up real metric names and labels, or log fields and streams. It reads the relevant section of the query language reference, may use exploration tools, and the input shows which tool it’s calling. For the vminsert question, one run against our demo data returned:

sum(rate(vm_rows_inserted_total{job=~"vminsert.*"}[5m])) by (job, instance)

The second problem is the black box: an assistant that you cannot give rules to, such as “always use this pattern” or “never use this metric or this function”, and that you cannot teach what your team knows.

Teams have conventions that AI Assistant cannot know: preferred metrics, labels with particular meanings, functions they avoid. So in Visum, every AI feature runs on a workflow your organization can open and change. An administrator can edit the instructions, choose the available tools, attach reference documents and adjust model settings, or create alternative workflows. If your team always uses a five-minute window for request rates, or a metric is deprecated, you write that into the workflow once instead of repeating it in every request.

The Customize MetricsQL assistant drawer with the Attached docs list and the Tools list, 10 tools selected

Customizing the built-in MetricsQL assistant: attached docs and the tools it gets are editable, like its system prompt.

Manual query editor

#

The builder should make common work easier and give people a way into unfamiliar syntax. Experienced users should still be able to write the expression they need.

I won’t dwell on what everyone expects from a query editor, but the details matter:

  • All MetricsQL and LogsQL expressions in Visum support syntax highlighting,
  • Autocomplete knows where the cursor is. Inside a selector it suggests label names, then values scoped to the metric and the matchers you’ve already typed.
  • There is documentation available next to each function.
MetricsQL autocomplete: two recent queries under History, then rate and other functions and metrics, with the documentation for rate

Autocomplete in the metrics editor: recent queries first, then functions and metrics, with the docs for rate.

Beyond the basics, two things are very important to me. The first one is query history. Most queries we write are variations of queries we wrote yesterday. In Explore, Visum keeps recent queries you ran for each signal. You can search them and rerun one in a click, and recent ones also appear at the top of autocomplete.

The query library's searchable History tab.

The searchable History tab of the query library.

The second is examples one click away. In Explore, the book icon at the end of the input opens the query library. For metrics and logs, its Docs tab holds the language reference, bundled with Visum and searchable by section. The Examples tab gets its own section below.

Good examples are one of the fastest ways to learn a query language, but how do you use them in the editor? Usually you copy one, figure out what to adjust for your setup, and walk through the query, editing it, trying not to miss anything or break a bracket. That doesn’t sound very convenient.

So every example in Visum’s library comes in two forms: a pattern with named placeholders, and a filled-in version that runs as is. Each of them has a short description and a link to the docs.

Metrics query library, Examples tab: cards with a pattern, an example, Use pattern, Run example and Documentation

The metrics query library: each example has a pattern, a runnable version, and a link to the docs.

  • Run example runs the ready-made version.
  • Use pattern puts the pattern into the code editor and turns each placeholder into a field:
sum(rate(<counter_metric>[<range>])) by (<label>)

The first field is selected, so you just start typing. Tab and Shift+Tab move between placeholders, and autocomplete keeps working inside each one.

For example, typing in <counter_metric> here suggests real metric names, and when metadata is available, the panel next to them tells you which ones are counters:

A pattern being filled in, with autocomplete suggesting alertmanager_alerts_received_total, type counter, inside the first placeholder

Filling in a pattern: autocomplete inside the first placeholder, the others still waiting their turn.

That’s why I like query patterns. The library can show a concrete example and offer a reusable version with placeholders such as <metric>, <label> or <field>. Choosing Use pattern puts that version into Manual mode. The user fills in the relevant pieces and presses Tab to move to the next placeholder, with suggestions available as they edit.

Animation showing a query pattern inserted into the editor and its placeholders filled using Tab navigation.

Inserting a pattern and moving between its placeholders with Tab.

An unfinished pattern also shouldn’t quietly become a failed query. Before running, Visum checks the query for leftover placeholders such as <metric>. If it finds one, nothing is sent or saved to history: a Fill in the example first warning appears, and you’re back on the first unfilled placeholder.

The Fill in the example first warning under a query that still contains placeholders

Running a pattern with placeholders still in it: Visum asks you to fill them in first.

This is a small interaction, but it makes the example library feel like part of the editor.

From beginner to pro

#

After spending so much time on this component, I don’t think there is one best way to write a query. There are different questions, different levels of familiarity, and different moments in the same person’s work.

I don’t expect everyone to use every feature or to follow the same path, but I do want the paths to connect. Someone new to VictoriaStack can start with a builder, an example, or a plain-language request, then inspect and adapt the expression as their understanding grows. Someone writing queries every day gets a capable editor and quick access to work they’ve already done.

That’s what I wanted: a low entry threshold, and an input that gradually guides you from beginner to pro.

Leave a comment below or Contact Us if you have any questions!
comments powered by Disqus

You might also like: