Documentation
¶
Overview ¶
Package timestamp implements several component related to time.
Index ¶
- Constants
- Variables
- func Check(t time.Time) error
- func CheckPb(t *timestamppb.Timestamp) error
- func CheckTimeRange(timeRange *modelv1.TimeRange) error
- func Find(timestamps []int64, target int64) int
- func FindRange[T int64 | uint64](timestamps []T, minVal, maxVal T) (int, int, bool)
- func MToN(ms time.Time) time.Time
- func NowMilli() time.Time
- func ParseDuration(s string) (time.Duration, error)
- func SetClock(ctx context.Context, clock Clock) context.Context
- type Clock
- type MockClock
- type Scheduler
- type SchedulerAction
- type SchedulerMetrics
- type TimeRange
- func NewInclusiveTimeRange(start, end time.Time) TimeRange
- func NewInclusiveTimeRangeDuration(start time.Time, duration time.Duration) TimeRange
- func NewSectionTimeRange(start, end time.Time) TimeRange
- func NewTimeRange(start, end time.Time, includeStart, includeEnd bool) TimeRange
- func NewTimeRangeDuration(start time.Time, duration time.Duration, includeStart, includeEnd bool) TimeRange
Constants ¶
const ( // MinNanoTime is the minimum time that can be represented. // // 1677-09-21 00:12:43.145224192 +0000 UTC. MinNanoTime = int64(math.MinInt64) // MaxNanoTime is the maximum time that can be represented. // // 2262-04-11 23:47:16.854775807 +0000 UTC. MaxNanoTime = int64(math.MaxInt64) )
Variables ¶
var ( // ErrSchedulerClosed indicates the scheduler is closed. ErrSchedulerClosed = errors.New("the scheduler is closed") // ErrTaskDuplicated indicates registered task already exists. ErrTaskDuplicated = errors.New("the task is duplicated") )
var ( // DefaultTimeRange for the input time range. DefaultTimeRange = &modelv1.TimeRange{ Begin: defaultBeginPbTime, End: maxMilliPbTime, } )
Functions ¶
func CheckPb ¶
func CheckPb(t *timestamppb.Timestamp) error
CheckPb checks that a protobuf timestamp is valid.
func CheckTimeRange ¶
CheckTimeRange checks that a protobuf time range is valid.
func FindRange ¶ added in v0.6.0
FindRange returns the indices of the first and last elements in a sorted 'timestamps' slice that are within the min and max range.
func ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".
Types ¶
type Clock ¶
Clock represents an interface contains all functions in the standard library time.
type MockClock ¶
type MockClock interface { clock.Clock // Add moves the current time of the mock clock forward by the specified duration. Add(d time.Duration) // Set sets the current time of the mock clock to a specific one. Set(t time.Time) // TriggerTimer sends the current time to timer.C TriggerTimer() bool }
MockClock represents a mock clock that only moves forward programmatically.
type Scheduler ¶ added in v0.3.0
Scheduler maintains a registry of tasks and their duty cycle. It also provides a Trigger method to fire a task that is scheduled by a MockClock.
func NewScheduler ¶ added in v0.3.0
NewScheduler returns an instance of Scheduler.
func (*Scheduler) Close ¶ added in v0.3.0
func (s *Scheduler) Close()
Close the Scheduler and shut down all registered tasks.
func (*Scheduler) Metrics ¶ added in v0.7.0
func (s *Scheduler) Metrics() map[string]*SchedulerMetrics
Metrics returns the metrics of all registered tasks.
type SchedulerAction ¶ added in v0.3.0
SchedulerAction is an executable when a trigger is fired now is the trigger time, logger has a context indicating the task's identity.
type SchedulerMetrics ¶ added in v0.7.0
type SchedulerMetrics struct { TotalJobsStarted atomic.Uint64 TotalJobsFinished atomic.Uint64 TotalTasksStarted atomic.Uint64 TotalTasksFinished atomic.Uint64 TotalTasksPanic atomic.Uint64 TotalTaskLatencyInNanoseconds atomic.Int64 }
SchedulerMetrics collects the metrics of a Scheduler.
type TimeRange ¶
TimeRange is a range of periods into which data can be written or retrieved.
func NewInclusiveTimeRange ¶
NewInclusiveTimeRange returns TimeRange includes start and end time.
func NewInclusiveTimeRangeDuration ¶
NewInclusiveTimeRangeDuration returns TimeRange includes start and end time. It is created from a start time and the Duration.
func NewSectionTimeRange ¶ added in v0.2.0
NewSectionTimeRange returns TimeRange includes start time. This function is for creating blocks and segments of tsdb.
func NewTimeRange ¶
NewTimeRange returns TimeRange.
func NewTimeRangeDuration ¶
func NewTimeRangeDuration(start time.Time, duration time.Duration, includeStart, includeEnd bool) TimeRange
NewTimeRangeDuration returns TimeRange from a start time and the Duration.
func (TimeRange) Before ¶ added in v0.6.0
Before returns whether the TimeRange is before the other time.
func (TimeRange) Overlapping ¶
Overlapping returns whether TimeRanges intersect each other.