feat(duo_workflows): add model as a filterable query field

What does this MR do and why?

model has been usable as a dimension and a sort field on the DuoWorkflows source since !511 (merged), but not as a filter. A query could break credits down by model without being able to scope to one, and model = "claude-sonnet-4-5" failed with:

Error: `model` is not a recognized field for Duo workflows. Valid fields: created, flowType, status, user, flowTypesUsed, activeDays.

!511 (merged) left filtering out deliberately, because the engine had no modelUsed filter argument to compile to. That argument now exists, so this adds Model to the source's filter fields:

  • typed with negatable_string_list_field_type(), i.e. =, in, != and not in, exactly like flowType
  • resolved through FilterKey::Negatable(ENGINE_MODEL) so it emits the engine's modelUsed spelling rather than the field name, or modelUsedNot for != and not in
  • valued through string_list_filter_value, so a bare string is wrapped into a one-element list

The type is left open rather than closed as an enum like status, because the engine stores whatever model name a session reported.

src/schema/schema.json is regenerated, adding one filter_fields entry.

Excluding unattributed credits

A session the engine could not attribute to a model is stored as an empty string. model != "" excludes that bucket, which is how the DAP Impact "Credits by model" tile narrows to model-attributed credits. It compiles to modelUsedNot: [""], and test_the_empty_string_is_excludable covers it alongside flowType.

Example Usage

Build prerequisite:

cd glql_rb
bundle install
bundle exec rake compile

Credits by flow type for a single model

mode: analytics
query: type = DuoWorkflow and model = "claude-sonnet-4-5" and created >= "2026-08-25" and created <= "2026-09-24"
dimensions: flowType
metrics: creditsUsedSum
sort: creditsUsedSum desc
Test via ruby extension

Note: this runs against gitlab.com now that gitlab!257782 (merged) is deployed: modelUsed and modelUsedNot are both in the live schema.

cd glql_rb # after the build prerequisite above

bundle exec ruby -Ilib - <<'RUBY'
require "gitlab_query_language"
require "json"
require "net/http"

query   = 'type = DuoWorkflow and model = "claude-sonnet-4-5" and created >= "2026-08-25" and created <= "2026-09-24"'
context = { mode: "analytics", dimensions: "flowType", metrics: "creditsUsedSum", sort: "creditsUsedSum desc", group: "gitlab-org" }

# 1. Compile GLQL -> GraphQL (also returns the typed `fields` the transform needs).
compiled = Glql.compile(query, context)
puts "== Generated GraphQL =="
puts compiled["output"]

# 2. Execute against GitLab. Analytics data is private, so a token is required.
uri  = URI("https://gitlab.com/api/graphql")
http = Net::HTTP.new(uri.host, uri.port); http.use_ssl = true
req  = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
req["PRIVATE-TOKEN"] = ENV.fetch("GITLAB_TOKEN")
req.body = { query: compiled["output"], variables: { limit: 3 } }.to_json
response = JSON.parse(http.request(req).body)

# 3. Transform the response back into flat rows, reusing the compiled fields.
result = Glql.transform(response["data"], { fields: compiled["fields"], source: compiled["source"], mode: compiled["mode"] })
puts "== Rows =="
puts JSON.pretty_generate(result["data"])
RUBY

Generated GraphQL, taken verbatim from this MR's DUMP_GRAPHQL=1 output (project scope, model as the dimension):

query GLQL($before: String, $after: String, $limit: Int) {
  project(fullPath: "gitlab-org/gitlab") {
    analytics {
      duoWorkflows(modelUsed: ["claude-sonnet-4-5"]) {
        aggregated(before: $before, after: $after, first: $limit) {
          count
          pageInfo {
            startCursor
            endCursor
            hasNextPage
            hasPreviousPage
          }
          nodes {
            dimensions {
              model {
                name
                provider
                hosting
                isDefault
              }
            }
            creditsUsed {
              creditsUsedSum: sum
            }
          }
        }
      }
    }
  }
}

How to set up and validate locally

  1. Run the test suite, which covers the new filter in tests/duo_workflows_tests.rs:

    cargo test
  2. Confirm the schema document is what the generator produces, as CI does:

    cargo run --bin generate-schema && npx prettier --write src/schema/schema.json
    git diff --exit-code src/schema/schema.json
  3. Confirm the compiled query carries the engine's argument spelling:

    DUMP_GRAPHQL=1 cargo test
    grep -rh 'modelUsed:' tmp/graphql/ | sort -u

References

The graphql-validate job checks generated queries against gitlab-org/gitlab's master schema, which has had modelUsed and modelUsedNot since 257782 merged.

Related to #236 (closed)

Edited by Jatin Parihar

Merge request reports

Loading
Loading