mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 22:07:27 -08:00
Fix most golint warnings.
This is with `golint -min_confidence=0.5`. I left several lint warnings untouched because they were either incorrect or I felt it was better not to change them at the moment.
This commit is contained in:
parent
6664b77f36
commit
995d3b831d
|
@ -46,6 +46,7 @@ func main() {
|
||||||
os.Exit(Main())
|
os.Exit(Main())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main manages the startup and shutdown lifecycle of the entire Prometheus server.
|
||||||
func Main() int {
|
func Main() int {
|
||||||
if err := parse(os.Args[1:]); err != nil {
|
if err := parse(os.Args[1:]); err != nil {
|
||||||
return 2
|
return 2
|
||||||
|
|
|
@ -68,19 +68,19 @@ func LoadFile(filename string) (*Config, error) {
|
||||||
|
|
||||||
// The defaults applied before parsing the respective config sections.
|
// The defaults applied before parsing the respective config sections.
|
||||||
var (
|
var (
|
||||||
// The default top-level configuration.
|
// DefaultConfig is the default top-level configuration.
|
||||||
DefaultConfig = Config{
|
DefaultConfig = Config{
|
||||||
GlobalConfig: DefaultGlobalConfig,
|
GlobalConfig: DefaultGlobalConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default global configuration.
|
// DefaultGlobalConfig is the default global configuration.
|
||||||
DefaultGlobalConfig = GlobalConfig{
|
DefaultGlobalConfig = GlobalConfig{
|
||||||
ScrapeInterval: Duration(1 * time.Minute),
|
ScrapeInterval: Duration(1 * time.Minute),
|
||||||
ScrapeTimeout: Duration(10 * time.Second),
|
ScrapeTimeout: Duration(10 * time.Second),
|
||||||
EvaluationInterval: Duration(1 * time.Minute),
|
EvaluationInterval: Duration(1 * time.Minute),
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default scrape configuration.
|
// DefaultScrapeConfig is the default scrape configuration.
|
||||||
DefaultScrapeConfig = ScrapeConfig{
|
DefaultScrapeConfig = ScrapeConfig{
|
||||||
// ScrapeTimeout and ScrapeInterval default to the
|
// ScrapeTimeout and ScrapeInterval default to the
|
||||||
// configured globals.
|
// configured globals.
|
||||||
|
@ -89,30 +89,30 @@ var (
|
||||||
HonorLabels: false,
|
HonorLabels: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default Relabel configuration.
|
// DefaultRelabelConfig is the default Relabel configuration.
|
||||||
DefaultRelabelConfig = RelabelConfig{
|
DefaultRelabelConfig = RelabelConfig{
|
||||||
Action: RelabelReplace,
|
Action: RelabelReplace,
|
||||||
Separator: ";",
|
Separator: ";",
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default DNS SD configuration.
|
// DefaultDNSSDConfig is the default DNS SD configuration.
|
||||||
DefaultDNSSDConfig = DNSSDConfig{
|
DefaultDNSSDConfig = DNSSDConfig{
|
||||||
RefreshInterval: Duration(30 * time.Second),
|
RefreshInterval: Duration(30 * time.Second),
|
||||||
Type: "SRV",
|
Type: "SRV",
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default file SD configuration.
|
// DefaultFileSDConfig is the default file SD configuration.
|
||||||
DefaultFileSDConfig = FileSDConfig{
|
DefaultFileSDConfig = FileSDConfig{
|
||||||
RefreshInterval: Duration(5 * time.Minute),
|
RefreshInterval: Duration(5 * time.Minute),
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default Consul SD configuration.
|
// DefaultConsulSDConfig is the default Consul SD configuration.
|
||||||
DefaultConsulSDConfig = ConsulSDConfig{
|
DefaultConsulSDConfig = ConsulSDConfig{
|
||||||
TagSeparator: ",",
|
TagSeparator: ",",
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default Serverset SD configuration.
|
// DefaultServersetSDConfig is the default Serverset SD configuration.
|
||||||
DefaultServersetSDConfig = ServersetSDConfig{
|
DefaultServersetSDConfig = ServersetSDConfig{
|
||||||
Timeout: Duration(10 * time.Second),
|
Timeout: Duration(10 * time.Second),
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ var (
|
||||||
RefreshInterval: Duration(30 * time.Second),
|
RefreshInterval: Duration(30 * time.Second),
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default Kubernetes SD configuration
|
// DefaultKubernetesSDConfig is the default Kubernetes SD configuration
|
||||||
DefaultKubernetesSDConfig = KubernetesSDConfig{
|
DefaultKubernetesSDConfig = KubernetesSDConfig{
|
||||||
KubeletPort: 10255,
|
KubeletPort: 10255,
|
||||||
RequestTimeout: Duration(10 * time.Second),
|
RequestTimeout: Duration(10 * time.Second),
|
||||||
|
@ -130,7 +130,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// This custom URL type allows validating at configuration load time.
|
// URL is a custom URL type that allows validation at configuration load time.
|
||||||
type URL struct {
|
type URL struct {
|
||||||
*url.URL
|
*url.URL
|
||||||
}
|
}
|
||||||
|
@ -633,6 +633,7 @@ func (c *MarathonSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro
|
||||||
return checkOverflow(c.XXX, "marathon_sd_config")
|
return checkOverflow(c.XXX, "marathon_sd_config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
||||||
func (c *KubernetesSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (c *KubernetesSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
*c = DefaultKubernetesSDConfig
|
*c = DefaultKubernetesSDConfig
|
||||||
type plain KubernetesSDConfig
|
type plain KubernetesSDConfig
|
||||||
|
@ -655,15 +656,15 @@ func (c *KubernetesSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
|
||||||
type RelabelAction string
|
type RelabelAction string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Performs a regex replacement.
|
// RelabelReplace performs a regex replacement.
|
||||||
RelabelReplace RelabelAction = "replace"
|
RelabelReplace RelabelAction = "replace"
|
||||||
// Drops targets for which the input does not match the regex.
|
// RelabelKeep drops targets for which the input does not match the regex.
|
||||||
RelabelKeep RelabelAction = "keep"
|
RelabelKeep RelabelAction = "keep"
|
||||||
// Drops targets for which the input does match the regex.
|
// RelabelDrop drops targets for which the input does match the regex.
|
||||||
RelabelDrop RelabelAction = "drop"
|
RelabelDrop RelabelAction = "drop"
|
||||||
// Sets a label to the modulus of a hash of labels.
|
// RelabelHashMod sets a label to the modulus of a hash of labels.
|
||||||
RelabelHashMod RelabelAction = "hashmod"
|
RelabelHashMod RelabelAction = "hashmod"
|
||||||
// Copy labels to other labelnames based on a regex.
|
// RelabelLabelMap copies labels to other labelnames based on a regex.
|
||||||
RelabelLabelMap RelabelAction = "labelmap"
|
RelabelLabelMap RelabelAction = "labelmap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -179,7 +179,6 @@ func (e *ParenExpr) Type() model.ValueType { return e.Expr.Type() }
|
||||||
func (e *StringLiteral) Type() model.ValueType { return model.ValString }
|
func (e *StringLiteral) Type() model.ValueType { return model.ValString }
|
||||||
func (e *UnaryExpr) Type() model.ValueType { return e.Expr.Type() }
|
func (e *UnaryExpr) Type() model.ValueType { return e.Expr.Type() }
|
||||||
func (e *VectorSelector) Type() model.ValueType { return model.ValVector }
|
func (e *VectorSelector) Type() model.ValueType { return model.ValVector }
|
||||||
|
|
||||||
func (e *BinaryExpr) Type() model.ValueType {
|
func (e *BinaryExpr) Type() model.ValueType {
|
||||||
if e.LHS.Type() == model.ValScalar && e.RHS.Type() == model.ValScalar {
|
if e.LHS.Type() == model.ValScalar && e.RHS.Type() == model.ValScalar {
|
||||||
return model.ValScalar
|
return model.ValScalar
|
||||||
|
@ -197,7 +196,7 @@ func (*StringLiteral) expr() {}
|
||||||
func (*UnaryExpr) expr() {}
|
func (*UnaryExpr) expr() {}
|
||||||
func (*VectorSelector) expr() {}
|
func (*VectorSelector) expr() {}
|
||||||
|
|
||||||
// VectorMatchCardinaly describes the cardinality relationship
|
// VectorMatchCardinality describes the cardinality relationship
|
||||||
// of two vectors in a binary operation.
|
// of two vectors in a binary operation.
|
||||||
type VectorMatchCardinality int
|
type VectorMatchCardinality int
|
||||||
|
|
||||||
|
@ -235,9 +234,10 @@ type VectorMatching struct {
|
||||||
Include model.LabelNames
|
Include model.LabelNames
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Visitor's Visit method is invoked for each node encountered by Walk.
|
// Visitor allows visiting a Node and its child nodes. The Visit method is
|
||||||
// If the result visitor w is not nil, Walk visits each of the children
|
// invoked for each node encountered by Walk. If the result visitor w is not
|
||||||
// of node with the visitor w, followed by a call of w.Visit(nil).
|
// nil, Walk visits each of the children of node with the visitor w, followed
|
||||||
|
// by a call of w.Visit(nil).
|
||||||
type Visitor interface {
|
type Visitor interface {
|
||||||
Visit(node Node) (w Visitor)
|
Visit(node Node) (w Visitor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,11 +225,11 @@ func init() {
|
||||||
key["nan"] = itemNumber
|
key["nan"] = itemNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t itemType) String() string {
|
func (i itemType) String() string {
|
||||||
if s, ok := itemTypeStr[t]; ok {
|
if s, ok := itemTypeStr[i]; ok {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("<item %d>", t)
|
return fmt.Sprintf("<item %d>", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i item) desc() string {
|
func (i item) desc() string {
|
||||||
|
@ -242,8 +242,8 @@ func (i item) desc() string {
|
||||||
return fmt.Sprintf("%s %s", i.typ.desc(), i)
|
return fmt.Sprintf("%s %s", i.typ.desc(), i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t itemType) desc() string {
|
func (i itemType) desc() string {
|
||||||
switch t {
|
switch i {
|
||||||
case itemError:
|
case itemError:
|
||||||
return "error"
|
return "error"
|
||||||
case itemEOF:
|
case itemEOF:
|
||||||
|
@ -261,7 +261,7 @@ func (t itemType) desc() string {
|
||||||
case itemDuration:
|
case itemDuration:
|
||||||
return "duration"
|
return "duration"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%q", t)
|
return fmt.Sprintf("%q", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
const eof = -1
|
const eof = -1
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestEvaluations(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for _, fn := range files {
|
for _, fn := range files {
|
||||||
test, err := NewTestFromFile(t, fn)
|
test, err := newTestFromFile(t, fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error creating test for %s: %s", fn, err)
|
t.Errorf("error creating test for %s: %s", fn, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ func NewTest(t testutil.T, input string) (*Test, error) {
|
||||||
return test, err
|
return test, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestFromFile(t testutil.T, filename string) (*Test, error) {
|
func newTestFromFile(t testutil.T, filename string) (*Test, error) {
|
||||||
content, err := ioutil.ReadFile(filename)
|
content, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -477,6 +477,7 @@ func (t *Test) clear() {
|
||||||
t.queryEngine = NewEngine(t.storage, nil)
|
t.queryEngine = NewEngine(t.storage, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes resources associated with the Test.
|
||||||
func (t *Test) Close() {
|
func (t *Test) Close() {
|
||||||
t.queryEngine.Stop()
|
t.queryEngine.Stop()
|
||||||
t.closeStorage()
|
t.closeStorage()
|
||||||
|
|
|
@ -32,22 +32,22 @@ const (
|
||||||
consulWatchTimeout = 30 * time.Second
|
consulWatchTimeout = 30 * time.Second
|
||||||
consulRetryInterval = 15 * time.Second
|
consulRetryInterval = 15 * time.Second
|
||||||
|
|
||||||
// ConsuleAddressLabel is the name for the label containing a target's address.
|
// consulAddressLabel is the name for the label containing a target's address.
|
||||||
ConsulAddressLabel = model.MetaLabelPrefix + "consul_address"
|
consulAddressLabel = model.MetaLabelPrefix + "consul_address"
|
||||||
// ConsuleNodeLabel is the name for the label containing a target's node name.
|
// consulNodeLabel is the name for the label containing a target's node name.
|
||||||
ConsulNodeLabel = model.MetaLabelPrefix + "consul_node"
|
consulNodeLabel = model.MetaLabelPrefix + "consul_node"
|
||||||
// ConsulTagsLabel is the name of the label containing the tags assigned to the target.
|
// consulTagsLabel is the name of the label containing the tags assigned to the target.
|
||||||
ConsulTagsLabel = model.MetaLabelPrefix + "consul_tags"
|
consulTagsLabel = model.MetaLabelPrefix + "consul_tags"
|
||||||
// ConsulServiceLabel is the name of the label containing the service name.
|
// consulServiceLabel is the name of the label containing the service name.
|
||||||
ConsulServiceLabel = model.MetaLabelPrefix + "consul_service"
|
consulServiceLabel = model.MetaLabelPrefix + "consul_service"
|
||||||
// ConsulServiceAddressLabel is the name of the label containing the (optional) service address.
|
// consulServiceAddressLabel is the name of the label containing the (optional) service address.
|
||||||
ConsulServiceAddressLabel = model.MetaLabelPrefix + "consul_service_address"
|
consulServiceAddressLabel = model.MetaLabelPrefix + "consul_service_address"
|
||||||
// ConsulServicePortLabel is the name of the label containing the service port.
|
// consulServicePortLabel is the name of the label containing the service port.
|
||||||
ConsulServicePortLabel = model.MetaLabelPrefix + "consul_service_port"
|
consulServicePortLabel = model.MetaLabelPrefix + "consul_service_port"
|
||||||
// ConsulDCLabel is the name of the label containing the datacenter ID.
|
// consulDCLabel is the name of the label containing the datacenter ID.
|
||||||
ConsulDCLabel = model.MetaLabelPrefix + "consul_dc"
|
consulDCLabel = model.MetaLabelPrefix + "consul_dc"
|
||||||
// ConsulServiceIDLabel is the name of the label containing the service ID.
|
// consulServiceIDLabel is the name of the label containing the service ID.
|
||||||
ConsulServiceIDLabel = model.MetaLabelPrefix + "consul_service_id"
|
consulServiceIDLabel = model.MetaLabelPrefix + "consul_service_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConsulDiscovery retrieves target information from a Consul server
|
// ConsulDiscovery retrieves target information from a Consul server
|
||||||
|
@ -226,8 +226,8 @@ func (cd *ConsulDiscovery) watchServices(update chan<- *consulService, done <-ch
|
||||||
cd.services[name] = srv
|
cd.services[name] = srv
|
||||||
}
|
}
|
||||||
srv.tgroup.Labels = model.LabelSet{
|
srv.tgroup.Labels = model.LabelSet{
|
||||||
ConsulServiceLabel: model.LabelValue(name),
|
consulServiceLabel: model.LabelValue(name),
|
||||||
ConsulDCLabel: model.LabelValue(cd.clientDatacenter),
|
consulDCLabel: model.LabelValue(cd.clientDatacenter),
|
||||||
}
|
}
|
||||||
update <- srv
|
update <- srv
|
||||||
}
|
}
|
||||||
|
@ -272,12 +272,12 @@ func (cd *ConsulDiscovery) watchService(srv *consulService, ch chan<- *config.Ta
|
||||||
|
|
||||||
srv.tgroup.Targets = append(srv.tgroup.Targets, model.LabelSet{
|
srv.tgroup.Targets = append(srv.tgroup.Targets, model.LabelSet{
|
||||||
model.AddressLabel: model.LabelValue(addr),
|
model.AddressLabel: model.LabelValue(addr),
|
||||||
ConsulAddressLabel: model.LabelValue(node.Address),
|
consulAddressLabel: model.LabelValue(node.Address),
|
||||||
ConsulNodeLabel: model.LabelValue(node.Node),
|
consulNodeLabel: model.LabelValue(node.Node),
|
||||||
ConsulTagsLabel: model.LabelValue(tags),
|
consulTagsLabel: model.LabelValue(tags),
|
||||||
ConsulServiceAddressLabel: model.LabelValue(node.ServiceAddress),
|
consulServiceAddressLabel: model.LabelValue(node.ServiceAddress),
|
||||||
ConsulServicePortLabel: model.LabelValue(strconv.Itoa(node.ServicePort)),
|
consulServicePortLabel: model.LabelValue(strconv.Itoa(node.ServicePort)),
|
||||||
ConsulServiceIDLabel: model.LabelValue(node.ServiceID),
|
consulServiceIDLabel: model.LabelValue(node.ServiceID),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import (
|
||||||
const (
|
const (
|
||||||
resolvConf = "/etc/resolv.conf"
|
resolvConf = "/etc/resolv.conf"
|
||||||
|
|
||||||
DNSNameLabel = model.MetaLabelPrefix + "dns_name"
|
dnsNameLabel = model.MetaLabelPrefix + "dns_name"
|
||||||
|
|
||||||
// Constants for instrumentation.
|
// Constants for instrumentation.
|
||||||
namespace = "prometheus"
|
namespace = "prometheus"
|
||||||
|
@ -161,7 +161,7 @@ func (dd *DNSDiscovery) refresh(name string, ch chan<- *config.TargetGroup) erro
|
||||||
}
|
}
|
||||||
tg.Targets = append(tg.Targets, model.LabelSet{
|
tg.Targets = append(tg.Targets, model.LabelSet{
|
||||||
model.AddressLabel: target,
|
model.AddressLabel: target,
|
||||||
DNSNameLabel: model.LabelValue(name),
|
dnsNameLabel: model.LabelValue(name),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import (
|
||||||
"github.com/prometheus/prometheus/config"
|
"github.com/prometheus/prometheus/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const FileSDFilepathLabel = model.MetaLabelPrefix + "filepath"
|
const fileSDFilepathLabel = model.MetaLabelPrefix + "filepath"
|
||||||
|
|
||||||
// FileDiscovery provides service discovery functionality based
|
// FileDiscovery provides service discovery functionality based
|
||||||
// on files that contain target groups in JSON or YAML format. Refreshing
|
// on files that contain target groups in JSON or YAML format. Refreshing
|
||||||
|
@ -245,7 +245,7 @@ func readFile(filename string) ([]*config.TargetGroup, error) {
|
||||||
if tg.Labels == nil {
|
if tg.Labels == nil {
|
||||||
tg.Labels = model.LabelSet{}
|
tg.Labels = model.LabelSet{}
|
||||||
}
|
}
|
||||||
tg.Labels[FileSDFilepathLabel] = model.LabelValue(filename)
|
tg.Labels[fileSDFilepathLabel] = model.LabelValue(filename)
|
||||||
}
|
}
|
||||||
return targetGroups, nil
|
return targetGroups, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@ import (
|
||||||
"github.com/prometheus/prometheus/retrieval/discovery/kubernetes"
|
"github.com/prometheus/prometheus/retrieval/discovery/kubernetes"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewKubernetesDiscovery(conf *config.KubernetesSDConfig) (*kubernetes.KubernetesDiscovery, error) {
|
// NewKubernetesDiscovery creates a Kubernetes service discovery based on the passed-in configuration.
|
||||||
kd := &kubernetes.KubernetesDiscovery{
|
func NewKubernetesDiscovery(conf *config.KubernetesSDConfig) (*kubernetes.Discovery, error) {
|
||||||
|
kd := &kubernetes.Discovery{
|
||||||
Conf: conf,
|
Conf: conf,
|
||||||
}
|
}
|
||||||
err := kd.Initialize()
|
err := kd.Initialize()
|
||||||
|
|
|
@ -65,8 +65,8 @@ const (
|
||||||
serviceEndpointsURL = apiPrefix + "/namespaces/%s/endpoints/%s"
|
serviceEndpointsURL = apiPrefix + "/namespaces/%s/endpoints/%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KubernetesDiscovery implements a TargetProvider for Kubernetes services.
|
// Discovery implements a TargetProvider for Kubernetes services.
|
||||||
type KubernetesDiscovery struct {
|
type Discovery struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
Conf *config.KubernetesSDConfig
|
Conf *config.KubernetesSDConfig
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ type KubernetesDiscovery struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize sets up the discovery for usage.
|
// Initialize sets up the discovery for usage.
|
||||||
func (kd *KubernetesDiscovery) Initialize() error {
|
func (kd *Discovery) Initialize() error {
|
||||||
client, err := newKubernetesHTTPClient(kd.Conf)
|
client, err := newKubernetesHTTPClient(kd.Conf)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -97,7 +97,7 @@ func (kd *KubernetesDiscovery) Initialize() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sources implements the TargetProvider interface.
|
// Sources implements the TargetProvider interface.
|
||||||
func (kd *KubernetesDiscovery) Sources() []string {
|
func (kd *Discovery) Sources() []string {
|
||||||
res, err := kd.client.Get(kd.Conf.Server + nodesURL)
|
res, err := kd.client.Get(kd.Conf.Server + nodesURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If we can't list nodes then we can't watch them. Assume this is a misconfiguration
|
// If we can't list nodes then we can't watch them. Assume this is a misconfiguration
|
||||||
|
@ -163,7 +163,7 @@ func (kd *KubernetesDiscovery) Sources() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run implements the TargetProvider interface.
|
// Run implements the TargetProvider interface.
|
||||||
func (kd *KubernetesDiscovery) Run(ch chan<- *config.TargetGroup, done <-chan struct{}) {
|
func (kd *Discovery) Run(ch chan<- *config.TargetGroup, done <-chan struct{}) {
|
||||||
defer close(ch)
|
defer close(ch)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@ -215,7 +215,7 @@ func (kd *KubernetesDiscovery) Run(ch chan<- *config.TargetGroup, done <-chan st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kd *KubernetesDiscovery) updateNodesTargetGroup() *config.TargetGroup {
|
func (kd *Discovery) updateNodesTargetGroup() *config.TargetGroup {
|
||||||
kd.nodesMu.Lock()
|
kd.nodesMu.Lock()
|
||||||
defer kd.nodesMu.Unlock()
|
defer kd.nodesMu.Unlock()
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ func (kd *KubernetesDiscovery) updateNodesTargetGroup() *config.TargetGroup {
|
||||||
return tg
|
return tg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kd *KubernetesDiscovery) updateNode(node *Node, eventType EventType) {
|
func (kd *Discovery) updateNode(node *Node, eventType EventType) {
|
||||||
kd.nodesMu.Lock()
|
kd.nodesMu.Lock()
|
||||||
defer kd.nodesMu.Unlock()
|
defer kd.nodesMu.Unlock()
|
||||||
updatedNodeName := node.ObjectMeta.Name
|
updatedNodeName := node.ObjectMeta.Name
|
||||||
|
@ -254,7 +254,7 @@ func (kd *KubernetesDiscovery) updateNode(node *Node, eventType EventType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// watchNodes watches nodes as they come & go.
|
// watchNodes watches nodes as they come & go.
|
||||||
func (kd *KubernetesDiscovery) watchNodes(events chan interface{}, done <-chan struct{}, retryInterval time.Duration) {
|
func (kd *Discovery) watchNodes(events chan interface{}, done <-chan struct{}, retryInterval time.Duration) {
|
||||||
until(func() {
|
until(func() {
|
||||||
req, err := http.NewRequest("GET", kd.Conf.Server+nodesURL, nil)
|
req, err := http.NewRequest("GET", kd.Conf.Server+nodesURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -294,7 +294,7 @@ func (kd *KubernetesDiscovery) watchNodes(events chan interface{}, done <-chan s
|
||||||
}
|
}
|
||||||
|
|
||||||
// watchServices watches services as they come & go.
|
// watchServices watches services as they come & go.
|
||||||
func (kd *KubernetesDiscovery) watchServices(events chan interface{}, done <-chan struct{}, retryInterval time.Duration) {
|
func (kd *Discovery) watchServices(events chan interface{}, done <-chan struct{}, retryInterval time.Duration) {
|
||||||
until(func() {
|
until(func() {
|
||||||
req, err := http.NewRequest("GET", kd.Conf.Server+servicesURL, nil)
|
req, err := http.NewRequest("GET", kd.Conf.Server+servicesURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -334,7 +334,7 @@ func (kd *KubernetesDiscovery) watchServices(events chan interface{}, done <-cha
|
||||||
}, retryInterval, done)
|
}, retryInterval, done)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kd *KubernetesDiscovery) updateService(service *Service, eventType EventType) *config.TargetGroup {
|
func (kd *Discovery) updateService(service *Service, eventType EventType) *config.TargetGroup {
|
||||||
kd.servicesMu.Lock()
|
kd.servicesMu.Lock()
|
||||||
defer kd.servicesMu.Unlock()
|
defer kd.servicesMu.Unlock()
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ func (kd *KubernetesDiscovery) updateService(service *Service, eventType EventTy
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kd *KubernetesDiscovery) deleteService(service *Service) *config.TargetGroup {
|
func (kd *Discovery) deleteService(service *Service) *config.TargetGroup {
|
||||||
tg := &config.TargetGroup{Source: serviceSource(service)}
|
tg := &config.TargetGroup{Source: serviceSource(service)}
|
||||||
|
|
||||||
delete(kd.services[service.ObjectMeta.Namespace], service.ObjectMeta.Name)
|
delete(kd.services[service.ObjectMeta.Namespace], service.ObjectMeta.Name)
|
||||||
|
@ -366,7 +366,7 @@ func (kd *KubernetesDiscovery) deleteService(service *Service) *config.TargetGro
|
||||||
return tg
|
return tg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kd *KubernetesDiscovery) addService(service *Service) *config.TargetGroup {
|
func (kd *Discovery) addService(service *Service) *config.TargetGroup {
|
||||||
namespace, ok := kd.services[service.ObjectMeta.Namespace]
|
namespace, ok := kd.services[service.ObjectMeta.Namespace]
|
||||||
if !ok {
|
if !ok {
|
||||||
namespace = map[string]*Service{}
|
namespace = map[string]*Service{}
|
||||||
|
@ -386,16 +386,16 @@ func (kd *KubernetesDiscovery) addService(service *Service) *config.TargetGroup
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var endpoints Endpoints
|
var eps Endpoints
|
||||||
if err := json.NewDecoder(res.Body).Decode(&endpoints); err != nil {
|
if err := json.NewDecoder(res.Body).Decode(&eps); err != nil {
|
||||||
log.Errorf("Error getting service endpoints: %s", err)
|
log.Errorf("Error getting service endpoints: %s", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return kd.updateServiceTargetGroup(service, &endpoints)
|
return kd.updateServiceTargetGroup(service, &eps)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kd *KubernetesDiscovery) updateServiceTargetGroup(service *Service, endpoints *Endpoints) *config.TargetGroup {
|
func (kd *Discovery) updateServiceTargetGroup(service *Service, eps *Endpoints) *config.TargetGroup {
|
||||||
tg := &config.TargetGroup{
|
tg := &config.TargetGroup{
|
||||||
Source: serviceSource(service),
|
Source: serviceSource(service),
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
|
@ -415,10 +415,10 @@ func (kd *KubernetesDiscovery) updateServiceTargetGroup(service *Service, endpoi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now let's loop through the endpoints & add them to the target group with appropriate labels.
|
// Now let's loop through the endpoints & add them to the target group with appropriate labels.
|
||||||
for _, eps := range endpoints.Subsets {
|
for _, ss := range eps.Subsets {
|
||||||
epPort := eps.Ports[0].Port
|
epPort := ss.Ports[0].Port
|
||||||
|
|
||||||
for _, addr := range eps.Addresses {
|
for _, addr := range ss.Addresses {
|
||||||
ipAddr := addr.IP
|
ipAddr := addr.IP
|
||||||
if len(ipAddr) == net.IPv6len {
|
if len(ipAddr) == net.IPv6len {
|
||||||
ipAddr = "[" + ipAddr + "]"
|
ipAddr = "[" + ipAddr + "]"
|
||||||
|
@ -435,7 +435,7 @@ func (kd *KubernetesDiscovery) updateServiceTargetGroup(service *Service, endpoi
|
||||||
}
|
}
|
||||||
|
|
||||||
// watchServiceEndpoints watches service endpoints as they come & go.
|
// watchServiceEndpoints watches service endpoints as they come & go.
|
||||||
func (kd *KubernetesDiscovery) watchServiceEndpoints(events chan interface{}, done <-chan struct{}, retryInterval time.Duration) {
|
func (kd *Discovery) watchServiceEndpoints(events chan interface{}, done <-chan struct{}, retryInterval time.Duration) {
|
||||||
until(func() {
|
until(func() {
|
||||||
req, err := http.NewRequest("GET", kd.Conf.Server+endpointsURL, nil)
|
req, err := http.NewRequest("GET", kd.Conf.Server+endpointsURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -475,7 +475,7 @@ func (kd *KubernetesDiscovery) watchServiceEndpoints(events chan interface{}, do
|
||||||
}, retryInterval, done)
|
}, retryInterval, done)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kd *KubernetesDiscovery) updateServiceEndpoints(endpoints *Endpoints, eventType EventType) *config.TargetGroup {
|
func (kd *Discovery) updateServiceEndpoints(endpoints *Endpoints, eventType EventType) *config.TargetGroup {
|
||||||
kd.servicesMu.Lock()
|
kd.servicesMu.Lock()
|
||||||
defer kd.servicesMu.Unlock()
|
defer kd.servicesMu.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,11 @@ type serversetEndpoint struct {
|
||||||
Port int
|
Port int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ZookeeperLogger struct {
|
type zookeeperLogger struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements zk.Logger
|
// Implements zk.Logger
|
||||||
func (zl ZookeeperLogger) Printf(s string, i ...interface{}) {
|
func (zl zookeeperLogger) Printf(s string, i ...interface{}) {
|
||||||
log.Infof(s, i...)
|
log.Infof(s, i...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ type ServersetDiscovery struct {
|
||||||
// NewServersetDiscovery returns a new ServersetDiscovery for the given config.
|
// NewServersetDiscovery returns a new ServersetDiscovery for the given config.
|
||||||
func NewServersetDiscovery(conf *config.ServersetSDConfig) *ServersetDiscovery {
|
func NewServersetDiscovery(conf *config.ServersetSDConfig) *ServersetDiscovery {
|
||||||
conn, _, err := zk.Connect(conf.Servers, time.Duration(conf.Timeout))
|
conn, _, err := zk.Connect(conf.Servers, time.Duration(conf.Timeout))
|
||||||
conn.SetLogger(ZookeeperLogger{})
|
conn.SetLogger(zookeeperLogger{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ func NewServersetDiscovery(conf *config.ServersetSDConfig) *ServersetDiscovery {
|
||||||
sources: map[string]*config.TargetGroup{},
|
sources: map[string]*config.TargetGroup{},
|
||||||
}
|
}
|
||||||
go sd.processUpdates()
|
go sd.processUpdates()
|
||||||
sd.treeCache = NewZookeeperTreeCache(conn, conf.Paths[0], updates)
|
sd.treeCache = newZookeeperTreeCache(conn, conf.Paths[0], updates)
|
||||||
return sd
|
return sd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ type zookeeperTreeCacheNode struct {
|
||||||
children map[string]*zookeeperTreeCacheNode
|
children map[string]*zookeeperTreeCacheNode
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewZookeeperTreeCache(conn *zk.Conn, path string, events chan zookeeperTreeCacheEvent) *zookeeperTreeCache {
|
func newZookeeperTreeCache(conn *zk.Conn, path string, events chan zookeeperTreeCacheEvent) *zookeeperTreeCache {
|
||||||
tc := &zookeeperTreeCache{
|
tc := &zookeeperTreeCache{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
prefix: path,
|
prefix: path,
|
||||||
|
|
|
@ -90,11 +90,11 @@ func (t TargetHealth) value() model.SampleValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Unknown is the state of a Target before it is first scraped.
|
// HealthUnknown is the state of a Target before it is first scraped.
|
||||||
HealthUnknown TargetHealth = iota
|
HealthUnknown TargetHealth = iota
|
||||||
// Healthy is the state of a Target that has been successfully scraped.
|
// HealthGood is the state of a Target that has been successfully scraped.
|
||||||
HealthGood
|
HealthGood
|
||||||
// Unhealthy is the state of a Target that was scraped unsuccessfully.
|
// HealthBad is the state of a Target that was scraped unsuccessfully.
|
||||||
HealthBad
|
HealthBad
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ func newHTTPClient(cfg *config.ScrapeConfig) (*http.Client, error) {
|
||||||
// Load CA cert.
|
// Load CA cert.
|
||||||
caCert, err := ioutil.ReadFile(cfg.CACert)
|
caCert, err := ioutil.ReadFile(cfg.CACert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to use specified CA cert %s: %s", cfg.CACert, err)
|
return nil, fmt.Errorf("unable to use specified CA cert %s: %s", cfg.CACert, err)
|
||||||
}
|
}
|
||||||
caCertPool.AppendCertsFromPEM(caCert)
|
caCertPool.AppendCertsFromPEM(caCert)
|
||||||
tlsConfig.RootCAs = caCertPool
|
tlsConfig.RootCAs = caCertPool
|
||||||
|
@ -268,7 +268,7 @@ func newHTTPClient(cfg *config.ScrapeConfig) (*http.Client, error) {
|
||||||
if cfg.ClientCert != nil && len(cfg.ClientCert.Cert) > 0 && len(cfg.ClientCert.Key) > 0 {
|
if cfg.ClientCert != nil && len(cfg.ClientCert.Cert) > 0 && len(cfg.ClientCert.Key) > 0 {
|
||||||
cert, err := tls.LoadX509KeyPair(cfg.ClientCert.Cert, cfg.ClientCert.Key)
|
cert, err := tls.LoadX509KeyPair(cfg.ClientCert.Cert, cfg.ClientCert.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to use specified client cert (%s) & key (%s): %s", cfg.ClientCert.Cert, cfg.ClientCert.Key, err)
|
return nil, fmt.Errorf("unable to use specified client cert (%s) & key (%s): %s", cfg.ClientCert.Cert, cfg.ClientCert.Key, err)
|
||||||
}
|
}
|
||||||
tlsConfig.Certificates = []tls.Certificate{cert}
|
tlsConfig.Certificates = []tls.Certificate{cert}
|
||||||
}
|
}
|
||||||
|
@ -285,12 +285,13 @@ func newHTTPClient(cfg *config.ScrapeConfig) (*http.Client, error) {
|
||||||
// Authorization header correctly on each request.
|
// Authorization header correctly on each request.
|
||||||
bearerToken := cfg.BearerToken
|
bearerToken := cfg.BearerToken
|
||||||
if len(bearerToken) == 0 && len(cfg.BearerTokenFile) > 0 {
|
if len(bearerToken) == 0 && len(cfg.BearerTokenFile) > 0 {
|
||||||
if b, err := ioutil.ReadFile(cfg.BearerTokenFile); err != nil {
|
b, err := ioutil.ReadFile(cfg.BearerTokenFile)
|
||||||
return nil, fmt.Errorf("Unable to read bearer token file %s: %s", cfg.BearerTokenFile, err)
|
if err != nil {
|
||||||
} else {
|
return nil, fmt.Errorf("unable to read bearer token file %s: %s", cfg.BearerTokenFile, err)
|
||||||
|
}
|
||||||
bearerToken = string(b)
|
bearerToken = string(b)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if len(bearerToken) > 0 {
|
if len(bearerToken) > 0 {
|
||||||
rt = httputil.NewBearerAuthRoundTripper(bearerToken, rt)
|
rt = httputil.NewBearerAuthRoundTripper(bearerToken, rt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -550,7 +550,7 @@ func (sd *StaticProvider) Run(ch chan<- *config.TargetGroup, done <-chan struct{
|
||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
// TargetGroups returns the provider's target groups.
|
// Sources returns the provider's sources.
|
||||||
func (sd *StaticProvider) Sources() (srcs []string) {
|
func (sd *StaticProvider) Sources() (srcs []string) {
|
||||||
for _, tg := range sd.TargetGroups {
|
for _, tg := range sd.TargetGroups {
|
||||||
srcs = append(srcs, tg.Source)
|
srcs = append(srcs, tg.Source)
|
||||||
|
|
|
@ -52,13 +52,13 @@ func (s AlertState) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Inactive alerts are neither firing nor pending.
|
// StateInactive is the state of an alert that is either firing nor pending.
|
||||||
StateInactive AlertState = iota
|
StateInactive AlertState = iota
|
||||||
// Pending alerts have been active for less than the configured
|
// StatePending is the state of an alert that has been active for less than
|
||||||
// threshold duration.
|
// the configured threshold duration.
|
||||||
StatePending
|
StatePending
|
||||||
// Firing alerts have been active for longer than the configured
|
// StateFiring is the state of an alert that has been active for longer than
|
||||||
// threshold duration.
|
// the configured threshold duration.
|
||||||
StateFiring
|
StateFiring
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -269,7 +269,7 @@ func (m *Manager) runIteration() {
|
||||||
float64(duration / time.Millisecond),
|
float64(duration / time.Millisecond),
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("Unknown rule type: %T", rule))
|
panic(fmt.Errorf("unknown rule type: %T", rule))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range vector {
|
for _, s := range vector {
|
||||||
|
|
|
@ -638,16 +638,16 @@ func (it *memorySeriesIterator) chunkIterator(i int) chunkIterator {
|
||||||
type nopSeriesIterator struct{}
|
type nopSeriesIterator struct{}
|
||||||
|
|
||||||
// ValueAtTime implements SeriesIterator.
|
// ValueAtTime implements SeriesIterator.
|
||||||
func (_ nopSeriesIterator) ValueAtTime(t model.Time) []model.SamplePair {
|
func (i nopSeriesIterator) ValueAtTime(t model.Time) []model.SamplePair {
|
||||||
return []model.SamplePair{}
|
return []model.SamplePair{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoundaryValues implements SeriesIterator.
|
// BoundaryValues implements SeriesIterator.
|
||||||
func (_ nopSeriesIterator) BoundaryValues(in metric.Interval) []model.SamplePair {
|
func (i nopSeriesIterator) BoundaryValues(in metric.Interval) []model.SamplePair {
|
||||||
return []model.SamplePair{}
|
return []model.SamplePair{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RangeValues implements SeriesIterator.
|
// RangeValues implements SeriesIterator.
|
||||||
func (_ nopSeriesIterator) RangeValues(in metric.Interval) []model.SamplePair {
|
func (i nopSeriesIterator) RangeValues(in metric.Interval) []model.SamplePair {
|
||||||
return []model.SamplePair{}
|
return []model.SamplePair{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,8 @@ func query(q string, timestamp model.Time, queryEngine *promql.Engine) (queryRes
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type templateExpander struct {
|
// Expander executes templates in text or HTML mode with a common set of Prometheus template functions.
|
||||||
|
type Expander struct {
|
||||||
text string
|
text string
|
||||||
name string
|
name string
|
||||||
data interface{}
|
data interface{}
|
||||||
|
@ -109,8 +110,8 @@ type templateExpander struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTemplateExpander returns a template expander ready to use.
|
// NewTemplateExpander returns a template expander ready to use.
|
||||||
func NewTemplateExpander(text string, name string, data interface{}, timestamp model.Time, queryEngine *promql.Engine, pathPrefix string) *templateExpander {
|
func NewTemplateExpander(text string, name string, data interface{}, timestamp model.Time, queryEngine *promql.Engine, pathPrefix string) *Expander {
|
||||||
return &templateExpander{
|
return &Expander{
|
||||||
text: text,
|
text: text,
|
||||||
name: name,
|
name: name,
|
||||||
data: data,
|
data: data,
|
||||||
|
@ -249,16 +250,16 @@ func NewTemplateExpander(text string, name string, data interface{}, timestamp m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funcs adds the functions in fm to the templateExpander's function map.
|
// Funcs adds the functions in fm to the Expander's function map.
|
||||||
// Existing functions will be overwritten in case of conflict.
|
// Existing functions will be overwritten in case of conflict.
|
||||||
func (te templateExpander) Funcs(fm text_template.FuncMap) {
|
func (te Expander) Funcs(fm text_template.FuncMap) {
|
||||||
for k, v := range fm {
|
for k, v := range fm {
|
||||||
te.funcMap[k] = v
|
te.funcMap[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand a template.
|
// Expand expands a template in text (non-HTML) mode.
|
||||||
func (te templateExpander) Expand() (result string, resultErr error) {
|
func (te Expander) Expand() (result string, resultErr error) {
|
||||||
// It'd better to have no alert description than to kill the whole process
|
// It'd better to have no alert description than to kill the whole process
|
||||||
// if there's a bug in the template.
|
// if there's a bug in the template.
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -283,8 +284,8 @@ func (te templateExpander) Expand() (result string, resultErr error) {
|
||||||
return buffer.String(), nil
|
return buffer.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand a template with HTML escaping, with templates read from the given files.
|
// ExpandHTML expands a template with HTML escaping, with templates read from the given files.
|
||||||
func (te templateExpander) ExpandHTML(templateFiles []string) (result string, resultErr error) {
|
func (te Expander) ExpandHTML(templateFiles []string) (result string, resultErr error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
|
@ -77,7 +77,7 @@ func (c callbackCloser) Close() {
|
||||||
|
|
||||||
// NewCallbackCloser returns a Closer that calls the provided function upon
|
// NewCallbackCloser returns a Closer that calls the provided function upon
|
||||||
// closing.
|
// closing.
|
||||||
func NewCallbackCloser(fn func()) *callbackCloser {
|
func NewCallbackCloser(fn func()) Closer {
|
||||||
return &callbackCloser{
|
return &callbackCloser{
|
||||||
fn: fn,
|
fn: fn,
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ type API struct {
|
||||||
QueryEngine *promql.Engine
|
QueryEngine *promql.Engine
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterHandler registers the handler for the various endpoints below /api.
|
// Register registers the handler for the various endpoints below /api.
|
||||||
func (api *API) Register(router *route.Router) {
|
func (api *API) Register(router *route.Router) {
|
||||||
router.Get("/query", handle("query", api.Query))
|
router.Get("/query", handle("query", api.Query))
|
||||||
router.Get("/query_range", handle("query_range", api.QueryRange))
|
router.Get("/query_range", handle("query_range", api.QueryRange))
|
||||||
|
|
|
@ -225,7 +225,7 @@ func (api *API) Metrics(w http.ResponseWriter, r *http.Request) {
|
||||||
resultBytes, err := json.Marshal(metricNames)
|
resultBytes, err := json.Marshal(metricNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error marshalling metric names: ", err)
|
log.Error("Error marshalling metric names: ", err)
|
||||||
httpJSONError(w, fmt.Errorf("Error marshalling metric names: %s", err), http.StatusInternalServerError)
|
httpJSONError(w, fmt.Errorf("error marshalling metric names: %s", err), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(resultBytes)
|
w.Write(resultBytes)
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Federation implements a web handler to serve scrape federation requests.
|
||||||
type Federation struct {
|
type Federation struct {
|
||||||
Storage local.Storage
|
Storage local.Storage
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,11 +337,11 @@ func (h *Handler) consolesPath() string {
|
||||||
func (h *Handler) getTemplate(name string) (string, error) {
|
func (h *Handler) getTemplate(name string) (string, error) {
|
||||||
baseTmpl, err := h.getTemplateFile("_base")
|
baseTmpl, err := h.getTemplateFile("_base")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Error reading base template: %s", err)
|
return "", fmt.Errorf("error reading base template: %s", err)
|
||||||
}
|
}
|
||||||
pageTmpl, err := h.getTemplateFile(name)
|
pageTmpl, err := h.getTemplateFile(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Error reading page template %s: %s", name, err)
|
return "", fmt.Errorf("error reading page template %s: %s", name, err)
|
||||||
}
|
}
|
||||||
return baseTmpl + pageTmpl, nil
|
return baseTmpl + pageTmpl, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue