Skip to content

Commit

Permalink
Merge pull request #2794 from seriouszyx/trace/jaeger
Browse files Browse the repository at this point in the history
[ISSUE #2788] Add Jaeger tracing plugin config
  • Loading branch information
xwm1992 authored Jan 3, 2023
2 parents a14ab25 + f46bfe6 commit b925c87
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ subprojects {
dependency 'io.prometheus:simpleclient_httpserver:0.8.1'
dependency 'io.opentelemetry:opentelemetry-exporter-zipkin:1.3.0'
dependency 'io.opentelemetry:opentelemetry-semconv:1.3.0-alpha'
dependency 'io.opentelemetry:opentelemetry-exporter-jaeger:1.20.1'

dependency "io.openmessaging:openmessaging-api:2.2.1-pubsub"

Expand Down
35 changes: 35 additions & 0 deletions eventmesh-trace-plugin/eventmesh-trace-jaeger/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.
*/

dependencies {
implementation project(":eventmesh-trace-plugin:eventmesh-trace-api")
implementation project(":eventmesh-common")
implementation 'org.slf4j:slf4j-api'
implementation 'org.apache.commons:commons-lang3'
implementation 'com.google.guava:guava'

implementation 'io.opentelemetry:opentelemetry-exporter-jaeger'
implementation 'io.opentelemetry:opentelemetry-semconv'

compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'

testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
testImplementation "org.mockito:mockito-core"
testImplementation "org.mockito:mockito-inline"
}
19 changes: 19 additions & 0 deletions eventmesh-trace-plugin/eventmesh-trace-jaeger/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# 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.
#

pluginType=trace
pluginName=jaeger
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.eventmesh.trace.jaeger;

import org.apache.eventmesh.trace.api.EventMeshTraceService;
import org.apache.eventmesh.trace.api.exception.TraceException;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;

public class JaegerTraceService implements EventMeshTraceService {

@Override
public void init() throws TraceException {

}

@Override
public Context extractFrom(Context context, Map<String, Object> carrier) throws TraceException {
return null;
}

@Override
public void inject(Context context, Map<String, Object> carrier) {

}

@Override
public Span createSpan(String spanName, SpanKind spanKind, long startTimestamp, TimeUnit timeUnit, Context context,
boolean isSpanFinishInOtherThread) throws TraceException {
return null;
}

@Override
public Span createSpan(String spanName, SpanKind spanKind, Context context, boolean isSpanFinishInOtherThread) throws TraceException {
return null;
}

@Override
public void shutdown() throws TraceException {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.eventmesh.trace.jaeger.common;

public class JaegerConstants {

public static final String SERVICE_NAME = "eventmesh_trace";

public static final String KEY_JAEGER_IP = "eventmesh.trace.jaeger.ip";

public static final String KEY_JAEGER_PORT = "eventmesh.trace.jaeger.port";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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.eventmesh.trace.jaeger.config;

import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.utils.PropertiesUtils;
import org.apache.eventmesh.trace.jaeger.common.JaegerConstants;

import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

import com.google.common.base.Preconditions;

import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@UtilityClass
public class JaegerConfiguration {

private static final String CONFIG_FILE = "jaeger.properties";

private static final Properties PROPERTIES = new Properties();

private String eventMeshJaegerIp = "localhost";

private int eventMeshJaegerPort = 14250;

static {
loadProperties();
initializeConfig();
}

private void loadProperties() {
URL resource = JaegerConfiguration.class.getClassLoader().getResource(CONFIG_FILE);
if (resource != null) {
try (InputStream inputStream = resource.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
if (inputStream.available() > 0) {
PROPERTIES.load(reader);
}
} catch (IOException e) {
throw new RuntimeException("Load zipkin.properties file from classpath error", e);
}
}
// get from config home
try {
String configPath = Constants.EVENTMESH_CONF_HOME + File.separator + CONFIG_FILE;
PropertiesUtils.loadPropertiesWhenFileExist(PROPERTIES, configPath);
} catch (IOException e) {
throw new IllegalArgumentException("Cannot load jaeger.properties file from conf", e);
}
}

private void initializeConfig() {
String jaegerIp = PROPERTIES.getProperty(JaegerConstants.KEY_JAEGER_IP);
Preconditions.checkState(StringUtils.isNotEmpty(jaegerIp),
String.format("%s error", JaegerConstants.KEY_JAEGER_IP));
eventMeshJaegerIp = StringUtils.deleteWhitespace(jaegerIp);

String jaegerPort = PROPERTIES.getProperty(JaegerConstants.KEY_JAEGER_PORT);
if (StringUtils.isNotEmpty(jaegerPort)) {
eventMeshJaegerPort = Integer.parseInt(StringUtils.deleteWhitespace(jaegerPort));
}
}

public static String getEventMeshJaegerIp() {
return eventMeshJaegerIp;
}

public static int getEventMeshJaegerPort() {
return eventMeshJaegerPort;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.eventmesh.trace.jaeger.config;

import org.junit.Assert;
import org.junit.Test;

public class JaegerConfigurationTest {

@Test
public void testGetConfiguration() {
Assert.assertEquals("localhost", JaegerConfiguration.getEventMeshJaegerIp());
Assert.assertEquals(14250, JaegerConfiguration.getEventMeshJaegerPort());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# 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.
#

eventmesh.trace.jaeger.ip=localhost
eventmesh.trace.pinpoint.port=14250
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ include 'eventmesh-trace-plugin'
include 'eventmesh-trace-plugin:eventmesh-trace-api'
include 'eventmesh-trace-plugin:eventmesh-trace-zipkin'
include 'eventmesh-trace-plugin:eventmesh-trace-pinpoint'
include 'eventmesh-trace-plugin:eventmesh-trace-jaeger'


include 'eventmesh-webhook'
Expand Down

0 comments on commit b925c87

Please sign in to comment.