Skip to content

Commit

Permalink
Move setting to "collectors" section - seems more appropriate there s…
Browse files Browse the repository at this point in the history
…ince that is where the other custom tags are defined, too.

This setting is ignored when not running in OpenShift.
  • Loading branch information
jmazzitelli committed Feb 28, 2017
1 parent 146618a commit 64ed71e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 48 deletions.
18 changes: 9 additions & 9 deletions README.adoc
Expand Up @@ -663,15 +663,6 @@ kubernetes:
----
|Restricts the number of metrics that will be stored for each pod being monitored.

|K8S_POD_LABEL_TAGS_PREFIX
|
[source,yaml]
----
kubernetes:
pod_label_tags_prefix: VALUE
----
| Pods might have one or more labels (name/value pairs). You can tag each metric with these pod labels if "pod_label_tags_prefix" is not an empty string. If it is an empty string or not specified, these tags will not be created. When not an empty string, for each label on a pod a tag will be placed on each pod metric with this string prefixing the pod label name. For example, if the prefix string is `labels.` and a pod has a label `something=foo` then that pod's metrics will have a tag named `labels.something` with value of `foo`. If you wish to create these tags with no prefix (that is, you want the tag names to be exactly the same as the label names) set the prefix value to `\_empty_`.

|COLLECTOR_MINIMUM_COLLECTION_INTERVAL
|
[source,yaml]
Expand All @@ -690,6 +681,15 @@ collector:
----
|The default collection interval for those endpoints that do not explicitly define its own collection interval. Specified as a number followed by units such as "30s" for thirty seconds or "2m" for two minutes.

|COLLECTOR_POD_LABEL_TAGS_PREFIX
|
[source,yaml]
----
collector:
pod_label_tags_prefix: VALUE
----
| Pods might have one or more labels (name/value pairs). You can tag each metric with these pod labels if "pod_label_tags_prefix" is not an empty string. If it is an empty string or not specified, these tags will not be created. When not an empty string, for each label on a pod a tag will be placed on each pod metric with this string prefixing the pod label name. For example, if the prefix string is `labels.` and a pod has a label `something=foo` then that pod's metrics will have a tag named `labels.something` with value of `foo`. If you wish to create these tags with no prefix (that is, you want the tag names to be exactly the same as the label names) set the prefix value to `\_empty_`.

|EMITTER_ADDRESS
|
[source,yaml]
Expand Down
55 changes: 29 additions & 26 deletions config/config.go
Expand Up @@ -44,14 +44,13 @@ const (
ENV_IDENTITY_CERT_FILE = "HAWKULAR_OPENSHIFT_AGENT_CERT_FILE"
ENV_IDENTITY_PRIVATE_KEY_FILE = "HAWKULAR_OPENSHIFT_AGENT_PRIVATE_KEY_FILE"

ENV_K8S_MASTER_URL = "K8S_MASTER_URL"
ENV_K8S_POD_NAMESPACE = "K8S_POD_NAMESPACE"
ENV_K8S_POD_NAME = "K8S_POD_NAME"
ENV_K8S_TOKEN = "K8S_TOKEN"
ENV_K8S_CA_CERT_FILE = "K8S_CA_CERT_FILE"
ENV_K8S_TENANT = "K8S_TENANT"
ENV_K8S_MAX_METRICS_PER_POD = "K8S_MAX_METRICS_PER_POD"
ENV_K8S_POD_LABEL_TAGS_PREFIX = "K8S_POD_LABEL_TAGS_PREFIX"
ENV_K8S_MASTER_URL = "K8S_MASTER_URL"
ENV_K8S_POD_NAMESPACE = "K8S_POD_NAMESPACE"
ENV_K8S_POD_NAME = "K8S_POD_NAME"
ENV_K8S_TOKEN = "K8S_TOKEN"
ENV_K8S_CA_CERT_FILE = "K8S_CA_CERT_FILE"
ENV_K8S_TENANT = "K8S_TENANT"
ENV_K8S_MAX_METRICS_PER_POD = "K8S_MAX_METRICS_PER_POD"

ENV_EMITTER_ADDRESS = "EMITTER_ADDRESS"
ENV_EMITTER_METRICS_ENABLED = "EMITTER_METRICS_ENABLED"
Expand All @@ -65,6 +64,7 @@ const (

ENV_COLLECTOR_MINIMUM_COLL_INTERVAL = "COLLECTOR_MINIMUM_COLLECTION_INTERVAL"
ENV_COLLECTOR_DEFAULT_COLL_INTERVAL = "COLLECTOR_DEFAULT_COLLECTION_INTERVAL"
ENV_COLLECTOR_POD_LABEL_TAGS_PREFIX = "COLLECTOR_POD_LABEL_TAGS_PREFIX"
)

// Hawkular_Server defines where the Hawkular Server is. This is where metrics are stored.
Expand All @@ -80,14 +80,27 @@ type Hawkular_Server struct {
}

// Collector provides information about collecting metrics from monitored endpoints.
//
// Tags specified here will be attached to all metrics this agent collects and stores.
//
// ID_Prefix is a string (with potential ${env} tokens) that is prepended to all IDs of
// all metrics collected by the agent.
//
// Pods might have one or more labels (name/value pairs). You can tag each metric
// with these pod labels if "Pod_Label_Tags_Prefix" is not an empty string. If it is an empty
// string or not specified, these tags will not be created. When not an empty string, for each
// label on a pod a tag will be placed on each pod metric with this string prefixing the
// pod label name. For example, if the prefix string is "labels." and a pod has a
// label "something=foo" then that pod's metrics will have a tag named "labels.something"
// with value of "foo". If you wish to create these tags with no prefix (that is, you want the
// tag names to be exactly the same as the label names) set the prefix value to "_empty_".
//
// USED FOR YAML
type Collector struct {
Minimum_Collection_Interval string
Default_Collection_Interval string
Tags tags.Tags ",omitempty"
Pod_Label_Tags_Prefix string ",omitempty"
Metric_ID_Prefix string
}

Expand All @@ -106,25 +119,15 @@ type Collector struct {
// that is the same name of the pod namespace where the metric was collected.
// If Tenant is not supplied, the default is the Tenant defined in the Hawkular_Server section.
//
// Kubernetes pods might have one or more labels (name/value pairs). You can tag each metric
// with these pod labels if "Pod_Label_Tags_Prefix" is not an empty string. If it is an empty
// string or not specified, these tags will not be created. When not an empty string, for each
// label on a pod a tag will be placed on each pod metric with this string prefixing the
// pod label name. For example, if the prefix string is "labels." and a pod has a
// label "something=foo" then that pod's metrics will have a tag named "labels.something"
// with value of "foo". If you wish to create these tags with no prefix (that is, you want the
// tag names to be exactly the same as the label names) set the prefix value to "_empty_".
//
// USED FOR YAML
type Kubernetes struct {
Master_URL string ",omitempty"
Token string ",omitempty"
CA_Cert_File string ",omitempty"
Pod_Namespace string ",omitempty"
Pod_Name string ",omitempty"
Tenant string ",omitempty"
Max_Metrics_Per_Pod int ",omitempty"
Pod_Label_Tags_Prefix string ",omitempty"
Master_URL string ",omitempty"
Token string ",omitempty"
CA_Cert_File string ",omitempty"
Pod_Namespace string ",omitempty"
Pod_Name string ",omitempty"
Tenant string ",omitempty"
Max_Metrics_Per_Pod int ",omitempty"
}

// Emitter defines the behavior of the emitter which is responsible for
Expand Down Expand Up @@ -167,6 +170,7 @@ func NewConfig() (c *Config) {

c.Collector.Minimum_Collection_Interval = getDefaultString(ENV_COLLECTOR_MINIMUM_COLL_INTERVAL, "10s")
c.Collector.Default_Collection_Interval = getDefaultString(ENV_COLLECTOR_DEFAULT_COLL_INTERVAL, "5m")
c.Collector.Pod_Label_Tags_Prefix = getDefaultString(ENV_COLLECTOR_POD_LABEL_TAGS_PREFIX, "")

c.Kubernetes.Master_URL = getDefaultString(ENV_K8S_MASTER_URL, "")
c.Kubernetes.Pod_Namespace = getDefaultString(ENV_K8S_POD_NAMESPACE, "")
Expand All @@ -175,7 +179,6 @@ func NewConfig() (c *Config) {
c.Kubernetes.CA_Cert_File = getDefaultString(ENV_K8S_CA_CERT_FILE, "")
c.Kubernetes.Tenant = getDefaultString(ENV_K8S_TENANT, "")
c.Kubernetes.Max_Metrics_Per_Pod = getDefaultInt(ENV_K8S_MAX_METRICS_PER_POD, 50)
c.Kubernetes.Pod_Label_Tags_Prefix = getDefaultString(ENV_K8S_POD_LABEL_TAGS_PREFIX, "")

c.Emitter.Metrics_Enabled = getDefaultString(ENV_EMITTER_METRICS_ENABLED, "true")
c.Emitter.Status_Enabled = getDefaultString(ENV_EMITTER_STATUS_ENABLED, "false")
Expand Down
20 changes: 10 additions & 10 deletions config/config_test.go
Expand Up @@ -111,6 +111,9 @@ func TestDefaults(t *testing.T) {
if conf.Collector.Default_Collection_Interval != "5m" {
t.Error("Default collection interval default is wrong")
}
if conf.Collector.Pod_Label_Tags_Prefix != "" {
t.Error("Pod label tags prefix default is wrong")
}
if conf.Hawkular_Server.URL != "http://127.0.0.1:8080" {
t.Error("Hawkular Server URL is wrong")
}
Expand Down Expand Up @@ -138,9 +141,6 @@ func TestDefaults(t *testing.T) {
if conf.Kubernetes.Max_Metrics_Per_Pod != 50 {
t.Error("Max metrics per pod default is wrong")
}
if conf.Kubernetes.Pod_Label_Tags_Prefix != "" {
t.Error("Pod label tags prefix default is wrong")
}
if len(conf.Endpoints) != 0 {
t.Error("There should be no endpoints by default")
}
Expand Down Expand Up @@ -172,15 +172,15 @@ func TestMarshalUnmarshal(t *testing.T) {
Collector: Collector{
Minimum_Collection_Interval: "12345s",
Default_Collection_Interval: "98765s",
Pod_Label_Tags_Prefix: "labels.",
},
Hawkular_Server: Hawkular_Server{
URL: "http://server:80",
},
Kubernetes: Kubernetes{
Pod_Namespace: "TestMarshalUnmarshal namespace",
Pod_Name: "TestMarshalUnmarshal name",
Max_Metrics_Per_Pod: 123,
Pod_Label_Tags_Prefix: "labels.",
Pod_Namespace: "TestMarshalUnmarshal namespace",
Pod_Name: "TestMarshalUnmarshal name",
Max_Metrics_Per_Pod: 123,
},
Emitter: Emitter{
Metrics_Enabled: "false",
Expand Down Expand Up @@ -235,6 +235,9 @@ func TestMarshalUnmarshal(t *testing.T) {
if conf.Collector.Default_Collection_Interval != "98765s" {
t.Errorf("Failed to unmarshal default collection interval:\n%v", conf)
}
if conf.Collector.Pod_Label_Tags_Prefix != "labels." {
t.Error("Pod Label Tags Prefix is wrong")
}
if conf.Collector.Metric_ID_Prefix != "" {
t.Errorf("Failed to unmarshal empty metric ID prefix:\n%v", conf)
}
Expand All @@ -250,9 +253,6 @@ func TestMarshalUnmarshal(t *testing.T) {
if conf.Kubernetes.Max_Metrics_Per_Pod != 123 {
t.Errorf("Failed to unmarshal max metrics per pod:\n%v", conf)
}
if conf.Kubernetes.Pod_Label_Tags_Prefix != "labels." {
t.Error("Pod Label Tags Prefix is wrong")
}
if conf.Endpoints[0].Collection_Interval != "123s" {
t.Error("First endpoint is not correct")
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/openshift/hawkular-openshift-agent-configmap.yaml
Expand Up @@ -10,7 +10,6 @@ data:
config.yaml: |
kubernetes:
tenant: ${POD:namespace_name}
pod_label_tags_prefix: labels.
hawkular_server:
url: https://hawkular-metrics.openshift-infra.svc.cluster.local
credentials:
Expand All @@ -23,6 +22,7 @@ data:
minimum_collection_interval: 10s
default_collection_interval: 30s
metric_id_prefix: pod/${POD:uid}/custom/
pod_label_tags_prefix: labels.
tags:
metric_name: ${METRIC:name}
description: ${METRIC:description}
Expand Down
4 changes: 2 additions & 2 deletions k8s/node_event_consumer.go
Expand Up @@ -246,10 +246,10 @@ func (nec *NodeEventConsumer) startCollecting(ne *NodeEvent) {
// if all pod labels should be used as tags on all metrics, create those tags from the pod labels.
endpointTags := tags.Tags{}
endpointTags.AppendTags(cmeEndpoint.Tags)
if nec.Config.Kubernetes.Pod_Label_Tags_Prefix != "" {
if nec.Config.Collector.Pod_Label_Tags_Prefix != "" {
// each label will be prefixed with the configured prefix string unless that prefix
// was "_empty_" in which case the user is telling us to use the label name as-is with no prefix.
prefix := nec.Config.Kubernetes.Pod_Label_Tags_Prefix
prefix := nec.Config.Collector.Pod_Label_Tags_Prefix
if prefix == "_empty_" {
prefix = ""
}
Expand Down

0 comments on commit 64ed71e

Please sign in to comment.