Expose field, type, and parameters in GLQL REST API entity

What does this MR do and why?

The GLQL compiler emits field, type, and parameters properties in the compile output, but the Grape entity (API::Entities::Glql::Field) silently drops them because it only exposes key, label, and name.

This MR adds these three attributes to the entity so API consumers can access:

  • field: the base field name, distinct from key for aliased parameterised fields (e.g. key: "p50", field: "durationQuantile")
  • type: field classification ("dimension" or "metric") for analytics mode fields, omitted for standard fields
  • parameters: resolved parameter metadata (e.g. { "granularity": "weekly" }), omitted when the field has no parameters

type and parameters use expose_nil: false so they are omitted from the response rather than serialised as null when not applicable.

How to set up and validate locally

  1. Run the entity spec:

    bundle exec rspec spec/lib/api/entities/glql/field_spec.rb
  2. Set up Clickhouse in your GDK

  3. Set up Siphon in your GDK

  4. Enable Clickhouse-based analytics: echo 'Gitlab::CurrentSettings.current_application_settings.update(use_clickhouse_for_analytics: true)' | rails c

  5. Seed Pipeline Analytics: FILTER=pipeline_metrics SEED_PIPELINE_METRICS=1 bundle exec rake db:seed_fu

  6. Verify the API response includes the new fields by compiling an analytics query:

    curl --request POST \
      --header "PRIVATE-TOKEN: <token>" \
      --header "Content-Type: application/json" \
      --data '{"glql_yaml": "mode: analytics\ndimensions: ref\nmetrics: durationQuantile(0.5) as \"p50\"\nquery: type = pipeline AND project = \"gitlab-org/gitlab-shell\""}' \
      --url "http://gdk.test:8080/api/v4/glql"

    The fields array should include "field": "durationQuantile", "type": "metric", and "parameters": {"quantile": "0.5"} for the p50 field.

References

Edited by Robert Hunt

Merge request reports

Loading
Loading