-
Notifications
You must be signed in to change notification settings - Fork 165
LOG-4812: Refactor metrics templates and helper functions #2244
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package helpers | ||
|
||
import ( | ||
log "github.com/ViaQ/logerr/v2/log/static" | ||
logging "github.com/openshift/cluster-logging-operator/apis/logging/v1" | ||
"github.com/openshift/cluster-logging-operator/internal/constants" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func GetOutputSecret(o logging.OutputSpec, secrets map[string]*corev1.Secret) *corev1.Secret { | ||
if s, ok := secrets[o.Name]; ok { | ||
log.V(9).Info("Using secret configured in output: " + o.Name) | ||
return s | ||
} | ||
if s := secrets[constants.LogCollectorToken]; s != nil { | ||
log.V(9).Info("Using secret configured in " + constants.LogCollectorToken) | ||
return s | ||
} | ||
log.V(9).Info("No Secret found in " + constants.LogCollectorToken) | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package helpers | ||
|
||
import ( | ||
logging "github.com/openshift/cluster-logging-operator/apis/logging/v1" | ||
"github.com/openshift/cluster-logging-operator/internal/generator/framework" | ||
) | ||
|
||
func SetTLSProfileOptions(o logging.OutputSpec, op framework.Options) { | ||
op[framework.MinTLSVersion], op[framework.Ciphers] = func() (string, string) { | ||
if o.Name == logging.OutputNameDefault && o.Type == logging.OutputTypeElasticsearch { | ||
return "", "" | ||
} else { | ||
return op.TLSProfileInfo(o, ",") | ||
} | ||
}() | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
logging "github.com/openshift/cluster-logging-operator/apis/logging/v1" | ||
"github.com/openshift/cluster-logging-operator/internal/generator/framework" | ||
"github.com/openshift/cluster-logging-operator/internal/generator/vector/normalize" | ||
) | ||
|
||
const ( | ||
UserDefinedSinkThrottle = `sink_throttle_%s` | ||
) | ||
|
||
func AddThrottleForSink(spec *logging.OutputSpec, inputs []string) []framework.Element { | ||
id := fmt.Sprintf(UserDefinedSinkThrottle, spec.Name) | ||
return normalize.NewThrottle(id, inputs, spec.Limit.MaxRecordsPerSecond, "") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/openshift/cluster-logging-operator/internal/generator/framework" | ||
"github.com/openshift/cluster-logging-operator/internal/generator/vector/helpers" | ||
) | ||
|
||
const ( | ||
AddNodenameToMetricTransformName = "add_nodename_to_metric" | ||
PrometheusOutputSinkName = "prometheus_output" | ||
PrometheusExporterListenPort = `24231` | ||
) | ||
|
||
type PrometheusExporter struct { | ||
ID string | ||
Inputs string | ||
Address string | ||
TlsMinVersion string | ||
CipherSuites 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" | ||
[sinks.{{.ID}}.tls] | ||
enabled = true | ||
key_file = "/etc/collector/metrics/tls.key" | ||
crt_file = "/etc/collector/metrics/tls.crt" | ||
min_tls_version = "{{.TlsMinVersion}}" | ||
ciphersuites = "{{.CipherSuites}}" | ||
{{end}}` | ||
} | ||
|
||
type AddNodenameToMetric struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AddNodeNameToMetric is only used in one place, together with the PrometheusOutput, may be we could just inline it into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And even merge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds like a future refactoring |
||
ID string | ||
Inputs string | ||
} | ||
|
||
func (a AddNodenameToMetric) Name() string { | ||
return AddNodenameToMetricTransformName | ||
} | ||
|
||
func (a AddNodenameToMetric) Template() string { | ||
return `{{define "` + a.Name() + `" -}} | ||
[transforms.{{.ID}}] | ||
type = "remap" | ||
inputs = {{.Inputs}} | ||
source = ''' | ||
.tags.hostname = get_env_var!("VECTOR_SELF_NODE_NAME") | ||
''' | ||
{{end}}` | ||
} | ||
|
||
func PrometheusOutput(id string, inputs []string, minTlsVersion string, cipherSuites string) framework.Element { | ||
return PrometheusExporter{ | ||
ID: id, | ||
Inputs: helpers.MakeInputs(inputs...), | ||
Address: helpers.ListenOnAllLocalInterfacesAddress() + `:` + PrometheusExporterListenPort, | ||
TlsMinVersion: minTlsVersion, | ||
CipherSuites: cipherSuites, | ||
} | ||
} | ||
|
||
func AddNodeNameToMetric(id string, inputs []string) framework.Element { | ||
return AddNodenameToMetric{ | ||
ID: id, | ||
Inputs: helpers.MakeInputs(inputs...), | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How 'bout