prometheus
71 строка · 2.0 Кб
1// Copyright 2017 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package storage
15
16import (
17"github.com/prometheus/prometheus/util/annotations"
18)
19
20// lazyGenericSeriesSet is a wrapped series set that is initialised on first call to Next().
21type lazyGenericSeriesSet struct {
22init func() (genericSeriesSet, bool)
23
24set genericSeriesSet
25}
26
27func (c *lazyGenericSeriesSet) Next() bool {
28if c.set != nil {
29return c.set.Next()
30}
31var ok bool
32c.set, ok = c.init()
33return ok
34}
35
36func (c *lazyGenericSeriesSet) Err() error {
37if c.set != nil {
38return c.set.Err()
39}
40return nil
41}
42
43func (c *lazyGenericSeriesSet) At() Labels {
44if c.set != nil {
45return c.set.At()
46}
47return nil
48}
49
50func (c *lazyGenericSeriesSet) Warnings() annotations.Annotations {
51if c.set != nil {
52return c.set.Warnings()
53}
54return nil
55}
56
57type warningsOnlySeriesSet annotations.Annotations
58
59func (warningsOnlySeriesSet) Next() bool { return false }
60func (warningsOnlySeriesSet) Err() error { return nil }
61func (warningsOnlySeriesSet) At() Labels { return nil }
62func (c warningsOnlySeriesSet) Warnings() annotations.Annotations { return annotations.Annotations(c) }
63
64type errorOnlySeriesSet struct {
65err error
66}
67
68func (errorOnlySeriesSet) Next() bool { return false }
69func (errorOnlySeriesSet) At() Labels { return nil }
70func (s errorOnlySeriesSet) Err() error { return s.err }
71func (errorOnlySeriesSet) Warnings() annotations.Annotations { return nil }
72