Files
opencloud/services/graph/pkg/identity/education_backend_prometheus.go
T
Pascal Bleser 5b72318493 chore(graph): add metrics for HTTP API and LDAP
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
2026-09-01 10:57:47 +02:00

872 lines
25 KiB
Go

// Code generated by gowrap. DO NOT EDIT.
// template: backend_prometheus.tmpl
// gowrap: http://github.com/hexdigest/gowrap
package identity
import (
"context"
"time"
libregraph "github.com/opencloud-eu/libre-graph-api-go"
"github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode"
"github.com/prometheus/client_golang/prometheus"
)
// PrometheusEducationBackend implements EducationBackend interface with all methods wrapped
// with Prometheus metrics
type PrometheusEducationBackend struct {
delegate EducationBackend
metric *prometheus.HistogramVec
}
var _ EducationBackend = &PrometheusEducationBackend{}
// returns an instance of the EducationBackend decorated with prometheus metric
func NewPrometheusEducationBackend(delegate EducationBackend, metric *prometheus.HistogramVec) PrometheusEducationBackend {
return PrometheusEducationBackend{
delegate: delegate,
metric: metric,
}
}
// AddClassesToEducationSchool implements EducationBackend.AddClassesToEducationSchool
func (_d PrometheusEducationBackend) AddClassesToEducationSchool(ctx context.Context, schoolNumberOrID string, memberIDs []string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpAddClassesToEducationSchool, result).Observe(duration)
}()
return _d.delegate.AddClassesToEducationSchool(ctx, schoolNumberOrID, memberIDs)
}
// AddTeacherToEducationClass implements EducationBackend.AddTeacherToEducationClass
func (_d PrometheusEducationBackend) AddTeacherToEducationClass(ctx context.Context, classID string, teacherID string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpAddTeacherToEducationClass, result).Observe(duration)
}()
return _d.delegate.AddTeacherToEducationClass(ctx, classID, teacherID)
}
// AddUsersToEducationSchool implements EducationBackend.AddUsersToEducationSchool
func (_d PrometheusEducationBackend) AddUsersToEducationSchool(ctx context.Context, schoolID string, memberID []string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpAddUsersToEducationSchool, result).Observe(duration)
}()
return _d.delegate.AddUsersToEducationSchool(ctx, schoolID, memberID)
}
// CreateEducationClass implements EducationBackend.CreateEducationClass
func (_d PrometheusEducationBackend) CreateEducationClass(ctx context.Context, class libregraph.EducationClass) (ep1 *libregraph.EducationClass, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpCreateEducationClass, result).Observe(duration)
}()
return _d.delegate.CreateEducationClass(ctx, class)
}
// CreateEducationSchool implements EducationBackend.CreateEducationSchool
func (_d PrometheusEducationBackend) CreateEducationSchool(ctx context.Context, group libregraph.EducationSchool) (ep1 *libregraph.EducationSchool, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpCreateEducationSchool, result).Observe(duration)
}()
return _d.delegate.CreateEducationSchool(ctx, group)
}
// CreateEducationUser implements EducationBackend.CreateEducationUser
func (_d PrometheusEducationBackend) CreateEducationUser(ctx context.Context, user libregraph.EducationUser) (ep1 *libregraph.EducationUser, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpCreateEducationUser, result).Observe(duration)
}()
return _d.delegate.CreateEducationUser(ctx, user)
}
// DeleteEducationClass implements EducationBackend.DeleteEducationClass
func (_d PrometheusEducationBackend) DeleteEducationClass(ctx context.Context, nameOrID string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpDeleteEducationClass, result).Observe(duration)
}()
return _d.delegate.DeleteEducationClass(ctx, nameOrID)
}
// DeleteEducationSchool implements EducationBackend.DeleteEducationSchool
func (_d PrometheusEducationBackend) DeleteEducationSchool(ctx context.Context, id string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpDeleteEducationSchool, result).Observe(duration)
}()
return _d.delegate.DeleteEducationSchool(ctx, id)
}
// DeleteEducationUser implements EducationBackend.DeleteEducationUser
func (_d PrometheusEducationBackend) DeleteEducationUser(ctx context.Context, nameOrID string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpDeleteEducationUser, result).Observe(duration)
}()
return _d.delegate.DeleteEducationUser(ctx, nameOrID)
}
// FilterEducationSchoolsByAttribute implements EducationBackend.FilterEducationSchoolsByAttribute
func (_d PrometheusEducationBackend) FilterEducationSchoolsByAttribute(ctx context.Context, attr string, value string) (epa1 []*libregraph.EducationSchool, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpFilterEducationSchoolsByAttribute, result).Observe(duration)
}()
return _d.delegate.FilterEducationSchoolsByAttribute(ctx, attr, value)
}
// FilterEducationUsersByAttribute implements EducationBackend.FilterEducationUsersByAttribute
func (_d PrometheusEducationBackend) FilterEducationUsersByAttribute(ctx context.Context, attr string, value string) (epa1 []*libregraph.EducationUser, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpFilterEducationUsersByAttribute, result).Observe(duration)
}()
return _d.delegate.FilterEducationUsersByAttribute(ctx, attr, value)
}
// GetEducationClass implements EducationBackend.GetEducationClass
func (_d PrometheusEducationBackend) GetEducationClass(ctx context.Context, namedOrID string) (ep1 *libregraph.EducationClass, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
// it's a get operation that returns a pointer (and not an array): check whether that's nil or not
if ep1 == nil {
result = MetricResultNotFound
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationClass, result).Observe(duration)
}()
return _d.delegate.GetEducationClass(ctx, namedOrID)
}
// GetEducationClassMembers implements EducationBackend.GetEducationClassMembers
func (_d PrometheusEducationBackend) GetEducationClassMembers(ctx context.Context, nameOrID string) (epa1 []*libregraph.EducationUser, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationClassMembers, result).Observe(duration)
}()
return _d.delegate.GetEducationClassMembers(ctx, nameOrID)
}
// GetEducationClassTeachers implements EducationBackend.GetEducationClassTeachers
func (_d PrometheusEducationBackend) GetEducationClassTeachers(ctx context.Context, classID string) (epa1 []*libregraph.EducationUser, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationClassTeachers, result).Observe(duration)
}()
return _d.delegate.GetEducationClassTeachers(ctx, classID)
}
// GetEducationClasses implements EducationBackend.GetEducationClasses
func (_d PrometheusEducationBackend) GetEducationClasses(ctx context.Context) (epa1 []*libregraph.EducationClass, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationClasses, result).Observe(duration)
}()
return _d.delegate.GetEducationClasses(ctx)
}
// GetEducationSchool implements EducationBackend.GetEducationSchool
func (_d PrometheusEducationBackend) GetEducationSchool(ctx context.Context, nameOrID string) (ep1 *libregraph.EducationSchool, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
// it's a get operation that returns a pointer (and not an array): check whether that's nil or not
if ep1 == nil {
result = MetricResultNotFound
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationSchool, result).Observe(duration)
}()
return _d.delegate.GetEducationSchool(ctx, nameOrID)
}
// GetEducationSchoolClasses implements EducationBackend.GetEducationSchoolClasses
func (_d PrometheusEducationBackend) GetEducationSchoolClasses(ctx context.Context, schoolNumberOrID string) (epa1 []*libregraph.EducationClass, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationSchoolClasses, result).Observe(duration)
}()
return _d.delegate.GetEducationSchoolClasses(ctx, schoolNumberOrID)
}
// GetEducationSchoolUsers implements EducationBackend.GetEducationSchoolUsers
func (_d PrometheusEducationBackend) GetEducationSchoolUsers(ctx context.Context, id string) (epa1 []*libregraph.EducationUser, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationSchoolUsers, result).Observe(duration)
}()
return _d.delegate.GetEducationSchoolUsers(ctx, id)
}
// GetEducationSchools implements EducationBackend.GetEducationSchools
func (_d PrometheusEducationBackend) GetEducationSchools(ctx context.Context) (epa1 []*libregraph.EducationSchool, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationSchools, result).Observe(duration)
}()
return _d.delegate.GetEducationSchools(ctx)
}
// GetEducationUser implements EducationBackend.GetEducationUser
func (_d PrometheusEducationBackend) GetEducationUser(ctx context.Context, nameOrID string) (ep1 *libregraph.EducationUser, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
// it's a get operation that returns a pointer (and not an array): check whether that's nil or not
if ep1 == nil {
result = MetricResultNotFound
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationUser, result).Observe(duration)
}()
return _d.delegate.GetEducationUser(ctx, nameOrID)
}
// GetEducationUsers implements EducationBackend.GetEducationUsers
func (_d PrometheusEducationBackend) GetEducationUsers(ctx context.Context) (epa1 []*libregraph.EducationUser, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpGetEducationUsers, result).Observe(duration)
}()
return _d.delegate.GetEducationUsers(ctx)
}
// RemoveClassFromEducationSchool implements EducationBackend.RemoveClassFromEducationSchool
func (_d PrometheusEducationBackend) RemoveClassFromEducationSchool(ctx context.Context, schoolNumberOrID string, memberID string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpRemoveClassFromEducationSchool, result).Observe(duration)
}()
return _d.delegate.RemoveClassFromEducationSchool(ctx, schoolNumberOrID, memberID)
}
// RemoveTeacherFromEducationClass implements EducationBackend.RemoveTeacherFromEducationClass
func (_d PrometheusEducationBackend) RemoveTeacherFromEducationClass(ctx context.Context, classID string, teacherID string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpRemoveTeacherFromEducationClass, result).Observe(duration)
}()
return _d.delegate.RemoveTeacherFromEducationClass(ctx, classID, teacherID)
}
// RemoveUserFromEducationSchool implements EducationBackend.RemoveUserFromEducationSchool
func (_d PrometheusEducationBackend) RemoveUserFromEducationSchool(ctx context.Context, schoolID string, memberID string) (err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpRemoveUserFromEducationSchool, result).Observe(duration)
}()
return _d.delegate.RemoveUserFromEducationSchool(ctx, schoolID, memberID)
}
// UpdateEducationClass implements EducationBackend.UpdateEducationClass
func (_d PrometheusEducationBackend) UpdateEducationClass(ctx context.Context, id string, class libregraph.EducationClass) (ep1 *libregraph.EducationClass, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpUpdateEducationClass, result).Observe(duration)
}()
return _d.delegate.UpdateEducationClass(ctx, id, class)
}
// UpdateEducationSchool implements EducationBackend.UpdateEducationSchool
func (_d PrometheusEducationBackend) UpdateEducationSchool(ctx context.Context, numberOrID string, school libregraph.EducationSchool) (ep1 *libregraph.EducationSchool, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpUpdateEducationSchool, result).Observe(duration)
}()
return _d.delegate.UpdateEducationSchool(ctx, numberOrID, school)
}
// UpdateEducationUser implements EducationBackend.UpdateEducationUser
func (_d PrometheusEducationBackend) UpdateEducationUser(ctx context.Context, nameOrID string, user libregraph.EducationUser) (ep1 *libregraph.EducationUser, err error) {
_since := time.Now()
defer func() {
duration := time.Since(_since).Seconds()
result := MetricResultSuccess
if err != nil {
result = MetricResultFailure
if err == ErrReadOnly {
result = MetricResultReadOnly
}
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
} else {
if e, ok := errorcode.ToError(err); ok {
if e.GetCode() == errorcode.ItemNotFound {
result = MetricResultNotFound
}
}
}
_d.metric.WithLabelValues(MetricOpUpdateEducationUser, result).Observe(duration)
}()
return _d.delegate.UpdateEducationUser(ctx, nameOrID, user)
}