checkWriteRequest return if applying the provided WriteRequest will result in a consistent state of metrics. The dms is not modified by the check. However, the WriteRequest _will_ be sanitized: the MetricFamilies are ensured to contain the grouping Labels after the check. If false is returned, the c
(wr WriteRequest)
| 347 | // consistency check is skipped. The WriteRequest is still sanitized, and the |
| 348 | // presence of timestamps still results in returning false. |
| 349 | func (dms *DiskMetricStore) checkWriteRequest(wr WriteRequest) bool { |
| 350 | if wr.MetricFamilies == nil { |
| 351 | // Delete request cannot create inconsistencies, and nothing has |
| 352 | // to be sanitized. |
| 353 | return true |
| 354 | } |
| 355 | |
| 356 | var err error |
| 357 | defer func() { |
| 358 | if err != nil && wr.Done != nil { |
| 359 | wr.Done <- err |
| 360 | } |
| 361 | }() |
| 362 | |
| 363 | if timestampsPresent(wr.MetricFamilies) { |
| 364 | err = errTimestamp |
| 365 | return false |
| 366 | } |
| 367 | for _, mf := range wr.MetricFamilies { |
| 368 | sanitizeLabels(mf, wr.Labels) |
| 369 | } |
| 370 | |
| 371 | // Without Done channel, don't do the expensive consistency check. |
| 372 | if wr.Done == nil { |
| 373 | return true |
| 374 | } |
| 375 | |
| 376 | // Construct a test dms, acting on a copy of the metrics, to test the |
| 377 | // WriteRequest with. |
| 378 | tdms := &DiskMetricStore{ |
| 379 | metricGroups: dms.GetMetricFamiliesMap(), |
| 380 | predefinedHelp: dms.predefinedHelp, |
| 381 | logger: promslog.NewNopLogger(), |
| 382 | } |
| 383 | tdms.processWriteRequest(wr) |
| 384 | |
| 385 | // Construct a test Gatherer to check if consistent gathering is possible. |
| 386 | tg := prometheus.Gatherers{ |
| 387 | prometheus.DefaultGatherer, |
| 388 | prometheus.GathererFunc(func() ([]*dto.MetricFamily, error) { |
| 389 | return tdms.GetMetricFamilies(), nil |
| 390 | }), |
| 391 | } |
| 392 | if _, err = tg.Gather(); err != nil { |
| 393 | return false |
| 394 | } |
| 395 | return true |
| 396 | } |
| 397 | |
| 398 | func (dms *DiskMetricStore) persist() error { |
| 399 | // Check (again) if persistence is configured because some code paths |
no test coverage detected