Skip to content
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

Support to bind TLS status as a part of component for service topology. #10522

Merged
merged 11 commits into from
Mar 10, 2023
3 changes: 3 additions & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

* Fix wrong layer of metric `user error` in DynamoDB monitoring.
* ElasticSearch storage does not check field types when OAP running in `no-init` mode.
* Support to bind TLS status as a part of component for service topology.
* Fix component ID priority bug.
* Fix component ID of topology overlap due to storage layer bugs.

#### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public class Const {
public static final String POINT = ".";
public static final String DOUBLE_COLONS_SPLIT = "::";
public static final String BLANK_ENTITY_NAME = "_blank";

public static final class TLS_MODE {
public static final String NON_TLS = "NONE";

public static final String M_TLS = "mTLS";

public static final String TLS = "TLS";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected StorageID id0() {
@Override
public boolean combine(Metrics metrics) {
final ProcessRelationClientSideMetrics processRelationClientSideMetrics = (ProcessRelationClientSideMetrics) metrics;
if (!ComponentLibraryCatalogUtil.get().compare(this.componentId, processRelationClientSideMetrics.getComponentId())) {
if (ComponentLibraryCatalogUtil.get().compare(this.componentId, processRelationClientSideMetrics.getComponentId())) {
this.setComponentId(processRelationClientSideMetrics.getComponentId());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected StorageID id0() {
@Override
public boolean combine(Metrics metrics) {
final ProcessRelationServerSideMetrics processRelationServerSideMetrics = (ProcessRelationServerSideMetrics) metrics;
if (!ComponentLibraryCatalogUtil.get().compare(this.componentId, processRelationServerSideMetrics.getComponentId())) {
if (ComponentLibraryCatalogUtil.get().compare(this.componentId, processRelationServerSideMetrics.getComponentId())) {
this.setComponentId(processRelationServerSideMetrics.getComponentId());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

package org.apache.skywalking.oap.server.core.analysis.manual.relation.service;

import java.util.Optional;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
import org.apache.skywalking.oap.server.core.analysis.metrics.IntList;
import org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
import org.apache.skywalking.oap.server.core.source.ServiceRelation;
import org.apache.skywalking.oap.server.library.util.StringUtil;

public class ServiceCallRelationDispatcher implements SourceDispatcher<ServiceRelation> {

@Override
public void dispatch(ServiceRelation source) {
switch (source.getDetectPoint()) {
Expand All @@ -41,7 +44,9 @@ private void serverSide(ServiceRelation source) {
metrics.setTimeBucket(source.getTimeBucket());
metrics.setSourceServiceId(source.getSourceServiceId());
metrics.setDestServiceId(source.getDestServiceId());
metrics.getComponentIds().add(source.getComponentId());
final IntList componentIds = metrics.getComponentIds();
componentIds.add(source.getComponentId());
tlsStatus(source.getTlsMode()).ifPresent(componentIds::add);
metrics.setEntityId(source.getEntityId());
MetricsStreamProcessor.getInstance().in(metrics);
}
Expand All @@ -51,8 +56,27 @@ private void clientSide(ServiceRelation source) {
metrics.setTimeBucket(source.getTimeBucket());
metrics.setSourceServiceId(source.getSourceServiceId());
metrics.setDestServiceId(source.getDestServiceId());
metrics.getComponentIds().add(source.getComponentId());
final IntList componentIds = metrics.getComponentIds();
componentIds.add(source.getComponentId());
tlsStatus(source.getTlsMode()).ifPresent(componentIds::add);
metrics.setEntityId(source.getEntityId());
MetricsStreamProcessor.getInstance().in(metrics);
}

private Optional<Integer> tlsStatus(String tlsMode) {
if (StringUtil.isBlank(tlsMode)) {
return Optional.empty();
}
switch (tlsMode) {
case Const.TLS_MODE.M_TLS:
// component ID, mtls = 142
return Optional.of(142);
case Const.TLS_MODE.TLS:
// component ID, tls = 130
return Optional.of(130);
case Const.TLS_MODE.NON_TLS:
default:
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

package org.apache.skywalking.oap.server.core.analysis.manual.relation.service;

import java.util.Optional;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
import org.apache.skywalking.oap.server.core.analysis.metrics.IntList;
import org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
import org.apache.skywalking.oap.server.core.source.TCPServiceRelation;
import org.apache.skywalking.oap.server.library.util.StringUtil;

public class TCPServiceCallRelationDispatcher implements SourceDispatcher<TCPServiceRelation> {

Expand All @@ -41,7 +45,9 @@ private void serverSide(TCPServiceRelation source) {
metrics.setTimeBucket(source.getTimeBucket());
metrics.setSourceServiceId(source.getSourceServiceId());
metrics.setDestServiceId(source.getDestServiceId());
metrics.getComponentIds().add(source.getComponentId());
final IntList componentIds = metrics.getComponentIds();
componentIds.add(source.getComponentId());
tlsStatus(source.getTlsMode()).ifPresent(componentIds::add);
metrics.setEntityId(source.getEntityId());
MetricsStreamProcessor.getInstance().in(metrics);
}
Expand All @@ -51,8 +57,27 @@ private void clientSide(TCPServiceRelation source) {
metrics.setTimeBucket(source.getTimeBucket());
metrics.setSourceServiceId(source.getSourceServiceId());
metrics.setDestServiceId(source.getDestServiceId());
metrics.getComponentIds().add(source.getComponentId());
final IntList componentIds = metrics.getComponentIds();
componentIds.add(source.getComponentId());
tlsStatus(source.getTlsMode()).ifPresent(componentIds::add);
metrics.setEntityId(source.getEntityId());
MetricsStreamProcessor.getInstance().in(metrics);
}

private Optional<Integer> tlsStatus(String tlsMode) {
if (StringUtil.isBlank(tlsMode)) {
return Optional.empty();
}
switch (tlsMode) {
case Const.TLS_MODE.M_TLS:
// component ID, mtls = 142
return Optional.of(142);
case Const.TLS_MODE.TLS:
// component ID, tls = 130
return Optional.of(130);
case Const.TLS_MODE.NON_TLS:
default:
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ private void init() throws InitialComponentCatalogException {
public boolean compare(int componentA, int componentB) {
final Integer priorityA = componentIDPriorities.getOrDefault(componentA, 50);
final Integer priorityB = componentIDPriorities.getOrDefault(componentB, 50);
return priorityA.compareTo(priorityB) > 0;
return priorityA.compareTo(priorityB) < 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.
*
*/

package org.apache.skywalking.oap.server.core;

import com.google.common.collect.Maps;
import java.util.Map;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.module.ModuleNotFoundRuntimeException;
import org.apache.skywalking.oap.server.library.module.ModuleProviderHolder;

public abstract class MockModuleManager extends ModuleManager {
private final Map<String, ModuleProviderHolder> moduleProviderHolderMap = Maps.newHashMap();

public MockModuleManager() {
init();
}

protected abstract void init();

protected void register(String name, ModuleProviderHolder provider) {
moduleProviderHolderMap.put(name, provider);
}

@Override
public boolean has(String moduleName) {
return moduleProviderHolderMap.containsKey(moduleName);
}

@Override
public ModuleProviderHolder find(String moduleName) throws ModuleNotFoundRuntimeException {
if (!moduleProviderHolderMap.containsKey(moduleName)) {
throw new ModuleNotFoundRuntimeException("ModuleProviderHolder[" + moduleName + "] cannot found in MOCK.");
}
return moduleProviderHolderMap.get(moduleName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.
*
*/

package org.apache.skywalking.oap.server.core;

import com.google.common.collect.Maps;
import java.util.Map;
import org.apache.skywalking.oap.server.library.module.ModuleServiceHolder;
import org.apache.skywalking.oap.server.library.module.Service;
import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException;

public abstract class MockModuleProvider implements ModuleServiceHolder {
protected Map<Class<? extends Service>, Service> serviceMap = Maps.newHashMap();

public MockModuleProvider() {
register();
}

protected abstract void register();

@Override
public void registerServiceImplementation(final Class<? extends Service> serviceType,
final Service service) throws ServiceNotProvidedException {
serviceMap.put(serviceType, service);
}

@Override
public <T extends Service> T getService(final Class<T> serviceType) throws ServiceNotProvidedException {
return (T) serviceMap.get(serviceType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public void testInitAndSettings() {
@Test
public void testPriority() {
ComponentLibraryCatalogService service = new ComponentLibraryCatalogService();
Assertions.assertEquals(false, service.compare(service.getComponentId("Unknown"), service.getComponentId("tcp")));
Assertions.assertEquals(false, service.compare(service.getComponentId("tcp"), service.getComponentId("tls")));
Assertions.assertEquals(false, service.compare(service.getComponentId("tls"), service.getComponentId("rpc")));
Assertions.assertEquals(false, service.compare(service.getComponentId("rpc"), service.getComponentId("http")));
Assertions.assertEquals(false, service.compare(service.getComponentId("http"), service.getComponentId("https")));
Assertions.assertEquals(false, service.compare(service.getComponentId("https"), service.getComponentId("SpringMVC")));
Assertions.assertEquals(true, service.compare(service.getComponentId("Unknown"), service.getComponentId("tcp")));
Assertions.assertEquals(true, service.compare(service.getComponentId("tcp"), service.getComponentId("tls")));
Assertions.assertEquals(true, service.compare(service.getComponentId("tcp"), service.getComponentId("mtls")));
Assertions.assertEquals(true, service.compare(service.getComponentId("tls"), service.getComponentId("rpc")));
Assertions.assertEquals(true, service.compare(service.getComponentId("rpc"), service.getComponentId("http")));
Assertions.assertEquals(true, service.compare(service.getComponentId("http"), service.getComponentId("https")));
Assertions.assertEquals(true, service.compare(service.getComponentId("https"), service.getComponentId("SpringMVC")));

// Equal priority
Assertions.assertEquals(false, service.compare(service.getComponentId("Dubbo"), service.getComponentId("SpringMVC")));
Expand Down
Loading