Add Knowledge Graph gRPC client

What does this MR do and why?

Adds a gRPC client so Rails can talk to the GKG (Knowledge Graph) webserver. Uses the published gitlab-gkg-proto gem and passes JWT tokens with user authorization context on every request.

Stacked on !224386 (merged) (JWT auth)

Design decisions

  • Uses the gitlab-gkg-proto gem instead of committed proto files, same as how Gitaly does it (gem 'gitaly')
  • Stub caching behind a mutex with channel reuse, again following the Gitaly client
  • Passes x-gitlab-correlation-id as gRPC metadata
  • Hooks into LabKit tracing when it's enabled
  • 10s timeout on unary RPCs, 10s on streaming, converted to gRPC deadlines
  • execute_tool and execute_query use bidi streaming with a Queue-backed enumerator for the redaction exchange

RPCs

RPC Type What it does
ListTools Unary Returns available KG tools with their schemas
ExecuteTool Bidi streaming Runs a tool, handles redaction exchange mid-stream
ExecuteQuery Bidi streaming Runs a raw query, same redaction flow
GetOntology Unary Returns the full graph schema (nodes, edges, domains)
GetClusterHealth Unary Health check for the Orbit dashboard

How to set up and validate locally

git checkout gkg-grpc-client
bundle install
bundle exec rails console

1. Create a client

client = Analytics::KnowledgeGraph::GrpcClient.new
# or with a custom endpoint:
client = Analytics::KnowledgeGraph::GrpcClient.new(endpoint: 'localhost:50051')

2. Test unary RPCs (needs a running GKG stack)

user = User.first
client.get_cluster_health(user: user)
client.list_tools(user: user)
client.get_ontology(user: user)

3. Verify stub caching

stub_a = Analytics::KnowledgeGraph::GrpcClient.stub
stub_b = Analytics::KnowledgeGraph::GrpcClient.stub
stub_a.equal?(stub_b) # => true (same object)

References

Edited by Michael Angelo Rivera

Merge request reports

Loading
Loading