MCPcopy
hub / github.com/keploy/keploy / FilterByTimeStampThreeTier

Function FilterByTimeStampThreeTier

pkg/util.go:3371–3505  ·  view source on GitHub ↗

FilterByTimeStampThreeTier is the three-pool, Lifetime-authoritative variant of filterByTimeStampTierAware. It elevates the startup tier (LifetimeConnection) to a first-class split at the core filter level so integrations that consume the pools (Postgres v3's BuildIndex, MySQL's per-connID trees) ca

(ctx context.Context, logger *zap.Logger, m []*models.Mock, afterTime, beforeTime time.Time, strictPerCall bool, firstWindowStart time.Time)

Source from the content-addressed store, hash-verified

3369// "connection-scoped reusable" pool without having to re-derive the
3370// classification from metadata.
3371func FilterByTimeStampThreeTier(ctx context.Context, logger *zap.Logger, m []*models.Mock, afterTime, beforeTime time.Time, strictPerCall bool, firstWindowStart time.Time) (filtered, unfiltered, startup []*models.Mock) {
3372 filtered = make([]*models.Mock, 0)
3373 unfiltered = make([]*models.Mock, 0)
3374 startup = make([]*models.Mock, 0)
3375
3376 if afterTime.Equal(time.Time{}) || beforeTime.Equal(time.Time{}) {
3377 // No window supplied — fall back to lifetime-only partitioning
3378 // so callers still get a three-way split. PerTest (and legacy-
3379 // untagged) mocks return in `filtered` to match the two-slice
3380 // legacy contract where the first return slice was "every mock
3381 // with no effective window to apply".
3382 for _, mk := range m {
3383 if mk == nil {
3384 continue
3385 }
3386 p := mk.DeepCopy()
3387 lt := effectiveLifetimeForRouting(p)
3388 switch lt {
3389 case models.LifetimeSession:
3390 p.TestModeInfo.IsFiltered = false
3391 unfiltered = append(unfiltered, p)
3392 case models.LifetimeConnection:
3393 p.TestModeInfo.IsFiltered = false
3394 startup = append(startup, p)
3395 default:
3396 p.TestModeInfo.IsFiltered = true
3397 filtered = append(filtered, p)
3398 }
3399 }
3400 return filtered, unfiltered, startup
3401 }
3402
3403 strict := strictWindowEnabled(strictPerCall)
3404 var droppedOutOfWindow, droppedInvalidOrder, preservedStartup int
3405 isNonKeploy := false
3406
3407 for _, mk := range m {
3408 if mk == nil {
3409 continue
3410 }
3411 p := mk.DeepCopy()
3412 if p.Version != "api.keploy.io/v1beta1" && p.Version != "api.keploy.io/v1beta2" {
3413 isNonKeploy = true
3414 }
3415 if p.Spec.ReqTimestampMock.Equal(time.Time{}) || p.Spec.ResTimestampMock.Equal(time.Time{}) {
3416 logger.Debug("request or response timestamp of mock is missing",
3417 zap.String("mock", p.Name), zap.Bool("strict", strict))
3418 p.TestModeInfo.IsFiltered = true
3419 filtered = append(filtered, p)
3420 continue
3421 }
3422 if p.Spec.ResTimestampMock.Before(p.Spec.ReqTimestampMock) {
3423 logger.Debug("mock has response timestamp before request timestamp; dropping",
3424 zap.String("mock", p.Name),
3425 zap.Time("req", p.Spec.ReqTimestampMock),
3426 zap.Time("res", p.Spec.ResTimestampMock))
3427 droppedInvalidOrder++
3428 continue

Callers 1

Calls 6

strictWindowEnabledFunction · 0.85
DeepCopyMethod · 0.80
IsZeroMethod · 0.80
DebugMethod · 0.65
StringMethod · 0.45

Tested by 1