Skip to content

Commit

Permalink
Switch from client_golang/model to common/model
Browse files Browse the repository at this point in the history
  • Loading branch information
fabxc committed Aug 21, 2015
1 parent 7a6d12a commit 306e846
Show file tree
Hide file tree
Showing 72 changed files with 1,419 additions and 1,419 deletions.
36 changes: 18 additions & 18 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"gopkg.in/yaml.v2"

clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/common/model"

"github.com/prometheus/prometheus/util/strutil"
)
Expand Down Expand Up @@ -270,7 +270,7 @@ type GlobalConfig struct {
// How frequently to evaluate rules by default.
EvaluationInterval Duration `yaml:"evaluation_interval,omitempty"`
// The labels to add to any timeseries that this Prometheus instance scrapes.
Labels clientmodel.LabelSet `yaml:"labels,omitempty"`
Labels model.LabelSet `yaml:"labels,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
Expand Down Expand Up @@ -399,9 +399,9 @@ func (a *BasicAuth) UnmarshalYAML(unmarshal func(interface{}) error) error {
type TargetGroup struct {
// Targets is a list of targets identified by a label set. Each target is
// uniquely identifiable in the group by its address label.
Targets []clientmodel.LabelSet
Targets []model.LabelSet
// Labels is a set of labels that is common across all targets in the group.
Labels clientmodel.LabelSet
Labels model.LabelSet

// Source is an identifier that describes a group of targets.
Source string
Expand All @@ -415,19 +415,19 @@ func (tg TargetGroup) String() string {
func (tg *TargetGroup) UnmarshalYAML(unmarshal func(interface{}) error) error {
g := struct {
Targets []string `yaml:"targets"`
Labels clientmodel.LabelSet `yaml:"labels"`
Labels model.LabelSet `yaml:"labels"`
XXX map[string]interface{} `yaml:",inline"`
}{}
if err := unmarshal(&g); err != nil {
return err
}
tg.Targets = make([]clientmodel.LabelSet, 0, len(g.Targets))
tg.Targets = make([]model.LabelSet, 0, len(g.Targets))
for _, t := range g.Targets {
if strings.Contains(t, "/") {
return fmt.Errorf("%q is not a valid hostname", t)
}
tg.Targets = append(tg.Targets, clientmodel.LabelSet{
clientmodel.AddressLabel: clientmodel.LabelValue(t),
tg.Targets = append(tg.Targets, model.LabelSet{
model.AddressLabel: model.LabelValue(t),
})
}
tg.Labels = g.Labels
Expand All @@ -437,34 +437,34 @@ func (tg *TargetGroup) UnmarshalYAML(unmarshal func(interface{}) error) error {
// MarshalYAML implements the yaml.Marshaler interface.
func (tg TargetGroup) MarshalYAML() (interface{}, error) {
g := &struct {
Targets []string `yaml:"targets"`
Labels clientmodel.LabelSet `yaml:"labels,omitempty"`
Targets []string `yaml:"targets"`
Labels model.LabelSet `yaml:"labels,omitempty"`
}{
Targets: make([]string, 0, len(tg.Targets)),
Labels: tg.Labels,
}
for _, t := range tg.Targets {
g.Targets = append(g.Targets, string(t[clientmodel.AddressLabel]))
g.Targets = append(g.Targets, string(t[model.AddressLabel]))
}
return g, nil
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (tg *TargetGroup) UnmarshalJSON(b []byte) error {
g := struct {
Targets []string `json:"targets"`
Labels clientmodel.LabelSet `json:"labels"`
Targets []string `json:"targets"`
Labels model.LabelSet `json:"labels"`
}{}
if err := json.Unmarshal(b, &g); err != nil {
return err
}
tg.Targets = make([]clientmodel.LabelSet, 0, len(g.Targets))
tg.Targets = make([]model.LabelSet, 0, len(g.Targets))
for _, t := range g.Targets {
if strings.Contains(t, "/") {
return fmt.Errorf("%q is not a valid hostname", t)
}
tg.Targets = append(tg.Targets, clientmodel.LabelSet{
clientmodel.AddressLabel: clientmodel.LabelValue(t),
tg.Targets = append(tg.Targets, model.LabelSet{
model.AddressLabel: model.LabelValue(t),
})
}
tg.Labels = g.Labels
Expand Down Expand Up @@ -686,15 +686,15 @@ func (a *RelabelAction) UnmarshalYAML(unmarshal func(interface{}) error) error {
type RelabelConfig struct {
// A list of labels from which values are taken and concatenated
// with the configured separator in order.
SourceLabels clientmodel.LabelNames `yaml:"source_labels,flow"`
SourceLabels model.LabelNames `yaml:"source_labels,flow"`
// Separator is the string between concatenated values from the source labels.
Separator string `yaml:"separator,omitempty"`
// Regex against which the concatenation is matched.
Regex *Regexp `yaml:"regex,omitempty"`
// Modulus to take of the hash of concatenated values from the source labels.
Modulus uint64 `yaml:"modulus,omitempty"`
// The label to which the resulting string is written in a replacement.
TargetLabel clientmodel.LabelName `yaml:"target_label,omitempty"`
TargetLabel model.LabelName `yaml:"target_label,omitempty"`
// Replacement is the regex replacement pattern to be used.
Replacement string `yaml:"replacement,omitempty"`
// Action is the action to be performed for the relabeling.
Expand Down
22 changes: 11 additions & 11 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"gopkg.in/yaml.v2"

clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/common/model"
)

var expectedConf = &Config{
Expand All @@ -33,7 +33,7 @@ var expectedConf = &Config{
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
EvaluationInterval: Duration(30 * time.Second),

Labels: clientmodel.LabelSet{
Labels: model.LabelSet{
"monitor": "codelab",
"foo": "bar",
},
Expand All @@ -60,11 +60,11 @@ var expectedConf = &Config{

TargetGroups: []*TargetGroup{
{
Targets: []clientmodel.LabelSet{
{clientmodel.AddressLabel: "localhost:9090"},
{clientmodel.AddressLabel: "localhost:9191"},
Targets: []model.LabelSet{
{model.AddressLabel: "localhost:9090"},
{model.AddressLabel: "localhost:9191"},
},
Labels: clientmodel.LabelSet{
Labels: model.LabelSet{
"my": "label",
"your": "label",
},
Expand All @@ -84,7 +84,7 @@ var expectedConf = &Config{

RelabelConfigs: []*RelabelConfig{
{
SourceLabels: clientmodel.LabelNames{"job", "__meta_dns_srv_name"},
SourceLabels: model.LabelNames{"job", "__meta_dns_srv_name"},
TargetLabel: "job",
Separator: ";",
Regex: &Regexp{*regexp.MustCompile("(.*)some-[regex]$")},
Expand Down Expand Up @@ -126,28 +126,28 @@ var expectedConf = &Config{

RelabelConfigs: []*RelabelConfig{
{
SourceLabels: clientmodel.LabelNames{"job"},
SourceLabels: model.LabelNames{"job"},
Regex: &Regexp{*regexp.MustCompile("(.*)some-[regex]$")},
Separator: ";",
Action: RelabelDrop,
},
{
SourceLabels: clientmodel.LabelNames{"__address__"},
SourceLabels: model.LabelNames{"__address__"},
TargetLabel: "__tmp_hash",
Modulus: 8,
Separator: ";",
Action: RelabelHashMod,
},
{
SourceLabels: clientmodel.LabelNames{"__tmp_hash"},
SourceLabels: model.LabelNames{"__tmp_hash"},
Regex: &Regexp{*regexp.MustCompile("^1$")},
Separator: ";",
Action: RelabelKeep,
},
},
MetricRelabelConfigs: []*RelabelConfig{
{
SourceLabels: clientmodel.LabelNames{"__name__"},
SourceLabels: model.LabelNames{"__name__"},
Regex: &Regexp{*regexp.MustCompile("expensive_metric.*$")},
Separator: ";",
Action: RelabelDrop,
Expand Down
6 changes: 3 additions & 3 deletions notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"

clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/common/model"

"github.com/prometheus/prometheus/util/httputil"
)
Expand All @@ -51,9 +51,9 @@ type NotificationReq struct {
// A reference to the runbook for the alert.
Runbook string
// Labels associated with this alert notification, including alert name.
Labels clientmodel.LabelSet
Labels model.LabelSet
// Current value of alert
Value clientmodel.SampleValue
Value model.SampleValue
// Since when this alert has been active (pending or firing).
ActiveSince time.Time
// A textual representation of the rule that triggered the alert.
Expand Down
8 changes: 4 additions & 4 deletions notification/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"
"time"

clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/common/model"
)

type testHTTPPoster struct {
Expand Down Expand Up @@ -65,10 +65,10 @@ func (s *testNotificationScenario) test(i int, t *testing.T) {
Summary: s.summary,
Description: s.description,
Runbook: s.runbook,
Labels: clientmodel.LabelSet{
clientmodel.LabelName("instance"): clientmodel.LabelValue("testinstance"),
Labels: model.LabelSet{
model.LabelName("instance"): model.LabelValue("testinstance"),
},
Value: clientmodel.SampleValue(1.0 / 3.0),
Value: model.SampleValue(1.0 / 3.0),
ActiveSince: time.Time{},
RuleString: "Test rule string",
GeneratorURL: "prometheus_url",
Expand Down
16 changes: 8 additions & 8 deletions promql/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"golang.org/x/net/context"

clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/common/model"

"github.com/prometheus/prometheus/storage/local"
)
Expand All @@ -32,7 +32,7 @@ type Analyzer struct {
// The expression being analyzed.
Expr Expr
// The time range for evaluation of Expr.
Start, End clientmodel.Timestamp
Start, End model.Time

// The preload times for different query time offsets.
offsetPreloadTimes map[time.Duration]preloadTimes
Expand All @@ -45,11 +45,11 @@ type preloadTimes struct {
// Instants require single samples to be loaded along the entire query
// range, with intervals between the samples corresponding to the query
// resolution.
instants map[clientmodel.Fingerprint]struct{}
instants map[model.Fingerprint]struct{}
// Ranges require loading a range of samples at each resolution step,
// stretching backwards from the current evaluation timestamp. The length of
// the range into the past is given by the duration, as in "foo[5m]".
ranges map[clientmodel.Fingerprint]time.Duration
ranges map[model.Fingerprint]time.Duration
}

// Analyze the provided expression and attach metrics and fingerprints to data-selecting
Expand All @@ -60,8 +60,8 @@ func (a *Analyzer) Analyze(ctx context.Context) error {
getPreloadTimes := func(offset time.Duration) preloadTimes {
if _, ok := a.offsetPreloadTimes[offset]; !ok {
a.offsetPreloadTimes[offset] = preloadTimes{
instants: map[clientmodel.Fingerprint]struct{}{},
ranges: map[clientmodel.Fingerprint]time.Duration{},
instants: map[model.Fingerprint]struct{}{},
ranges: map[model.Fingerprint]time.Duration{},
}
}
return a.offsetPreloadTimes[offset]
Expand All @@ -73,7 +73,7 @@ func (a *Analyzer) Analyze(ctx context.Context) error {
switch n := node.(type) {
case *VectorSelector:
n.metrics = a.Storage.MetricsForLabelMatchers(n.LabelMatchers...)
n.iterators = make(map[clientmodel.Fingerprint]local.SeriesIterator, len(n.metrics))
n.iterators = make(map[model.Fingerprint]local.SeriesIterator, len(n.metrics))

pt := getPreloadTimes(n.Offset)
for fp := range n.metrics {
Expand All @@ -86,7 +86,7 @@ func (a *Analyzer) Analyze(ctx context.Context) error {
}
case *MatrixSelector:
n.metrics = a.Storage.MetricsForLabelMatchers(n.LabelMatchers...)
n.iterators = make(map[clientmodel.Fingerprint]local.SeriesIterator, len(n.metrics))
n.iterators = make(map[model.Fingerprint]local.SeriesIterator, len(n.metrics))

pt := getPreloadTimes(n.Offset)
for fp := range n.metrics {
Expand Down
30 changes: 15 additions & 15 deletions promql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"time"

clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/common/model"

"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/storage/metric"
Expand Down Expand Up @@ -59,7 +59,7 @@ type AlertStmt struct {
Name string
Expr Expr
Duration time.Duration
Labels clientmodel.LabelSet
Labels model.LabelSet
Summary string
Description string
Runbook string
Expand All @@ -72,7 +72,7 @@ type EvalStmt struct {

// The time boundaries for the evaluation. If Start equals End an instant
// is evaluated.
Start, End clientmodel.Timestamp
Start, End model.Time
// Time between two evaluated instants for the range [Start:End].
Interval time.Duration
}
Expand All @@ -81,7 +81,7 @@ type EvalStmt struct {
type RecordStmt struct {
Name string
Expr Expr
Labels clientmodel.LabelSet
Labels model.LabelSet
}

func (*AlertStmt) stmt() {}
Expand Down Expand Up @@ -136,10 +136,10 @@ type Expressions []Expr

// AggregateExpr represents an aggregation operation on a vector.
type AggregateExpr struct {
Op itemType // The used aggregation operation.
Expr Expr // The vector expression over which is aggregated.
Grouping clientmodel.LabelNames // The labels by which to group the vector.
KeepExtraLabels bool // Whether to keep extra labels common among result elements.
Op itemType // The used aggregation operation.
Expr Expr // The vector expression over which is aggregated.
Grouping model.LabelNames // The labels by which to group the vector.
KeepExtraLabels bool // Whether to keep extra labels common among result elements.
}

// BinaryExpr represents a binary expression between two child expressions.
Expand All @@ -166,13 +166,13 @@ type MatrixSelector struct {
LabelMatchers metric.LabelMatchers

// The series iterators are populated at query analysis time.
iterators map[clientmodel.Fingerprint]local.SeriesIterator
metrics map[clientmodel.Fingerprint]clientmodel.COWMetric
iterators map[model.Fingerprint]local.SeriesIterator
metrics map[model.Fingerprint]model.COWMetric
}

// NumberLiteral represents a number.
type NumberLiteral struct {
Val clientmodel.SampleValue
Val model.SampleValue
}

// ParenExpr wraps an expression so it cannot be disassembled as a consequence
Expand Down Expand Up @@ -200,8 +200,8 @@ type VectorSelector struct {
LabelMatchers metric.LabelMatchers

// The series iterators are populated at query analysis time.
iterators map[clientmodel.Fingerprint]local.SeriesIterator
metrics map[clientmodel.Fingerprint]clientmodel.COWMetric
iterators map[model.Fingerprint]local.SeriesIterator
metrics map[model.Fingerprint]model.COWMetric
}

func (e *AggregateExpr) Type() ExprType { return ExprVector }
Expand Down Expand Up @@ -262,10 +262,10 @@ type VectorMatching struct {
Card VectorMatchCardinality
// On contains the labels which define equality of a pair
// of elements from the vectors.
On clientmodel.LabelNames
On model.LabelNames
// Include contains additional labels that should be included in
// the result from the side with the higher cardinality.
Include clientmodel.LabelNames
Include model.LabelNames
}

// A Visitor's Visit method is invoked for each node encountered by Walk.
Expand Down
Loading

0 comments on commit 306e846

Please sign in to comment.