Beispiel #1
0
func (st logStreamState) getStart(sink string, allModels bool) (time.Time, error) {
	var tracker *state.LastSentLogTracker
	if allModels {
		var err error
		tracker, err = state.NewAllLastSentLogTracker(st, sink)
		if err != nil {
			return time.Time{}, errors.Trace(err)
		}
	} else {
		tracker = state.NewLastSentLogTracker(st, st.ModelUUID(), sink)
	}
	defer tracker.Close()

	// Resume for the sink...
	_, lastSentTimestamp, err := tracker.Get()
	if errors.Cause(err) == state.ErrNeverForwarded {
		// If we've never forwarded a message, we start from
		// position zero.
		lastSentTimestamp = 0
	} else if err != nil {
		return time.Time{}, errors.Trace(err)
	}

	// Using the same timestamp will cause at least 1 duplicate
	// entry, but that is better than dropping records.
	// TODO(ericsnow) Add 1 to start once we track by sequential int ID
	// instead of by timestamp.
	return time.Unix(0, lastSentTimestamp), nil
}
Beispiel #2
0
func (s *LogsSuite) TestAllLastSentLogTrackerNotController(c *gc.C) {
	st := s.NewStateForModelNamed(c, "test-model")
	defer st.Close()

	_, err := state.NewAllLastSentLogTracker(st, "test")

	c.Check(err, gc.ErrorMatches, `only the admin model can track all log records`)
}
Beispiel #3
0
func (s *LogsSuite) TestAllLastSentLogTrackerSetGet(c *gc.C) {
	tracker, err := state.NewAllLastSentLogTracker(s.State, "test-sink")
	c.Assert(err, jc.ErrorIsNil)
	defer tracker.Close()

	err = tracker.Set(10, 100)
	c.Assert(err, jc.ErrorIsNil)
	id1, ts1, err := tracker.Get()
	c.Assert(err, jc.ErrorIsNil)
	err = tracker.Set(20, 200)
	c.Assert(err, jc.ErrorIsNil)
	id2, ts2, err := tracker.Get()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(id1, gc.Equals, int64(10))
	c.Check(ts1, gc.Equals, int64(100))
	c.Check(id2, gc.Equals, int64(20))
	c.Check(ts2, gc.Equals, int64(200))
}