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

added tests to run as merge check on Zipkin #227

Merged
merged 18 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/webserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ jobs:
with:
name: opentelemetry-webserver-sdk-x64-linux.tgz
path: /tmp/apache_centos7/opentelemetry-webserver-sdk-x64-linux.tgz
- name: run integrationtest
run: |
docker rm -f apache_centos7_container
cd instrumentation/otel-webserver-module
docker-compose --profile centos7 up -d
docker ps -a
sleep 30
./gradlew :test:integration:integrationTests -i

webserver-build-test-centos6:
name: webserver-centos6-build
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/otel-webserver-module/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ services:
- centos_nginx
- centos7_nginx
- ubuntu20.04_nginx
command: ["--config=/etc/otel-config.yml", "${OTELCOL_ARGS}"]
command: ["--config=/etc/otel-config.yml"]
volumes:
- ./otel-config.yml:/etc/otel-config.yml
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ApacheModuleEnabled ON

#ApacheModule Otel Exporter details
ApacheModuleOtelSpanExporter otlp
ApacheModuleOtelExporterEndpoint docker.for.mac.localhost:4317
ApacheModuleOtelExporterEndpoint collector:4317

# SSL Certificates
#ApacheModuleOtelSslEnabled ON
Expand Down
5 changes: 5 additions & 0 deletions instrumentation/otel-webserver-module/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rootProject.name = 'otel-webserver-module'

include 'test:integration'
findProject(':test:integration')?.name = 'integration'

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'java'
}

version '1.0'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.projectlombok:lombok:1.18.16'
implementation 'org.testng:testng:7.1.0'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.13.2'
implementation group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1.1'
testImplementation group: 'io.rest-assured', name: 'rest-assured', version: '4.5.1'
testImplementation group: 'org.testng', name: 'testng', version: '6.14.3'
testImplementation group: 'io.rest-assured', name: 'json-schema-validator', version: '4.3.0'
implementation group: 'org.json', name: 'json', version: '20160810'

}

task integrationTests(type: Test) {
useTestNG() {
useDefaultListeners = true
suites 'src/test/resources/testngsuites/testng.xml'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package restutils;

import io.restassured.RestAssured;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;

import static utils.Constants.WEBSERVER_URL;
import static utils.Constants.ZIPKIN_URL;

public class BaseTest {

private String ZIPKIN_SERVICE_NAME = "zipkin";
private LoadGenUtils loadGenUtils = new LoadGenUtils();

@BeforeSuite
public void setup() {
RestAssured.baseURI = ZIPKIN_URL;
}

@BeforeClass
public void generateLoad(){
loadGenUtils.generateLoad(WEBSERVER_URL, 90);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package restutils;

import io.restassured.RestAssured;

public class LoadGenUtils {

public void generateLoad(String Uri, int count) {
while(count > 0){
RestAssured.given().get(Uri);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
count --;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package restutils;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import static io.restassured.RestAssured.given;

public class RestClient {

public static Response getResponse(String Uri){
given().when().get(Uri).then().log()
.all()
.assertThat()
.statusCode(200);

return RestAssured.given().get(Uri);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package restutils;

import io.restassured.response.Response;
import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Assert;
import java.util.logging.Logger;
import static utils.Constants.*;


public class ValidationUtils extends BaseTest{

private static final Logger LOGGER = Logger.getLogger(ValidationUtils.class.getName());
public RestClient restClient = new RestClient();
public Response response;

public void valiateResponseWithKey(Response response, String key) {

}

public void verifyAllTraces() {
response = restClient.getResponse(ZIPKIN_URL + TRACES);
LOGGER.info(response.body().asString());
JSONArray jsonArray = new JSONArray(response.getBody().asString());
for(int i=0; i<jsonArray.length(); i++) {
JSONArray traceArray = jsonArray.getJSONArray(i);
for (int j=0; j<traceArray.length(); j++){
JSONObject span = traceArray.getJSONObject(j);
if(span.get("name").toString().contentEquals("/")){
Assert.assertTrue(span.get("kind").toString().contentEquals("SERVER"));
} else {
Assert.assertTrue(span.get("kind").toString().contentEquals("CLIENT"));
}
Assert.assertTrue(span.getJSONObject("tags").get("service.namespace").toString().contentEquals("sample_namespace"));
Assert.assertTrue(span.getJSONObject("localEndpoint").get("serviceName").toString().contentEquals("demoservice"));
Assert.assertTrue(span.getJSONObject("tags").get("telemetry.sdk.language").toString().contentEquals("Apache"));
}
}

}

public void verifyAllSpans() {
response = restClient.getResponse(ZIPKIN_URL + SPANS);
String spans = response.jsonPath().get("$").toString();
System.out.println(spans);
LOGGER.info(spans);
JSONArray jsonArray = new JSONArray(response.getBody().asString());
for(int i=0; i<jsonArray.length(); i++) {
if(i==0){
Assert.assertTrue(jsonArray.getString(i).contentEquals("/"));
}
else if(i==1){
Assert.assertTrue(jsonArray.getString(i).contentEquals("mod_proxy.c_handler"));
}
else if(i==2){
Assert.assertTrue(jsonArray.getString(i).contentEquals("mod_proxy_balancer.c_handler"));
} else {
Assert.assertTrue(false);
}
}
}

public void verifyAllServices() {
response = restClient.getResponse(ZIPKIN_URL + SERVICES);
LOGGER.info(response.body().jsonPath().get().toString());
JSONArray jsonArray = new JSONArray(response.getBody().asString());
Assert.assertTrue(jsonArray.getString(0).contentEquals("demoservice"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package utils;

public class Constants {

public static final String TRACES= "/traces?lookback=1800000&limit=9";
public static final String SERVICES= "/services";
public static final String SPANS= "/spans?serviceName=demoservice";

private static final String HTTP_PROTOCOL = "http";
private static final String BASE_URL="localhost:9411/api/v2";
public static final String ZIPKIN_URL = HTTP_PROTOCOL + "://" + BASE_URL;
public static final String WEBSERVER_URL="http://localhost:9004/";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package utils;

import com.google.gson.JsonArray;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.Iterator;

public class JsonUtils {

public void validateComplexJson(JSONObject json, String key) {
boolean exists = json.has(key);
Iterator<?> keys;
String nextKeys;

if(!exists) {
keys = json.keys();
while(keys.hasNext()){
nextKeys = (String)keys.next();
try{
if(json.get(nextKeys) instanceof JSONObject) {
if(!exists) {
validateComplexJson(json.getJSONObject(nextKeys), key);
} else if (json.get(nextKeys) instanceof JsonArray) {
JSONArray jsonArray = json.getJSONArray(nextKeys);
for(int i=0; i<jsonArray.length(); i++) {
String jsonArrayString = jsonArray.get(i).toString();
JSONObject innerJson = new JSONObject(jsonArrayString);
if (!exists) {
validateComplexJson(innerJson, key);
}
}
}
}
} catch (Exception e) {

}
}
} else {
parseObject(json, key);
}
}

public void parseObject(JSONObject json, String key) {
System.out.println(json.get(key));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package zipkin;

import org.testng.annotations.Test;
import restutils.BaseTest;
import restutils.ValidationUtils;

public class TraceCreationTest extends BaseTest {
ValidationUtils validationUtils = new ValidationUtils();

@Test
public void checkServiceName() throws Exception {
validationUtils.verifyAllServices();

}

@Test
public void checkSpans() throws Exception {
validationUtils.verifyAllSpans();
}

@Test()
public void testTraceAndSpansCreation() throws Exception {
validationUtils.verifyAllTraces();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version = "1.0"encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name = "Zipkin-Test">
<test name = "TraceCreation Tests">
<classes>
<class name = "zipkin.TraceCreationTest"/>
</classes>
</test>
</suite>