Skip to content

LOG-2263: Vector: Added prometheus_exporter sink #1348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions internal/generator/vector/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type = "file"
ignore_older_secs = 600
include = ["/var/log/oauth-apiserver.audit.log"]

[sources.internal_metrics]
type = "internal_metrics"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot add namespace in this vector version. In latest version we can set the metric namespace here.


[transforms.container_logs]
type = "remap"
inputs = ["raw_container_logs"]
Expand Down Expand Up @@ -233,6 +236,12 @@ key_file = "/var/run/ocp-collector/secrets/kafka-receiver-1/tls.key"
crt_file = "/var/run/ocp-collector/secrets/kafka-receiver-1/tls.crt"
ca_file = "/var/run/ocp-collector/secrets/kafka-receiver-1/ca-bundle.crt"
enabled = true

[sinks.prometheus_output]
type = "prometheus_exporter"
inputs = ["internal_metrics"]
address = "0.0.0.0:24231"
default_namespace = "collector"
`,
}),
Entry("with complex spec for elastic-search", generator.ConfGenerateTest{
Expand Down Expand Up @@ -313,6 +322,9 @@ type = "file"
ignore_older_secs = 600
include = ["/var/log/oauth-apiserver.audit.log"]

[sources.internal_metrics]
type = "internal_metrics"

[transforms.container_logs]
type = "remap"
inputs = ["raw_container_logs"]
Expand Down Expand Up @@ -563,6 +575,11 @@ id_key = "_id"
key_file = "/var/run/ocp-collector/secrets/es-2/tls.key"
crt_file = "/var/run/ocp-collector/secrets/es-2/tls.crt"
ca_file = "/var/run/ocp-collector/secrets/es-2/ca-bundle.crt"
[sinks.prometheus_output]
type = "prometheus_exporter"
inputs = ["internal_metrics"]
address = "0.0.0.0:24231"
default_namespace = "collector"
`,
}),
Entry("with multiple pipelines for elastic-search", generator.ConfGenerateTest{
Expand Down Expand Up @@ -649,6 +666,9 @@ type = "file"
ignore_older_secs = 600
include = ["/var/log/oauth-apiserver.audit.log"]

[sources.internal_metrics]
type = "internal_metrics"

[transforms.container_logs]
type = "remap"
inputs = ["raw_container_logs"]
Expand Down Expand Up @@ -907,6 +927,11 @@ id_key = "_id"
key_file = "/var/run/ocp-collector/secrets/es-2/tls.key"
crt_file = "/var/run/ocp-collector/secrets/es-2/tls.crt"
ca_file = "/var/run/ocp-collector/secrets/es-2/ca-bundle.crt"
[sinks.prometheus_output]
type = "prometheus_exporter"
inputs = ["internal_metrics"]
address = "0.0.0.0:24231"
default_namespace = "collector"
`,
}),
)
Expand Down
47 changes: 47 additions & 0 deletions internal/generator/vector/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package vector

const (
InternalMetricsSourceName = "internal_metrics"
PrometheusOutputSinkName = "prometheus_output"
PrometheusExporterAddress = "0.0.0.0:24231"
)

type InternalMetrics struct {
ID string
ScrapeIntervalSec int
}

func (InternalMetrics) Name() string {
return "internalMetricsTemplate"
}

//#namespace = "collector"
//#scrape_interval_secs = {{.ScrapeIntervalSec}}
func (i InternalMetrics) Template() string {
return `
{{define "` + i.Name() + `" -}}
[sources.{{.ID}}]
type = "internal_metrics"
{{end}}
`
}

type PrometheusExporter struct {
ID string
Inputs string
Address string
}

func (p PrometheusExporter) Name() string {
return "PrometheusExporterTemplate"
}

func (p PrometheusExporter) Template() string {
return `{{define "` + p.Name() + `" -}}
[sinks.{{.ID}}]
type = "prometheus_exporter"
inputs = {{.Inputs}}
address = "{{.Address}}"
default_namespace = "collector"
{{end}}`
}
10 changes: 10 additions & 0 deletions internal/generator/vector/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vector
import (
logging "github.com/openshift/cluster-logging-operator/apis/logging/v1"
"github.com/openshift/cluster-logging-operator/internal/generator"
"github.com/openshift/cluster-logging-operator/internal/generator/vector/helpers"
"github.com/openshift/cluster-logging-operator/internal/generator/vector/output/elasticsearch"
"github.com/openshift/cluster-logging-operator/internal/generator/vector/output/kafka"
"github.com/openshift/cluster-logging-operator/internal/generator/vector/output/loki"
Expand All @@ -25,5 +26,14 @@ func Outputs(clspec *logging.ClusterLoggingSpec, secrets map[string]*corev1.Secr
outputs = generator.MergeElements(outputs, elasticsearch.Conf(o, inputs, secret, op))
}
}
outputs = append(outputs, PrometheusOutput(PrometheusOutputSinkName, []string{InternalMetricsSourceName}))
return outputs
}

func PrometheusOutput(id string, inputs []string) generator.Element {
return PrometheusExporter{
ID: id,
Inputs: helpers.MakeInputs(inputs...),
Address: PrometheusExporterAddress,
}
}
10 changes: 10 additions & 0 deletions internal/generator/vector/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func Sources(spec *logging.ClusterLogForwarderSpec, op generator.Options) []generator.Element {
return generator.MergeElements(
LogSources(spec, op),
MetricsSources(InternalMetricsSourceName),
)
}

Expand Down Expand Up @@ -87,3 +88,12 @@ func ExcludeContainerPaths() string {
", ",
))
}

func MetricsSources(id string) []generator.Element {
return []generator.Element{
InternalMetrics{
ID: id,
ScrapeIntervalSec: 2,
},
}
}