Skip to content

chore(graph): disable HTTP or eventhandlers by configuration - #3293

Merged
pbleser-oc merged 8 commits into
opencloud-eu:mainfrom
pbleser-oc:chore/#1312-graph-event-handler-split
Sep 1, 2026
Merged

pbleser-oc merged 8 commits into
opencloud-eu:mainfrom
pbleser-oc:chore/#1312-graph-event-handler-split

Conversation

@pbleser-oc

@pbleser-oc pbleser-oc commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Description

In the scope of the broader issue #1312, this PR deals with performing those changes for the graph service, namely to add the ability to disable the HTTP API or to disable the events API handler by configuration.

It also adds numerous metrics, and tests for the events processing.

Making Event Processing and HTTP Optional (#1312)

The previous implementation was combining the HTTP server service and the events consumption, which is why this PR refactors the composition of those services:

  • the event consumption has been moved into its own service
  • the identity.Backend is created beforehand, and then injected as a collaborator in both the HTTP service as well as the event consumer service

To encourage re-use in latter implementations and changes, it also introduces two top-level package changes:

  • internal/eventstest/events_test_helpers: contains a TestBus implementation to unit-test event consumers without the need to engage NATS
  • internal/metricstest/metrics_test_helpers: contains assertion functions to test Prometheus metrics

Run-down of changes for this aspect:

  • add the ability to disable the HTTP API handler (GRAPH_HTTP_DISABLED)
  • add the ability to disable the Events API handler (GRAPH_EVENTS_DISABLE_CONSUMER)
  • add metrics, especially for event processing
  • add metrics to the documentation
  • introduces a new top-level packages internal/eventstest and internal/metricstest with utilities for testing event consumers and Prometheus metrics, respectively

Includes metrics for whether the HTTP API handler is enabled, and another for whether the Event consumer is enabled, to allow counting the number of instances that do either, and potentially define alerts when one of those reaches 0 (or another low threshold).

image

Adding Metrics

Introducing gowrap as a build-time tool to generate interface delegate structs from templates:

  • added as a make generate target in services/graph,
  • added as a build-time dependency in .bingo/

LDAP Client Metrics

Introduces LDAP client abstraction interface to be able to wrap the go-ldap client API with metrics transparently (and possibly hooks and such in the future), in order to use delegation patterns to measure the time LDAP (client) operations take to finish, as well as to track their results (success, failure, not-found).

Has two implementations that are generated using gowrap:

  • a go-ldap adapter implementation that directly delegates
  • a time measuring and metrics collecting implementation that delegates to another LdapClient

The metrics collecting one is disabled by default, can be enabled with GRAPH_LDAP_METRICS_DISABLE=false

It collects the duration of outbound LDAP client operations into a histogram, as well as the number of concurrent outbound LDAP operations in a gauge (via an atomic int and a gauge func for best performance).

image image

HTTP Requests Metrics

Add an HTTP middleware that measures how long Graph HTTP API requests take, storing taken time into a histogram along with labels for

  • method,
  • path pattern (from the chi routes),
  • Graph API version prefix,
  • Graph API resource name,
  • and the resulting status code.

It also tracks the number of concurrent inbound Graph API HTTP requests using a gauge (also via an atomic int and a gauge func for best performance).

Disabled by default, can be enabled with GRAPH_HTTP_METRICS_DISABLE=false

image

LDAP Identity Backend Metrics

Add Backend and EducationBackend delegate implementations that measure execution time on the level of the higher API call operations there (CreateUser, DeleteUser, ..., CreateSchool, ...), generated using gowrap.

Disabled by default, can be enabled with GRAPH_IDENTITY_BACKEND_METRICS_DISABLE=false

image

LDAP Client API Change

Made an internal change to how the singular entry search operations work in the LDAP identity backend:

  • check whether searches for a singular entry returns more than one result, in which case a new error TooManyResults is returned, instead of leaving that undetected, blindly taking the first result, and potentially risking data inconsistencies

Logging Improvements

Improve the loggers in identity backends by adding attributes for their request targets (Reva gateway address or LDAP URI, respectively).

Also add a "backend" attribute for all Graph API logs (set to "ldap" or "cs3"), to help debug potential issues.

The LDAP identity backend logger also has two new attributes to help debugging with logs:

  • write (bool): whether write operations are enabled
  • refint (bool): whether refint is enabled or not

Also adds a dedicated counter for user password change operations.

Additional boy-scouting

  • add a constructor func for the CS3 backend
  • add a constructor func for the LDAP backend
  • in the LDAP identity backend, in searchLDAPEntryByFilter (used by all search/get public functions), errors that occur when performing LDAP SEARCH operations were blindly mapped to a ItemNotFound error, instead of being analyzed as it could be caused by a technical error
  • in the requireadmin middleware, add debug logging to explain why a request is denied
  • when an LDAP password change fails because the user entry was not found in LDAP, we now have a log message that tracks that

Related Issue

Motivation and Context

Details can be found in #1312

How Has This Been Tested?

HTTP API

Tested the HTTP API (when enabled) using:

xh --verify=no -a alan:demo --https :9200/graph/v1.0/me

and

xh --verify=no -a alan:demo --https :9200/graph/v1.0/users/b1f74ec4-dd7e-11ef-a543-03775734d0f7

and

xh --verify=no -a admin:admin --https :9200/graph/v1.0/users \$orderby=='displayName asc'

and

xh --verify=no -a admin:admin --https POST :9200/graph/v1.0/users accountEnabled:=true displayName="Jane Doe" onPremisesSamAccountName=jdoe mail="[email protected]" passwordProfile:='{"password": "secret12345"}'

Events API

Tested the event API (when enabled) using:

echo -n '{"metadata":{"eventtype":"events.UserSignedIn"},"payload":"'$(echo -n '{"Executant":{"opaque_id":"alan"}}'|base64)'"}'|nats pub main-queue

Tested combinations of enabling/disabling the events and HTTP APIs.
When both are disabled, the service refuses to start and exits early with an error message.

Metrics

Metrics were tested with a small k6 script included in this PR (namely services/graph/load_test.js) that performs various read-only operations with parallel VUs.

k6 run --vus 20 --duration 10m ./services/graph/load_test.js

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation added (in services/graph/README.md)

@codacy-production

codacy-production Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 critical · 4 high

Alerts:
⚠ 6 issues (≤ 0 issues of at least minor severity)

Results:
6 new issues

Category Results
ErrorProne 4 high
Security 2 critical

View in Codacy

🟢 Metrics 25 complexity · 322 duplication

Metric Results
Complexity 25
Duplication 322

View in Codacy

🟢 Coverage 21.40% diff coverage · -0.19% coverage variation

Metric Results
Coverage variation ✅ -0.19% coverage variation (-1.00%)
Diff coverage ✅ 21.40% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a249fa5) 85770 20078 23.41%
Head commit (e436532) 87549 (+1779) 20331 (+253) 23.22% (-0.19%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3293) 2210 473 21.40%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@pbleser-oc
pbleser-oc force-pushed the chore/#1312-graph-event-handler-split branch 3 times, most recently from d892695 to ec49989 Compare August 13, 2026 11:42
@pbleser-oc
pbleser-oc marked this pull request as draft August 14, 2026 13:22
@pbleser-oc
pbleser-oc force-pushed the chore/#1312-graph-event-handler-split branch 15 times, most recently from 89661f4 to 1db7cb2 Compare August 20, 2026 22:50
@pbleser-oc
pbleser-oc marked this pull request as ready for review August 21, 2026 06:38
Comment thread services/graph/pkg/service/v0/users.go Resolved
@pbleser-oc
pbleser-oc force-pushed the chore/#1312-graph-event-handler-split branch from c196096 to 6aee3e2 Compare August 24, 2026 14:54
Comment thread services/graph/pkg/service/v0/users.go Resolved
@pbleser-oc
pbleser-oc force-pushed the chore/#1312-graph-event-handler-split branch from 6aee3e2 to e279617 Compare August 24, 2026 15:03

@butonic butonic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This touches a lot of LDAP code and also introduces gowrap tooling, so I'd like to get @rhafer to take a look at this as well.

@butonic
butonic requested a review from rhafer August 24, 2026 15:05

@rhafer rhafer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've focussed the review of the LDAP related changes. Main issue is that we need to map the ldap.LDAPResultSizeLimitExceeded error instead of checking the number of returned entries, since we already set a sizelimit of 1 for all request that expect just a single result entry.

Other than that looks nice. I like the logging improvements, and improved error handling.

I must admin that am not really a fan of generating code from templates, but I also see the benefit here. I am already wondering if we could "re-implement" the LDAP reconnect wrapper (https://github.com/opencloud-eu/reva/blob/main/pkg/utils/ldap/reconnect.go) in a similar way :).

Comment thread services/graph/pkg/identity/backend.go Resolved
Comment thread services/graph/pkg/identity/ldap.go Resolved
case 1:
return res.Entries[0], nil
default:
return nil, ErrTooManyResults

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here. We need to map the LDAPResultSizeLimitExceeded error instead.

@pbleser-oc
pbleser-oc force-pushed the chore/#1312-graph-event-handler-split branch 2 times, most recently from 19a5124 to 38b3ebe Compare August 31, 2026 08:45

@rhafer rhafer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me now. I've kicked the CI once more, something seems to be flaky there :( .

@rhafer

rhafer commented Sep 1, 2026

Copy link
Copy Markdown
Member

@pbleser-oc The test-lint-unit failure is actually a real one:

=== RUN   TestGetGroup
2026-09-01T07:39:29Z DBG GetGroup line=/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group.go:30 refint=false request-id= service=opencloud write=true
2026-09-01T07:39:29Z DBG getLDAPGroupsByFilter attributes=["cn","entryUUID","member"] base=ou=groups,dc=test filter=(&(objectClass=groupOfNames)(|(cn=group)(entryUUID=group))) line=/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group.go:553 refint=false scope=2 service=opencloud sizelimit=1 write=true
    ldap_group_test.go:63: 
        	Error Trace:	/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group_test.go:63
        	Error:      	Error "tooManyResults: failed to search for LDAP groups" does not contain "itemNotFound:"
        	Test:       	TestGetGroup
2026-09-01T07:39:29Z DBG GetGroup line=/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group.go:30 refint=false request-id= service=opencloud write=true
2026-09-01T07:39:29Z DBG getLDAPGroupsByFilter attributes=["cn","entryUUID","member"] base=ou=groups,dc=test filter=(&(objectClass=groupOfNames)(|(cn=group)(entryUUID=group))) line=/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group.go:553 refint=false scope=2 service=opencloud sizelimit=1 write=true
    ldap_group_test.go:65: 
        	Error Trace:	/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group_test.go:65
        	Error:      	Error "tooManyResults: failed to search for LDAP groups" does not contain "itemNotFound:"
        	Test:       	TestGetGroup
2026-09-01T07:39:29Z DBG GetGroup line=/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group.go:30 refint=false request-id= service=opencloud write=true
2026-09-01T07:39:29Z DBG getLDAPGroupsByFilter attributes=["cn","entryUUID","member"] base=ou=groups,dc=test filter=(&(objectClass=groupOfNames)(|(cn=group)(entryUUID=group))) line=/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group.go:553 refint=false scope=2 service=opencloud sizelimit=1 write=true
    ldap_group_test.go:67: 
        	Error Trace:	/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group_test.go:67
        	Error:      	Error "tooManyResults: failed to search for LDAP groups" does not contain "itemNotFound:"
        	Test:       	TestGetGroup
2026-09-01T07:39:29Z DBG GetGroup line=/go/src/github.com/opencloud-eu/opencloud/services/graph/pkg/identity/ldap_group.go:30 refint=false request-id= service=opencloud write=true

@pbleser-oc
pbleser-oc force-pushed the chore/#1312-graph-event-handler-split branch from 38b3ebe to 32c7fc1 Compare September 1, 2026 08:47
dschmidt and others added 8 commits September 1, 2026 10:57
scope: takes an opaque resource id, which is hostile to hand-written
queries. Accept driveId:"<storage$space>" as a regular KQL field
instead: it resolves to the indexed RootID, and a bare drive id is
completed to the root resource id (a space root's opaque id is its
space id). Full root ids pass through untouched.

Combined with path: this gives a readable location scope without any
token stripping: both are plain fields, so they compose with groups,
OR and NOT like everything else.
When top-level AND conjuncts pin the query to a single root
(driveId/RootID restrictions), only that space's index is asked; the
restriction itself stays in the query, so this is purely an
optimization. Conservative by design: any top-level OR, negated or
group-nested restriction leaves the fan-out untouched, searching a
space too many is wasted work while skipping one would be wrong.
Mountpoints are kept for result path mapping.

Costs one extra parse of the query in the service; parsing once and
handing the AST to the engines (which currently re-parse per space) is
a follow-up that changes the engine interface.
SCOPE-06..09 cover the completed root id, negation and composition; the cross-space fixture root follows the space-root convention (opaque id = space id).
In the scope of the broader issue opencloud-eu#1312, this PR deals with performing
those changes for the `graph` service, namely to add the ability to
disable the HTTP API or to disable the events API handler by
configuration.

It also adds metrics for the events processing, and tests for the events
processing.

The previous implementation was combining the HTTP server service and
the events consumption, which is why this PR refactors the composition
of those services:

 * the event consumption has been moved into its own service
 * the identity.Backend is created beforehand, and then injected as a
   collaborator in both the HTTP service as well as the event consumer
   service

It also adds metrics, mainly for the event processing.

To encourage re-use in latter implementations and changes, it also
introduces two top-level package changes:

 * internal/eventstest/events_test_helpers: contains a TestBus
   implementation to unit-test event consumers without NATS
 * internal/metricstest/metrics_test_helpers: contains assertion
   functions to test Prometheus metrics
Introducing gowrap as a build-time tool to generate interface delegate
structs from templates:

 * added as a 'make go-generate' target in services/graph,
 * added as a build-time dependency in .bingo/

Introduce an LDAP client abstraction interface to be able to wrap the
go-ldap client API with metrics transparently (and possibly hooks and
such in the future), in order to use delegation patterns to measure the
time LDAP (client) operations take to finish, as well as to track their
results (success, failure, not-found).

Has two implementations that are generated using gowrap:

* a go-ldap adapter implementation that directly delegates to a go-ldap
  connection
* a time measuring and metrics collecting implementation that delegates
  to another LdapClient

The metrics collecting one is disabled by default, can be enabled with
GRAPH_LDAP_METRICS_DISABLE=false

It collects durations of outbound LDAP client operations into a histogram, as
well as the number of concurrent outbound LDAP operations in a gauge (via an
atomic int and a gauge function, as that performs best).

Add an HTTP middleware that measures how long Graph HTTP API requests
take, storing taken time into a histogram along with labels for

 * method,
 * path pattern (from the chi routes),
 * Graph API version prefix,
 * Graph API resource name,
 * and the resulting status code.

It also tracks the number of concurrent inbound Graph API HTTP requests
using a gauge (also using an atomic int and a gauge function).

Disabled by default, can be enabled with
GRAPH_HTTP_METRICS_DISABLE=false

Add Backend and EducationBackend delegate implementations that measure
execution time on the level of the higher API call operations there
(CreateUser, DeleteUser, ..., CreateSchool, ...), generated using
gowrap.

Disabled by default, can be enabled with
GRAPH_IDENTITY_BACKEND_METRICS_DISABLE=false

Also added a small k6 script to produce some read-only load on the Graph
API, for a casual test of the metrics, as well as k6 in mise.toml.

Make an internal changes to how singular LDAP entry searches work in the LDAP
identity backends:

 * check whether searches for a singular entry returns more than one
   result, in which case a new error TooManyResults is returned, instead
   of leaving that undetected, blindly taking the first result, and
   potentially risking data inconsistencies

Improve the loggers in identity backends by adding attributes for their
request targets (Reva gateway address or LDAP URI, respectively).

Also add a "backend" attribute for all Graph API logs (set to "ldap" or
"cs3"), to help debug potential issues, and remove them from all the logger
debug calls at the beginning of each LDAP-related function as those should
really be part of the logger and set beforehand.

The LDAP identity backend logger also has two new attributes to help
debugging with logs:

 * write (bool): whether write operations are enabled
 * refint (bool): whether refint is enabled or not

Also adds a dedicated counter metric for user password change operations.

Minor campfire improvements:

 * add a constructor func for the CS3 backend

 * add a constructor func for the LDAP backend

 * in the LDAP identity backend, in searchLDAPEntryByFilter (used by all
   search/get public functions), errors that occur when performing LDAP
   SEARCH operations were blindly mapped to a ItemNotFound error,
   instead of being analyzed as it could be caused by a technical error

 * in the requireadmin middleware, add debug logging to explain why a
   request is denied

 * when an LDAP password change fails because the user entry was not
   found in LDAP, we now have a log message that tracks that
  * introduce a fix in the metrics tools introduced with 8821053 in
    order to deal with a struct that has fields that are not exported
    (as is the case here)

  * introduce a func in the toplevel metrics package that registers a
    single metric, as that needs to be done explicitly for unexported
    ones

  * in the graph service, use RegisterAll and BuildInfo from the
    toplevel metrics package, as introduced with 8821053
@pbleser-oc
pbleser-oc force-pushed the chore/#1312-graph-event-handler-split branch from 3b0cd10 to e436532 Compare September 1, 2026 08:58
@pbleser-oc

Copy link
Copy Markdown
Member Author

Fixed the broken tests in ldap_group_test.go, spliced it into the commit with a fp to keep meaningfully squashed commits for the merge.

@pbleser-oc
pbleser-oc merged commit 249d105 into opencloud-eu:main Sep 1, 2026
66 of 67 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenCloud Team Board Sep 1, 2026
@pbleser-oc
pbleser-oc deleted the chore/#1312-graph-event-handler-split branch September 1, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants