You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2020/11/12 12:15:09 UTC
[skywalking] 01/02: Add Istio control plane otel MAL expressions
and UI template
This is an automated email from the ASF dual-hosted git repository.
hanahmily pushed a commit to branch otel-istio
in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit 798385aca1f500d486bc516c803489211050ef47
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Thu Nov 12 17:32:57 2020 +0800
Add Istio control plane otel MAL expressions and UI template
Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
.../skywalking/oap/meter/analyzer/Analyzer.java | 25 ++-
.../oap/meter/analyzer/dsl/SampleFamily.java | 4 +-
.../oap/meter/analyzer/prometheus/rule/Rule.java | 1 +
.../oap/meter/analyzer/prometheus/rule/Rules.java | 1 +
.../resources/oc-rules/istio-controlplane.yaml | 117 +++++++++++++
.../resources/ui-initialized-templates/istio.yml | 185 +++++++++++++++++++++
.../provider/PrometheusFetcherProvider.java | 5 +-
.../receiver/opencensus/OCMetricHandler.java | 9 +-
.../opencensus/OCMetricReceiverProvider.java | 16 +-
9 files changed, 347 insertions(+), 16 deletions(-)
diff --git a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/Analyzer.java b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/Analyzer.java
index 5b5c198..2d25a0b 100644
--- a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/Analyzer.java
+++ b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/Analyzer.java
@@ -106,7 +106,7 @@ public class Analyzer {
for (int i = 0; i < subSs.size(); i++) {
Sample s = subSs.get(i);
bb[i] = Long.parseLong(s.getLabels().get("le"));
- vv[i] = (long) s.getValue();
+ vv[i] = getValue(s);
}
BucketedValues bv = new BucketedValues(bb, vv);
long time = subSs.get(0).getTimestamp();
@@ -124,10 +124,17 @@ public class Analyzer {
});
return;
}
- if (ss.length == 1) {
+ boolean isLabeled = false;
+ for (Sample each : ss) {
+ if (!each.getLabels().isEmpty()) {
+ isLabeled = true;
+ break;
+ }
+ }
+ if (!isLabeled && ss.length == 1) {
Preconditions.checkState(createMetric(ctx.getMeterEntity().getScopeType(), "", ctx));
AcceptableValue<Long> v = meterSystem.buildMetrics(metricName, Long.class);
- v.accept(ctx.getMeterEntity(), (long) ss[0].getValue());
+ v.accept(ctx.getMeterEntity(), getValue(ss[0]));
send(v, ss[0].getTimestamp());
return;
}
@@ -135,12 +142,22 @@ public class Analyzer {
AcceptableValue<DataTable> v = meterSystem.buildMetrics(metricName, DataTable.class);
DataTable dt = new DataTable();
for (Sample each : ss) {
- dt.put(composeGroup(each.getLabels()), (long) each.getValue());
+ dt.put(composeGroup(each.getLabels()), getValue(each));
}
v.accept(ctx.getMeterEntity(), dt);
send(v, ss[0].getTimestamp());
}
+ private long getValue(Sample sample) {
+ if (sample.getValue() <= 0.0) {
+ return 0L;
+ }
+ if (sample.getValue() < 1.0) {
+ return 1L;
+ }
+ return Math.round(sample.getValue());
+ }
+
private String composeGroup(ImmutableMap<String, String> labels) {
return composeGroup(labels, k -> true);
}
diff --git a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/SampleFamily.java b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/SampleFamily.java
index af8e463..ed861cf 100644
--- a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/SampleFamily.java
+++ b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/SampleFamily.java
@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.meter.analyzer.dsl;
+import com.google.common.base.CharMatcher;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
@@ -319,7 +320,8 @@ public class SampleFamily {
}
private String dim(List<String> labelKeys) {
- return labelKeys.stream().map(k -> samples[0].labels.getOrDefault(k, "")).collect(Collectors.joining("."));
+ String name = labelKeys.stream().map(k -> samples[0].labels.getOrDefault(k, "")).collect(Collectors.joining("."));
+ return CharMatcher.is('.').trimFrom(name);
}
private SampleFamily left(List<String> labelKeys) {
diff --git a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rule.java b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rule.java
index d3504b9..df3acf4 100644
--- a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rule.java
+++ b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rule.java
@@ -34,5 +34,6 @@ public class Rule {
private String metricsPath;
private StaticConfig staticConfig;
private String defaultMetricLevel;
+ private Boolean enabled = true;
private List<MetricsRule> metricsRules;
}
diff --git a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
index 3ba836e..96e26ae 100644
--- a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
+++ b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
@@ -59,6 +59,7 @@ public class Rules {
return null;
})
.filter(Objects::nonNull)
+ .filter(Rule::getEnabled)
.collect(Collectors.toList());
}
}
diff --git a/oap-server/server-bootstrap/src/main/resources/oc-rules/istio-controlplane.yaml b/oap-server/server-bootstrap/src/main/resources/oc-rules/istio-controlplane.yaml
new file mode 100644
index 0000000..145e6bc
--- /dev/null
+++ b/oap-server/server-bootstrap/src/main/resources/oc-rules/istio-controlplane.yaml
@@ -0,0 +1,117 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This will parse a textual representation of a duration. The formats
+# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
+# with days considered to be exactly 24 hours.
+# <p>
+# Examples:
+# <pre>
+# "PT20.345S" -- parses as "20.345 seconds"
+# "PT15M" -- parses as "15 minutes" (where a minute is 60 seconds)
+# "PT10H" -- parses as "10 hours" (where an hour is 3600 seconds)
+# "P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+# "P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes"
+# "P-6H3M" -- parses as "-6 hours and +3 minutes"
+# "-P6H3M" -- parses as "-6 hours and -3 minutes"
+# "-P-6H+3M" -- parses as "+6 hours and -3 minutes"
+# </pre>
+enabled: true
+defaultMetricLevel: service(['cluster', 'app'])
+metricsRules:
+ ## Resource usage
+ # Pilot Versions
+ - name: pilot_version
+ exp: istio_build.tagEqual('component', 'pilot').sum(['cluster', 'app', 'tag'])
+ # Memory
+ - name: virtual_memory
+ exp: process_virtual_memory_bytes.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: resident_memory
+ exp: process_resident_memory_bytes.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: go_alloc
+ exp: go_memstats_alloc_bytes.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: go_heap_inuse
+ exp: go_memstats_heap_inuse_bytes.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: go_stack_inuse
+ exp: go_memstats_stack_inuse_bytes.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ # CPU
+ - name: cpu
+ exp: (process_cpu_seconds_total * 100).tagEqual('app', 'istiod').sum(['cluster', 'app']).rate('PT1M')
+ # Goroutines
+ - name: go_goroutines
+ exp: go_goroutines.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ ## Pilot push info
+ # Pilot pushes
+ - name: pilot_xds_pushes
+ exp: pilot_xds_pushes.tagMatch('type', 'lds|cds|rds|eds').sum(['cluster', 'app', 'type']).irate()
+ # Pilot Errors
+ - name: pilot_xds_cds_reject
+ exp: pilot_xds_cds_reject.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_xds_eds_reject
+ exp: pilot_xds_eds_reject.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_xds_rds_reject
+ exp: pilot_xds_rds_reject.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_xds_lds_reject
+ exp: pilot_xds_lds_reject.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_xds_write_timeout
+ exp: pilot_xds_write_timeout.tagEqual('app', 'istiod').sum(['cluster', 'app']).rate('PT1M')
+ - name: pilot_total_xds_internal_errors
+ exp: pilot_total_xds_internal_errors.tagEqual('app', 'istiod').sum(['cluster', 'app']).rate('PT1M')
+ - name: pilot_total_xds_rejects
+ exp: pilot_total_xds_rejects.tagEqual('app', 'istiod').sum(['cluster', 'app']).rate('PT1M')
+ - name: pilot_xds_push_context_errors
+ exp: pilot_xds_push_context_errors.tagEqual('app', 'istiod').sum(['cluster', 'app']).rate('PT1M')
+ - name: pilot_xds_pushes_error
+ exp: pilot_xds_pushes.tagEqual('app', 'istiod').tagNotMatch('type', 'lds|cds|rds|eds').sum(['cluster', 'app', 'type']).rate('PT1M')
+ - name: pilot_xds_push_errors
+ exp: pilot_xds_push_errors.tagEqual('app', 'istiod').sum(['cluster', 'app', 'type']).rate('PT1M')
+ - name: pilot_xds_push_timeout
+ exp: pilot_xds_push_timeout.tagEqual('app', 'istiod').sum(['cluster', 'app']).rate('PT1M')
+ - name: pilot_xds_push_timeout_failures
+ exp: pilot_xds_push_timeout_failures.tagEqual('app', 'istiod').sum(['cluster', 'app']).rate('PT1M')
+ # Proxy Push Time
+ - name: pilot_proxy_push_percentile
+ exp: pilot_proxy_convergence_time.sum(['cluster', 'app', 'le']).rate('PT1M').histogram().histogram_percentile([50,90,99])
+ # Conflicts
+ - name: pilot_conflict_il
+ exp: pilot_conflict_inbound_listener.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_conflict_ol_http_tcp
+ exp: pilot_conflict_outbound_listener_http_over_current_tcp.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_conflict_ol_tcp_tcp
+ exp: pilot_conflict_outbound_listener_tcp_over_current_tcp.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_conflict_ol_tcp_http
+ exp: pilot_conflict_outbound_listener_tcp_over_current_http.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ # ADS Monitoring
+ - name: pilot_virt_services
+ exp: pilot_virt_services.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_services
+ exp: pilot_services.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ - name: pilot_xds
+ exp: pilot_xds.tagEqual('app', 'istiod').sum(['cluster', 'app'])
+ # Cluster with no known endpoints
+ - name: pilot_cluster_no_endpoints
+ exp: pilot_xds_eds_instances.tagEqual('app', 'istiod').tagNotMatch('cluster', '.+\\|.+').sum(['cluster', 'app', 'cluster'])
+
+ ## Webhooks
+ # Configuration Validation
+ - name: galley_validation_passed
+ exp: galley_validation_passed.sum(['cluster', 'app']).rate('PT1M')
+ - name: galley_validation_failed
+ exp: galley_validation_failed.sum(['cluster', 'app']).rate('PT1M')
+ # Sidecar Injection
+ - name: sidecar_injection_success_total
+ exp: sidecar_injection_success_total.sum(['cluster', 'app']).rate('PT1M')
+ - name: sidecar_injection_failure_total
+ exp: sidecar_injection_failure_total.sum(['cluster', 'app']).rate('PT1M')
diff --git a/oap-server/server-bootstrap/src/main/resources/ui-initialized-templates/istio.yml b/oap-server/server-bootstrap/src/main/resources/ui-initialized-templates/istio.yml
new file mode 100644
index 0000000..a247aa2
--- /dev/null
+++ b/oap-server/server-bootstrap/src/main/resources/ui-initialized-templates/istio.yml
@@ -0,0 +1,185 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# UI templates initialized file includes the default template when the SkyWalking OAP starts up at the first time.
+#
+# Also, SkyWalking would detect the existing templates in the database, once they are missing, all templates in this file
+# could be added automatically.
+
+templates:
+ - name: "Istio"
+ # The type includes DASHBOARD, TOPOLOGY_INSTANCE, TOPOLOGY_ENDPOINT.
+ # DASHBOARD type templates could have multiple definitions, by using different names.
+ # TOPOLOGY_INSTANCE, TOPOLOGY_ENDPOINT type templates should be defined once, as they are used in the topology page only.
+ type: "DASHBOARD"
+ # Configuration could be defined through UI, and use `export` to format in the standard JSON.
+ configuration: |-
+ [
+ {
+ "name": "Istio",
+ "type": "service",
+ "children": [
+ {
+ "name": "Control Plane",
+ "children": [
+ {
+ "width": 3,
+ "title": "Istio Versions",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "REGULAR_VALUE",
+ "metricName": "meter_pilot_version",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartArea"
+ },
+ {
+ "width": 3,
+ "title": "Memory",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "REGULAR_VALUE",
+ "metricName": "meter_virtual_memory,meter_resident_memory,meter_go_alloc,meter_go_heap_inuse,meter_go_stack_inuse",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartArea",
+ "unit": "MB",
+ "aggregation": "/",
+ "aggregationNum": "1048576"
+ },
+ {
+ "width": 3,
+ "title": "CPU",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "REGULAR_VALUE",
+ "metricName": "meter_cpu",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartArea",
+ "unit": "%"
+ },
+ {
+ "width": 3,
+ "title": "Goroutines",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "REGULAR_VALUE",
+ "metricName": "meter_go_goroutines",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartLine"
+ },
+ {
+ "width": "4",
+ "title": "Pilot pushes",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "LABELED_VALUE",
+ "metricName": "meter_pilot_xds_pushes",
+ "queryMetricType": "readLabeledMetricsValues",
+ "chartType": "ChartBar"
+ },
+ {
+ "width": "4",
+ "title": "Pilot Errors",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "UNKNOWN",
+ "metricName": "meter_pilot_xds_cds_reject,meter_pilot_xds_eds_reject,meter_pilot_xds_rds_reject,meter_pilot_xds_lds_reject,meter_pilot_xds_write_timeout,meter_pilot_total_xds_internal_errors,meter_pilot_total_xds_rejects,meter_pilot_xds_push_context_errors,meter_pilot_xds_pushes_error,meter_pilot_xds_push_errors,meter_pilot_xds_push_timeout,meter_pilot_xds_push_timeout_failures",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartArea"
+ },
+ {
+ "width": "4",
+ "title": "Proxy Push Time",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "LABELED_VALUE",
+ "metricName": "meter_pilot_proxy_push_percentile",
+ "queryMetricType": "readLabeledMetricsValues",
+ "chartType": "ChartArea",
+ "metricLabels": "50,90,99",
+ "labelsIndex": "50,90,99",
+ "unit": "%"
+ },
+ {
+ "width": "4",
+ "title": "Conflicts",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "REGULAR_VALUE",
+ "metricName": "meter_pilot_conflict_il,meter_pilot_conflict_ol_http_tcp,meter_pilot_conflict_ol_tcp_tcp,meter_pilot_conflict_ol_tcp_http",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartBar"
+ },
+ {
+ "width": "4",
+ "title": "ADS Monitoring",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "REGULAR_VALUE",
+ "metricName": "meter_pilot_virt_services,meter_pilot_services,meter_pilot_xds",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartArea"
+ },
+ {
+ "width": "4",
+ "title": "Cluster with no known endpoints",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "UNKNOWN",
+ "metricName": "meter_pilot_cluster_no_endpoints",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartArea"
+ },
+ {
+ "width": "6",
+ "title": "Configuration Validation",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": true,
+ "metricType": "REGULAR_VALUE",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartLine",
+ "metricName": "meter_galley_validation_passed,meter_galley_validation_failed"
+ },
+ {
+ "width": "6",
+ "title": "Sidecar Injection",
+ "height": 350,
+ "entityType": "Service",
+ "independentSelector": false,
+ "metricType": "REGULAR_VALUE",
+ "metricName": "meter_sidecar_injection_success_total",
+ "queryMetricType": "readMetricsValues",
+ "chartType": "ChartArea"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ # Activated as the DASHBOARD type, makes this templates added into the UI page automatically.
+ # False means providing a basic template, user needs to add it manually.
+ activated: true
+ # True means wouldn't show up on the dashboard. Only keeps the definition in the storage.
+ disabled: false
\ No newline at end of file
diff --git a/oap-server/server-fetcher-plugin/prometheus-fetcher-plugin/src/main/java/org/apache/skywalking/oap/server/fetcher/prometheus/provider/PrometheusFetcherProvider.java b/oap-server/server-fetcher-plugin/prometheus-fetcher-plugin/src/main/java/org/apache/skywalking/oap/server/fetcher/prometheus/provider/PrometheusFetcherProvider.java
index 437cabc..c8eeda4 100644
--- a/oap-server/server-fetcher-plugin/prometheus-fetcher-plugin/src/main/java/org/apache/skywalking/oap/server/fetcher/prometheus/provider/PrometheusFetcherProvider.java
+++ b/oap-server/server-fetcher-plugin/prometheus-fetcher-plugin/src/main/java/org/apache/skywalking/oap/server/fetcher/prometheus/provider/PrometheusFetcherProvider.java
@@ -22,6 +22,7 @@ import com.google.common.collect.Maps;
import io.vavr.CheckedFunction1;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
@@ -112,7 +113,9 @@ public class PrometheusFetcherProvider extends ModuleProvider {
long now = System.currentTimeMillis();
converter.toMeter(sc.getTargets().stream()
.map(CheckedFunction1.liftTry(target -> {
- String content = HttpClient.builder().url(target.getUrl()).caFilePath(target.getSslCaFilePath()).build().request();
+ URI url = new URI(target.getUrl());
+ URI targetURL = url.resolve(r.getMetricsPath());
+ String content = HttpClient.builder().url(targetURL.toString()).caFilePath(target.getSslCaFilePath()).build().request();
List<Metric> result = new ArrayList<>();
try (InputStream targetStream = new ByteArrayInputStream(content.getBytes(Charsets.UTF_8))) {
Parser p = Parsers.text(targetStream);
diff --git a/oap-server/server-receiver-plugin/opencensus-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/opencensus/OCMetricHandler.java b/oap-server/server-receiver-plugin/opencensus-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/opencensus/OCMetricHandler.java
index 28aad37..2f1a954 100644
--- a/oap-server/server-receiver-plugin/opencensus-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/opencensus/OCMetricHandler.java
+++ b/oap-server/server-receiver-plugin/opencensus-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/opencensus/OCMetricHandler.java
@@ -33,6 +33,7 @@ import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.oap.meter.analyzer.MetricConvert;
@@ -40,19 +41,20 @@ import org.apache.skywalking.oap.meter.analyzer.prometheus.PrometheusMetricConve
import org.apache.skywalking.oap.server.library.util.prometheus.metrics.Counter;
import org.apache.skywalking.oap.server.library.util.prometheus.metrics.Gauge;
import org.apache.skywalking.oap.server.library.util.prometheus.metrics.Histogram;
+import org.apache.skywalking.oap.server.library.util.prometheus.metrics.Metric;
import org.apache.skywalking.oap.server.library.util.prometheus.metrics.Summary;
@RequiredArgsConstructor
@Slf4j
public class OCMetricHandler extends MetricsServiceGrpc.MetricsServiceImplBase {
- private final PrometheusMetricConverter prometheusMetric;
+ private final List<PrometheusMetricConverter> metrics;
@Override public StreamObserver<ExportMetricsServiceRequest> export(
StreamObserver<ExportMetricsServiceResponse> responseObserver) {
return new StreamObserver<ExportMetricsServiceRequest>() {
@Override public void onNext(ExportMetricsServiceRequest request) {
- prometheusMetric.toMeter(request.getMetricsList().stream()
+ Stream<Metric> metricStream = request.getMetricsList().stream()
.flatMap(metric -> metric.getTimeseriesList().stream().map(timeSeries ->
Tuple.of(metric.getMetricDescriptor(),
buildLabels(metric.getMetricDescriptor().getLabelKeysList(), timeSeries.getLabelValuesList()),
@@ -80,7 +82,8 @@ public class OCMetricHandler extends MetricsServiceGrpc.MetricsServiceImplBase {
throw new UnsupportedOperationException("Unsupported OC type:" + t._1.getType());
}
}))
- .flatMap(tryIt -> MetricConvert.log(tryIt, "Convert OC metric to prometheus metric")));
+ .flatMap(tryIt -> MetricConvert.log(tryIt, "Convert OC metric to prometheus metric"));
+ metrics.forEach(m -> m.toMeter(metricStream));
}
@Override public void onError(Throwable throwable) {
diff --git a/oap-server/server-receiver-plugin/opencensus-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/opencensus/OCMetricReceiverProvider.java b/oap-server/server-receiver-plugin/opencensus-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/opencensus/OCMetricReceiverProvider.java
index 338175c..ae87dee 100644
--- a/oap-server/server-receiver-plugin/opencensus-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/opencensus/OCMetricReceiverProvider.java
+++ b/oap-server/server-receiver-plugin/opencensus-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/opencensus/OCMetricReceiverProvider.java
@@ -20,9 +20,8 @@ package org.apache.skywalking.oap.server.receiver.opencensus;
import java.util.List;
import java.util.Objects;
-import java.util.stream.Collectors;
import org.apache.skywalking.oap.meter.analyzer.prometheus.PrometheusMetricConverter;
-import org.apache.skywalking.oap.meter.analyzer.prometheus.rule.MetricsRule;
+import org.apache.skywalking.oap.meter.analyzer.prometheus.rule.Rule;
import org.apache.skywalking.oap.meter.analyzer.prometheus.rule.Rules;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.meter.MeterSystem;
@@ -35,11 +34,13 @@ import org.apache.skywalking.oap.server.library.server.ServerException;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCServer;
import org.apache.skywalking.oap.server.receiver.sharing.server.SharingServerModule;
+import static java.util.stream.Collectors.toList;
+
public class OCMetricReceiverProvider extends ModuleProvider {
public static final String NAME = "default";
private OCMetricReceiverConfig config;
private GRPCServer grpcServer = null;
- private List<MetricsRule> rules;
+ private List<Rule> rules;
@Override
public String name() {
@@ -62,9 +63,8 @@ public class OCMetricReceiverProvider extends ModuleProvider {
if (config.getGRPCPort() <= 0) {
return;
}
- rules = Rules.loadRules(config.getRulePath()).stream()
- .flatMap(rule -> rule.getMetricsRules().stream())
- .collect(Collectors.toList());
+ rules = Rules.loadRules(config.getRulePath());
+
grpcServer = new GRPCServer(config.getGRPCHost(), config.getGRPCPort());
if (config.getMaxMessageSize() > 0) {
grpcServer.setMaxMessageSize(config.getMaxMessageSize());
@@ -85,7 +85,9 @@ public class OCMetricReceiverProvider extends ModuleProvider {
public void start() throws ServiceNotProvidedException, ModuleStartException {
if (Objects.nonNull(grpcServer)) {
final MeterSystem service = getManager().find(CoreModule.NAME).provider().getService(MeterSystem.class);
- grpcServer.addHandler(new OCMetricHandler(new PrometheusMetricConverter(rules, null, service)));
+ grpcServer.addHandler(new OCMetricHandler(rules.stream().map(r ->
+ new PrometheusMetricConverter(r.getMetricsRules(), r.getDefaultMetricLevel(), service))
+ .collect(toList())));
}
}