Allow excluding ServiceEntries in some namespaces when looking up ServiceEntries (#11640)

This commit is contained in:
kezhenxu94 2023-12-08 22:02:17 +08:00 committed by GitHub
parent 39c21e3b45
commit 8ff67d09e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 0 deletions

View File

@ -9,6 +9,8 @@
* Remove unreasonable default configurations for gRPC thread executor.
* Remove `gRPCThreadPoolQueueSize (SW_RECEIVER_GRPC_POOL_QUEUE_SIZE)`
configuration.
* Allow excluding ServiceEntries in some namespaces when looking up
ServiceEntries as a final resolution method of service metadata.
#### UI
* Fix the mismatch between the unit and calculation of the "Network Bandwidth Usage" widget in Linux-Service Dashboard.

View File

@ -191,6 +191,7 @@ The Configuration Vocabulary lists all available configurations provided by `app
| - | - | alsTCPAnalysis | Starts Envoy TCP Access Log Service analysis. Value = `k8s-mesh` means starting the analysis. | SW_ENVOY_METRIC_ALS_TCP_ANALYSIS | - |
| - | - | k8sServiceNameRule | `k8sServiceNameRule` allows you to customize the service name in ALS via Kubernetes metadata. The available variables are `pod` and `service`. E.g. you can use `${service.metadata.name}-${pod.metadata.labels.version}` to append the version number to the service name. Note that when using environment variables to pass this configuration, use single quotes(`''`) to avoid being evaluated by the shell. | K8S_SERVICE_NAME_RULE | ${pod.metadata.labels.(service.istio.io/canonical-name)} |
| - | - | istioServiceNameRule | `istioServiceNameRule` allows you to customize the service name in ALS via Kubernetes metadata. The available variables are `serviceEntry`. E.g. you can use `${serviceEntry.metadata.name}-${serviceEntry.metadata.labels.version}` to append the version number to the service name. Note that when using environment variables to pass this configuration, use single quotes(`''`) to avoid being evaluated by the shell. | ISTIO_SERVICE_NAME_RULE | ${serviceEntry.metadata.name} |
| - | - | istioServiceEntryIgnoredNamespaces | When looking up service informations from the Istio ServiceEntries, some of the ServiceEntries might be created in several namespaces automatically by some components, and OAP will randomly pick one of them to build the service name, users can use this config to exclude ServiceEntries that they don't want to be used. Comma separated. | SW_ISTIO_SERVICE_ENTRY_IGNORED_NAMESPACES | - |
| receiver-otel | default | A receiver for analyzing metrics data from OpenTelemetry. | - | - | |
| - | - | enabledHandlers | Enabled handlers for otel. | SW_OTEL_RECEIVER_ENABLED_HANDLERS | - |
| - | - | enabledOtelMetricsRules | Enabled metric rules for OTLP handler. | SW_OTEL_RECEIVER_ENABLED_OTEL_METRICS_RULES | - |

View File

@ -18,12 +18,14 @@
package org.apache.skywalking.oap.server.receiver.envoy;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.Getter;
import org.apache.skywalking.oap.meter.analyzer.prometheus.rule.Rule;
@ -41,6 +43,7 @@ public class EnvoyMetricReceiverConfig extends ModuleConfig {
private String k8sServiceNameRule;
@Getter
private String istioServiceNameRule;
private String istioServiceEntryIgnoredNamespaces;
private final ServiceMetaInfoFactory serviceMetaInfoFactory = new ServiceMetaInfoFactoryImpl();
@Getter
@ -71,4 +74,9 @@ public class EnvoyMetricReceiverConfig extends ModuleConfig {
public ServiceMetaInfoFactory serviceMetaInfoFactory() {
return serviceMetaInfoFactory;
}
public Set<String> getIstioServiceEntryIgnoredNamespaces() {
final var s = Strings.nullToEmpty(istioServiceEntryIgnoredNamespaces);
return Splitter.on(",").omitEmptyStrings().trimResults().splitToStream(s).collect(Collectors.toSet());
}
}

View File

@ -58,6 +58,8 @@ public class IstioServiceEntryRegistry {
serviceNameFormatter = new ServiceNameFormatter(config.getIstioServiceNameRule());
final var ignoredNamespaces = config.getIstioServiceEntryIgnoredNamespaces();
final var cacheBuilder = CacheBuilder.newBuilder().expireAfterWrite(Duration.ofMinutes(3));
ipServiceMetaInfoMap = cacheBuilder.build(new CacheLoader<>() {
@ -69,6 +71,7 @@ public class IstioServiceEntryRegistry {
.parallelStream()
.filter(se -> se.getMetadata() != null)
.filter(se -> se.getSpec() != null)
.filter(se -> !ignoredNamespaces.contains(se.getMetadata().getNamespace()))
.filter(se -> {
final var spec = se.getSpec();
switch (spec.getResolution()) {

View File

@ -316,6 +316,12 @@ envoy-metric:
# Be careful, when using environment variables to pass this configuration, use single quotes(`''`) to avoid it being evaluated by the shell.
k8sServiceNameRule: ${K8S_SERVICE_NAME_RULE:"${pod.metadata.labels.(service.istio.io/canonical-name)}"}
istioServiceNameRule: ${ISTIO_SERVICE_NAME_RULE:"${serviceEntry.metadata.name}"}
# When looking up service informations from the Istio ServiceEntries, some
# of the ServiceEntries might be created in several namespaces automatically
# by some components, and OAP will randomly pick one of them to build the
# service name, users can use this config to exclude ServiceEntries that
# they don't want to be used. Comma separated.
istioServiceEntryIgnoredNamespaces: ${SW_ISTIO_SERVICE_ENTRY_IGNORED_NAMESPACES:""}
kafka-fetcher:
selector: ${SW_KAFKA_FETCHER:-}