(ctx context.Context, userID string, patch []byte, skipConflictingOverridesCheck bool)
| 113 | } |
| 114 | |
| 115 | func (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 | |
| 162 | func (a *UserConfigOverridesAPI) delete(ctx context.Context, userID string, version backend.Version) error { |
| 163 | ctx, span := tracer.Start(ctx, "UserConfigOverridesAPI.delete", trace.WithAttributes( |
no test coverage detected