func log(q Query, i *indexfile.IndexFile, bp *base.Positions, err *error) func() { start := time.Now() if q.base() { indexBaseLookupsStarted.Increment() } else { indexSetLookupsStarted.Increment() } return func() { duration := time.Since(start) if q.base() { indexBaseLookupsFinished.Increment() indexBaseLookupNanos.IncrementBy(duration.Nanoseconds()) } else { indexSetLookupsFinished.Increment() indexSetLookupNanos.IncrementBy(duration.Nanoseconds()) } v(3, "Query %q in %q took %v, found %d %v", q, i.Name(), duration, len(*bp), *err) } }
func (a timeQuery) LookupIn(ctx context.Context, index *indexfile.IndexFile) (bp base.Positions, err error) { defer log(a, index, &bp, &err)() last := filepath.Base(index.Name()) intval, err := strconv.ParseInt(last, 10, 64) if err != nil { return nil, fmt.Errorf("could not parse basename %q: %v", last, err) } t := time.Unix(0, intval*1000) // converts micros -> nanos // Note, we add a minute when doing 'before' queries and subtract a minute // when doing 'after' queries, to make sure we actually get the time // specified. if !a[0].IsZero() && t.Before(a[0].Add(time.Minute)) { v(2, "time query skipping %q", index.Name()) return base.NoPositions, nil } if !a[1].IsZero() && t.After(a[1].Add(-time.Minute)) { v(2, "time query skipping %q", index.Name()) return base.NoPositions, nil } v(2, "time query using %q", index.Name()) return base.AllPositions, nil }
func (q mplsQuery) LookupIn(ctx context.Context, index *indexfile.IndexFile) (bp base.Positions, err error) { defer log(q, index, &bp, &err)() return index.MPLSPositions(ctx, uint32(q)) }
func (q vlanQuery) LookupIn(ctx context.Context, index *indexfile.IndexFile) (bp base.Positions, err error) { defer log(q, index, &bp, &err)() return index.VLANPositions(ctx, uint16(q)) }
func (q ipQuery) LookupIn(ctx context.Context, index *indexfile.IndexFile) (bp base.Positions, err error) { defer log(q, index, &bp, &err)() return index.IPPositions(ctx, q[0], q[1]) }
func (q protocolQuery) LookupIn(ctx context.Context, index *indexfile.IndexFile) (bp base.Positions, err error) { defer log(q, index, &bp, &err)() return index.ProtoPositions(ctx, byte(q)) }