MCPcopy
hub / github.com/grafana/tempo / update

Method update

modules/overrides/userconfigurable/api/api.go:115–160  ·  view source on GitHub ↗
(ctx context.Context, userID string, patch []byte, skipConflictingOverridesCheck bool)

Source from the content-addressed store, hash-verified

113}
114
115func (a *UserConfigOverridesAPI) update(ctx context.Context, userID string, patch []byte, skipConflictingOverridesCheck bool) (*client.Limits, backend.Version, error) {
116 ctx, span := tracer.Start(ctx, "UserConfigOverridesAPI.update", trace.WithAttributes(
117 attribute.String("userID", userID),
118 ))
119 defer span.End()
120 traceID, _ := tracing.ExtractTraceID(ctx)
121
122 currLimits, currVersion, err := a.client.Get(ctx, userID)
123 if err != nil && !errors.Is(err, backend.ErrDoesNotExist) {
124 return nil, "", err
125 }
126
127 level.Info(a.logger).Log("traceID", traceID, "msg", "patching user-configurable overrides", "userID", userID, "patch", patch, "currLimits", logLimits(currLimits), "currVersion", currVersion)
128
129 if errors.Is(err, backend.ErrDoesNotExist) {
130 currVersion = backend.VersionNew
131 }
132
133 patchedBytes := patch
134 if !errors.Is(err, backend.ErrDoesNotExist) {
135 currBytes, err := json.Marshal(currLimits)
136 if err != nil {
137 return nil, "", err
138 }
139
140 patchedBytes, err = jsonpatch.MergePatch(currBytes, patch)
141 if err != nil {
142 return nil, "", err
143 }
144 }
145
146 patchedLimits, err := a.parseLimits(bytes.NewReader(patchedBytes))
147 if err != nil {
148 return nil, "", newValidationError(err)
149 }
150
151 version, err := a.set(ctx, userID, patchedLimits, currVersion, skipConflictingOverridesCheck)
152 if errors.Is(err, backend.ErrVersionDoesNotMatch) {
153 return nil, "", errors.New("overrides have been modified during request processing, try again")
154 }
155 if err != nil {
156 return nil, "", err
157 }
158
159 return patchedLimits, version, err
160}
161
162func (a *UserConfigOverridesAPI) delete(ctx context.Context, userID string, version backend.Version) error {
163 ctx, span := tracer.Start(ctx, "UserConfigOverridesAPI.delete", trace.WithAttributes(

Callers 1

PatchHandlerMethod · 0.95

Calls 10

parseLimitsMethod · 0.95
setMethod · 0.95
ExtractTraceIDFunction · 0.92
logLimitsFunction · 0.85
newValidationErrorFunction · 0.85
StartMethod · 0.65
GetMethod · 0.65
LogMethod · 0.65
MarshalMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected