MCPcopy Index your code
hub / github.com/cortexproject/cortex / Push

Method Push

pkg/ingester/ingester.go:1269–1685  ·  view source on GitHub ↗

Push adds metrics to a block

(ctx context.Context, req *cortexpb.WriteRequest)

Source from the content-addressed store, hash-verified

1267
1268// Push adds metrics to a block
1269func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*cortexpb.WriteResponse, error) {
1270 if err := i.checkRunning(); err != nil {
1271 return nil, err
1272 }
1273
1274 span, ctx := opentracing.StartSpanFromContext(ctx, "Ingester.Push")
1275 defer span.Finish()
1276
1277 userID, err := users.TenantID(ctx)
1278 if err != nil {
1279 return nil, err
1280 }
1281
1282 // We will report *this* request in the error too.
1283 inflight := i.inflightPushRequests.Inc()
1284 i.maxInflightPushRequests.Track(inflight)
1285 defer i.inflightPushRequests.Dec()
1286
1287 gl := i.getInstanceLimits()
1288 if gl != nil && gl.MaxInflightPushRequests > 0 {
1289 if inflight > gl.MaxInflightPushRequests {
1290 i.metrics.pushErrorsTotal.WithLabelValues(userID, pushErrTooManyInflightRequests).Inc()
1291 return nil, errTooManyInflightPushRequests
1292 }
1293 }
1294
1295 var firstPartialErr error
1296
1297 // NOTE: because we use `unsafe` in deserialisation, we must not
1298 // retain anything from `req` past the call to ReuseSlice
1299 defer req.Free()
1300 defer cortexpb.ReuseSlice(req.Timeseries)
1301
1302 il := i.getInstanceLimits()
1303 if il != nil && il.MaxIngestionRate > 0 {
1304 if rate := i.ingestionRate.Rate(); rate >= il.MaxIngestionRate {
1305 return nil, errMaxSamplesPushRateLimitReached
1306 }
1307 }
1308
1309 db, err := i.getOrCreateTSDB(userID, false)
1310 if err != nil {
1311 return nil, wrapWithUser(err, userID)
1312 }
1313
1314 // Ensure the ingester shutdown procedure hasn't started
1315 i.stoppedMtx.RLock()
1316 if i.stopped {
1317 i.stoppedMtx.RUnlock()
1318 return nil, errIngesterStopping
1319 }
1320 i.stoppedMtx.RUnlock()
1321
1322 if err := db.acquireAppendLock(); err != nil {
1323 return &cortexpb.WriteResponse{}, httpgrpc.Errorf(http.StatusServiceUnavailable, "%s", wrapWithUser(err, userID).Error())
1324 }
1325 defer db.releaseAppendLock()
1326

Callers 1

PushStreamMethod · 0.95

Implementers 1

Ingesterpkg/ingester/ingester.go

Calls 15

checkRunningMethod · 0.95
getInstanceLimitsMethod · 0.95
getOrCreateTSDBMethod · 0.95
pushMetadataMethod · 0.95
isLabelSetOutOfOrderMethod · 0.95
getMaxExemplarsMethod · 0.95
TenantIDFunction · 0.92
ReuseSliceFunction · 0.92

Tested by

no test coverage detected