From 0d68765e7252ca7126e5fea1cf9bb063c5991943 Mon Sep 17 00:00:00 2001 From: Melchior Moulin Date: Tue, 14 Jun 2022 10:26:52 +0200 Subject: [PATCH] activate tracing bool Signed-off-by: Melchior Moulin --- README.md | 63 ++++++++++++++++---------------- cmd/main.go | 11 +++--- internal/config/canary_config.go | 16 +++++--- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 131b915..480c970 100644 --- a/README.md +++ b/README.md @@ -53,37 +53,38 @@ Where this is possible, a field name is provided in the table. The configuration file described in more detail the next section. | Environment variable | Description | Default | Dynamic Configuration field name | -|---|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------|---| -| `KAFKA_BOOTSTRAP_SERVERS` | Comma separated bootstrap servers of the Kafka cluster to connect to. | `localhost:9092` | | -| `KAFKA_BOOTSTRAP_BACKOFF_MAX_ATTEMPTS` | Maximum number of attempts for connecting to the Kafka cluster if it is not ready yet. | `10` | | -| `KAFKA_BOOTSTRAP_BACKOFF_SCALE` | The scale used to delay between attempts to connect to the Kafka cluster (in ms) | `5000` | | -| `TOPIC` | The name of the topic used by the tool to send and receive messages. | `__strimzi_canary` | | -| `TOPIC_CONFIG` | Topic configuration defined as a list of semicolon separated `key=value` pairs (i.e. `retention.ms=600000;segment.bytes=16384`). | empty | | -| `RECONCILE_INTERVAL_MS` | It defines how often the tool has to send and receive messages (in ms). | `30000` | | -| `CLIENT_ID` | The client id used for configuring producer and consumer. | `strimzi-canary-client` | | -| `CONSUMER_GROUP_ID` | Group id for the consumer group joined by the canary consumer. | `strimzi-canary-group` | | -| `PRODUCER_LATENCY_BUCKETS` | Buckets of the histogram related to the producer latency metric (in ms). | `100,200,400,800,1600` | | -| `ENDTOEND_LATENCY_BUCKETS` | Buckets of the histogram related to the end to end latency metric between producer and consumer (in ms). | `100,200,400,800,1600` | | -| `EXPECTED_CLUSTER_SIZE` | Expected number of brokers in the Kafka cluster where the canary connects to. This parameter avoids that the tool runs more partitions reassignment of the topic while the Kafka cluster is starting up and the brokers are coming one by one. `-1` means "dynamic" reassignment as described above. When greater than 0, the canary waits for the Kafka cluster having the expected number of brokers running before creating the topic and assigning the partitions | `-1` | | -| `KAFKA_VERSION` | Version of the Kafka cluster | `3.1.0` | | -| `SARAMA_LOG_ENABLED` | Enables the Sarama client logging. | `false` | `saramaLogEnabled` | -| `VERBOSITY_LOG_LEVEL` | Verbosity of the tool logging. Allowed values 0 = INFO, 1 = DEBUG, 2 = TRACE | `0` | `verbosityLogLevel` | -| `TLS_ENABLED` | If the canary has to use TLS to connect to the Kafka cluster. | `false` | | -| `TLS_CA_CERT` | TLS CA certificate, in PEM format, to use to connect to the Kafka cluster. When this parameter is empty (default behaviour) and the TLS connection is enabled, the canary uses the system certificates trust store. When a TLS CA certificate is specified, it is added to the system certificates trust store | empty | | -| `TLS_CLIENT_CERT` | TLS client certificate, in PEM format, to use for enabling TLS client authentication against the Kafka cluster. | empty | | -| `TLS_CLIENT_KEY` | TLS client private key, in PEM format, to use for enabling TLS client authentication against the Kafka cluster. | empty | | -| `TLS_INSECURE_SKIP_VERIFY` | if the underneath Sarama client has to verify the server's certificate chain and host name. | `false` | | -| `SASL_MECHANISM` | Mechanism to use for SASL authentication against the Kafka cluster. Supported are `PLAIN`, `SCRAM-SHA-256` and `SCRAM-SHA-512`. | empty | | -| `SASL_USER` | Username for SASL authentication against the Kafka cluster when one of `PLAIN`, `SCRAM-SHA-256` or `SCRAM-SHA-512` is used. | empty | | -| `SASL_PASSWORD` | Password for SASL authentication against the Kafka cluster when one of `PLAIN`, `SCRAM-SHA-256` or `SCRAM-SHA-512` is used. | empty | | -| `CONNECTION_CHECK_INTERVAL_MS` | It defines how often the tool has to check the connection with brokers (in ms). | `120000` | | -| `CONNECTION_CHECK_LATENCY_BUCKETS` | Buckets of the histogram related to the broker's connection latency metric (in ms). | `100,200,400,800,1600` | | -| `STATUS_CHECK_INTERVAL_MS` | It defines how often (in ms) the tool updates internal status information (i.e. percentage of consumed messages) to expose outside on the corresponding HTTP endpoint. | `30000` | | -| `STATUS_TIME_WINDOW_MS` | It defines the sliding time window size (in ms) in which status information are sampled. | `300000` | | -| `DYNAMIC_CONFIG_FILE` | Location of an optional external config file that provides configuration at runtime. | empty | | -| `DYNAMIC_CONFIG_WATCHER_INTERVAL` | Interval that dynamic config file is examined for changes in content (in ms) | `30000` | | -| `OTEL_EXPORTER_OTLP_ENDPOINT` | Activate OTLP tracing and set the endpoint | empty | | -| `OTEL_EXPORTER_JAEGER_ENDPOINT` | Activate Jaeger tracing and set the endpoint | empty | | +|---|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------|----------------------------------| +| `KAFKA_BOOTSTRAP_SERVERS` | Comma separated bootstrap servers of the Kafka cluster to connect to. | `localhost:9092` | | +| `KAFKA_BOOTSTRAP_BACKOFF_MAX_ATTEMPTS` | Maximum number of attempts for connecting to the Kafka cluster if it is not ready yet. | `10` | | +| `KAFKA_BOOTSTRAP_BACKOFF_SCALE` | The scale used to delay between attempts to connect to the Kafka cluster (in ms) | `5000` | | +| `TOPIC` | The name of the topic used by the tool to send and receive messages. | `__strimzi_canary` | | +| `TOPIC_CONFIG` | Topic configuration defined as a list of semicolon separated `key=value` pairs (i.e. `retention.ms=600000;segment.bytes=16384`). | empty | | +| `RECONCILE_INTERVAL_MS` | It defines how often the tool has to send and receive messages (in ms). | `30000` | | +| `CLIENT_ID` | The client id used for configuring producer and consumer. | `strimzi-canary-client` | | +| `CONSUMER_GROUP_ID` | Group id for the consumer group joined by the canary consumer. | `strimzi-canary-group` | | +| `PRODUCER_LATENCY_BUCKETS` | Buckets of the histogram related to the producer latency metric (in ms). | `100,200,400,800,1600` | | +| `ENDTOEND_LATENCY_BUCKETS` | Buckets of the histogram related to the end to end latency metric between producer and consumer (in ms). | `100,200,400,800,1600` | | +| `EXPECTED_CLUSTER_SIZE` | Expected number of brokers in the Kafka cluster where the canary connects to. This parameter avoids that the tool runs more partitions reassignment of the topic while the Kafka cluster is starting up and the brokers are coming one by one. `-1` means "dynamic" reassignment as described above. When greater than 0, the canary waits for the Kafka cluster having the expected number of brokers running before creating the topic and assigning the partitions | `-1` | | +| `KAFKA_VERSION` | Version of the Kafka cluster | `3.1.0` | | +| `SARAMA_LOG_ENABLED` | Enables the Sarama client logging. | `false` | `saramaLogEnabled` | +| `VERBOSITY_LOG_LEVEL` | Verbosity of the tool logging. Allowed values 0 = INFO, 1 = DEBUG, 2 = TRACE | `0` | `verbosityLogLevel` | +| `TLS_ENABLED` | If the canary has to use TLS to connect to the Kafka cluster. | `false` | | +| `TLS_CA_CERT` | TLS CA certificate, in PEM format, to use to connect to the Kafka cluster. When this parameter is empty (default behaviour) and the TLS connection is enabled, the canary uses the system certificates trust store. When a TLS CA certificate is specified, it is added to the system certificates trust store | empty | | +| `TLS_CLIENT_CERT` | TLS client certificate, in PEM format, to use for enabling TLS client authentication against the Kafka cluster. | empty | | +| `TLS_CLIENT_KEY` | TLS client private key, in PEM format, to use for enabling TLS client authentication against the Kafka cluster. | empty | | +| `TLS_INSECURE_SKIP_VERIFY` | if the underneath Sarama client has to verify the server's certificate chain and host name. | `false` | | +| `SASL_MECHANISM` | Mechanism to use for SASL authentication against the Kafka cluster. Supported are `PLAIN`, `SCRAM-SHA-256` and `SCRAM-SHA-512`. | empty | | +| `SASL_USER` | Username for SASL authentication against the Kafka cluster when one of `PLAIN`, `SCRAM-SHA-256` or `SCRAM-SHA-512` is used. | empty | | +| `SASL_PASSWORD` | Password for SASL authentication against the Kafka cluster when one of `PLAIN`, `SCRAM-SHA-256` or `SCRAM-SHA-512` is used. | empty | | +| `CONNECTION_CHECK_INTERVAL_MS` | It defines how often the tool has to check the connection with brokers (in ms). | `120000` | | +| `CONNECTION_CHECK_LATENCY_BUCKETS` | Buckets of the histogram related to the broker's connection latency metric (in ms). | `100,200,400,800,1600` | | +| `STATUS_CHECK_INTERVAL_MS` | It defines how often (in ms) the tool updates internal status information (i.e. percentage of consumed messages) to expose outside on the corresponding HTTP endpoint. | `30000` | | +| `STATUS_TIME_WINDOW_MS` | It defines the sliding time window size (in ms) in which status information are sampled. | `300000` | | +| `DYNAMIC_CONFIG_FILE` | Location of an optional external config file that provides configuration at runtime. | empty | | +| `DYNAMIC_CONFIG_WATCHER_INTERVAL` | Interval that dynamic config file is examined for changes in content (in ms) | `30000` | | +| `OTEL_EXPORTER_OTLP_ENDPOINT` | Activate OTLP tracing | empty | | +| `OTEL_EXPORTER_JAEGER_ENDPOINT` | Activate Jaeger tracing | empty | | +| `ACTIVATE_TRACING` | Activate tracing. When true OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_JAEGER_ENDPOINT | `false` | `activateTracing` | ## Dynamic Configuration file diff --git a/cmd/main.go b/cmd/main.go index 9a9849d..48bd7fa 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -46,15 +46,14 @@ var ( var saramaLogger = log.New(io.Discard, "[Sarama] ", log.LstdFlags) -func InitTracerProvider(JaegerExporterTracing bool, OtlpExporterTracing bool) *sdktrace.TracerProvider { +func InitTracerProvider(ActivateTracing bool, JaegerExporterTracing bool, OtlpExporterTracing bool) *sdktrace.TracerProvider { resources, _ := resource.New(context.Background(), resource.WithFromEnv(), // pull attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables resource.WithProcess(), // This option configures a set of Detectors that discover process information ) - exporter := exporterTracing(JaegerExporterTracing, OtlpExporterTracing) otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{})) - - if JaegerExporterTracing || OtlpExporterTracing { + if ActivateTracing { + exporter := exporterTracing(JaegerExporterTracing, OtlpExporterTracing) tp := sdktrace.NewTracerProvider( sdktrace.WithResource(resources), sdktrace.WithBatcher(exporter), @@ -94,7 +93,7 @@ func main() { glog.Infof("Starting Strimzi canary tool [%s] with config: %+v", version, canaryConfig) - tp := InitTracerProvider(canaryConfig.JaegerExporterTracing, canaryConfig.OtlpExporterTracing) + tp := InitTracerProvider(canaryConfig.ActivateTracing, canaryConfig.JaegerExporterTracing, canaryConfig.OtlpExporterTracing) defer func() { if tp != nil { if err := tp.Shutdown(context.Background()); err != nil { @@ -193,7 +192,7 @@ func applyDynamicConfig(dynamicCanaryConfig *config.DynamicCanaryConfig) { } else { saramaLogger.SetOutput(io.Discard) } - InitTracerProvider(*dynamicCanaryConfig.JaegerExporterTracing, *dynamicCanaryConfig.OtlpExporterTracing) + InitTracerProvider(*dynamicCanaryConfig.ActivateTracing, *dynamicCanaryConfig.JaegerExporterTracing, *dynamicCanaryConfig.OtlpExporterTracing) glog.Warningf("Applied dynamic config %s", dynamicCanaryConfig) } diff --git a/internal/config/canary_config.go b/internal/config/canary_config.go index e8dac98..8299d56 100644 --- a/internal/config/canary_config.go +++ b/internal/config/canary_config.go @@ -52,6 +52,7 @@ const ( JaegerAgentHostEnvVar = "OTEL_EXPORTER_JAEGER_AGENT_HOST" OtlpEndpointEnvVar = "OTEL_EXPORTER_OTLP_ENDPOINT" OtlpTracesEndpointEnvVar = "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + ActivateTracingEnvVar = "ACTIVATE_TRACING" // default values for environment variables BootstrapServersDefault = "localhost:9092" BootstrapBackoffMaxAttemptsDefault = 10 @@ -85,14 +86,15 @@ const ( JaegerAgentHostEnvVarDefault = "" OtlpEndpointEnvVarDefault = "" OtlpTracesEndpointEnvVarDefault = "" + ActivateTracingEnvVarDefault = false ) type DynamicCanaryConfig struct { SaramaLogEnabled *bool `json:"saramaLogEnabled"` VerbosityLogLevel *int `json:"verbosityLogLevel"` - OtlpExporterTracing *bool //if Jaeger or OTLP env var are defined we activate Tracing - JaegerExporterTracing *bool //if true activate jaeger else it is opentelemetry exporter - + OtlpExporterTracing *bool + JaegerExporterTracing *bool + ActivateTracing *bool `json:"activateTracing"` } // CanaryConfig defines the canary tool configuration @@ -125,13 +127,15 @@ type CanaryConfig struct { StatusTimeWindow time.Duration DynamicConfigWatcherInterval time.Duration OtlpExporterTracing bool - JaegerExporterTracing bool //if true activate jaeger else it is opentelemetry exporter - + JaegerExporterTracing bool + ActivateTracing bool } func NewDynamicCanaryConfig() *DynamicCanaryConfig { saramaLogEnabled := lookupBoolEnv(SaramaLogEnabledEnvVar, SaramaLogEnabledDefault) verbosityLogLevel := lookupIntEnv(VerbosityLogLevelEnvVar, VerbosityLogLevelDefault) + activateTracing := lookupBoolEnv(ActivateTracingEnvVar, ActivateTracingEnvVarDefault) + jaegerExporterTracing := isJaegerTracingExporter() otlpExporterTracing := isOtlpTracingExporter() dynamicCanaryConfig := DynamicCanaryConfig{ @@ -139,6 +143,7 @@ func NewDynamicCanaryConfig() *DynamicCanaryConfig { VerbosityLogLevel: &verbosityLogLevel, OtlpExporterTracing: &otlpExporterTracing, JaegerExporterTracing: &jaegerExporterTracing, + ActivateTracing: &activateTracing, } return &dynamicCanaryConfig } @@ -206,6 +211,7 @@ func NewCanaryConfig() *CanaryConfig { DynamicConfigWatcherInterval: time.Duration(lookupIntEnv(DynamicConfigWatcherIntervalEnvVar, DynamicConfigWatcherIntervalDefault)), OtlpExporterTracing: isOtlpTracingExporter(), JaegerExporterTracing: isJaegerTracingExporter(), + ActivateTracing: lookupBoolEnv(ActivateTracingEnvVar, ActivateTracingEnvVarDefault), } return &config }