Skip to content

Commit

Permalink
Merge pull request #1 from Microsoft/master
Browse files Browse the repository at this point in the history
pull lastest from Microsoft master
  • Loading branch information
littleaj authored Mar 11, 2019
2 parents a602c46 + e78f5e5 commit 4ebdcdc
Show file tree
Hide file tree
Showing 31 changed files with 791 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ private void addMethods(ClassInstrumentationData classData, Element eClassNode)
}

public Element getTopTag(File configurationFile) throws ParserConfigurationException, IOException, SAXException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
dBuilder = dbFactory.newDocumentBuilder();
DocumentBuilder dBuilder = createDocumentBuilder();
Document doc = dBuilder.parse(configurationFile);
doc.getDocumentElement().normalize();

Expand All @@ -459,4 +457,13 @@ public Element getTopTag(File configurationFile) throws ParserConfigurationExcep
Element topElementTag = (Element)topNodeTag;
return topElementTag;
}

private DocumentBuilder createDocumentBuilder() throws ParserConfigurationException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
// mitigates CWE-611: https://cwe.mitre.org/data/definitions/611.html
dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbFactory.setXIncludeAware(false);
dbFactory.setExpandEntityReferences(false);
return dbFactory.newDocumentBuilder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TelemetryChannel fetch() {
}

private final TelemetryConfiguration configuration;
private TelemetryContext context;
private volatile TelemetryContext context;
private TelemetryChannel channel;

private static final Object TELEMETRY_STOP_HOOK_LOCK = new Object();
Expand Down
5 changes: 4 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ include ':test:smoke:framework:fakeIngestion:servlet'
include ':test:smoke:framework:fakeIngestion:standalone'

include ':test:smoke:testApps:PerfTestApp'
include ':test:smoke:testApps:PerfTestAppSpringBoot'
//include ':test:smoke:testApps:SimpleCalculator'
include ':test:smoke:testApps:CachingCalculator'
include ':test:smoke:testApps:CoreAndFilter'
Expand All @@ -59,11 +60,13 @@ include ':test:smoke:testApps:TraceLog4j1_2'
include ':test:smoke:testApps:TraceLogBack'
include ':test:smoke:testApps:TraceLog4j2'
include ':test:smoke:testApps:HeartBeat'
include ':test:smoke:testApps:SpringBootTest'
include ':test:smoke:testApps:FixedRateSampling'

if (System.env.'COLLECTD_HOME') {
include 'collectd'
}

include ':test:smoke:testApps:SpringBootTest'



Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ public Envelope nextItem() {

public int getCountForType(String type) {
Preconditions.checkNotNull(type, "type");
return getItemsByType(type).size();
return getItemsEnvelopeDataType(type).size();
}

public List<Envelope> getItemsByType(String type) {
public List<Envelope> getItemsEnvelopeDataType(String type) {
return this.servlet.getItemsByType(type);
}

public <T extends Domain> List<T> getTelemetryDataByType(String type) {
Preconditions.checkNotNull(type, "type");
List<Envelope> items = getItemsByType(type);
List<Envelope> items = getItemsEnvelopeDataType(type);
List<T> dataItems = new ArrayList<T>();
for (Envelope e : items) {
Data<T> dt = (Data<T>) e.getData();
Expand All @@ -87,7 +87,7 @@ public <T extends Domain> List<T> getTelemetryDataByType(String type) {
}

public <T extends Domain> T getBaseDataForType(int index, String type) {
Data<T> data = (Data<T>) getItemsByType(type).get(index).getData();
Data<T> data = (Data<T>) getItemsEnvelopeDataType(type).get(index).getData();
return data.getBaseData();
}

Expand Down
23 changes: 23 additions & 0 deletions test/smoke/testApps/FixedRateSampling/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apply plugin: 'war'

dependencies {
compile aiCoreJar
compile aiWebJar
compile 'com.google.guava:guava:20.0'

providedCompile 'javax.servlet:javax.servlet-api:3.0.1'

providedRuntime 'mysql:mysql-connector-java:5.1.44'

smokeTestCompile 'com.google.guava:guava:23.0'

testCompile 'com.google.guava:guava:23.0' // VSCODE intellisense bug workaround
}

compileJava.sourceCompatibility = 1.7
compileJava.targetCompatibility = 1.7
compileSmokeTestJava.sourceCompatibility = 1.8
compileSmokeTestJava.targetCompatibility = 1.8

ext.testAppArtifactDir = war.destinationDir
ext.testAppArtifactFilename = war.archiveName
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.microsoft.ajl.simplecalc;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(description = "smoke test health check", urlPatterns = { "/" })
public class HealthCheckServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().println("OK");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.microsoft.ajl.simplecalc;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletFuncs {

protected static void getRenderedHtml(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
renderHtml(request, response.getWriter());
}

private static void renderHtml(HttpServletRequest req, PrintWriter writer) {
writer.println("<html>");
writer.println("<head><title>Calculation Result</title></head>");
writer.println("<body>");
writer.printf("<h1>%s</h1>", req.getRequestURI());
writer.println("<h2>OK!</h2>");
writer.println("</body></html>");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.microsoft.ajl.simplecalc;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.telemetry.EventTelemetry;

/**
* Servlet implementation class SimpleFixedRateSamplingServlet
*/
@WebServlet(description = "sends 100 event telemetry items with different op ids", urlPatterns = { "/fixedRateSampling" })
public class SimpleFixedRateSamplingServlet extends HttpServlet {
private static final long serialVersionUID = -5889330779672565409L;
private TelemetryClient client = new TelemetryClient();

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletFuncs.getRenderedHtml(request, response);
client.trackTrace("Trace Test.");
for (int i = 0; i < 100; i++) {
String str = String.format("Event Test %s", i);
EventTelemetry et = new EventTelemetry(str);
et.getContext().getOperation().setId(String.valueOf(i));
client.trackEvent(et);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">


<!-- The key from the portal: -->

<InstrumentationKey>00000000-0000-0000-0000-0FEEDDADBEEF</InstrumentationKey>

<SDKLogger type="CONSOLE">
<enabled>true</enabled>
<UniquePrefix>JavaSDKLog</UniquePrefix>
</SDKLogger>

<!-- HTTP request component (not required for bare API) -->

<TelemetryModules>
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule" />
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebSessionTrackingTelemetryModule" />
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebUserTrackingTelemetryModule" />
</TelemetryModules>

<!-- Events correlation (not required for bare API) -->
<!-- These initializers add context data to each event -->

<TelemetryInitializers>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationIdTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationNameTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebSessionTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserAgentTelemetryInitializer" />
</TelemetryInitializers>

<Channel>
<!-- <EndpointAddress>http://localhost:60606/v2/track</EndpointAddress> -->
<EndpointAddress>http://fakeingestion:60606/v2/track</EndpointAddress>
</Channel>

<PerformanceCounters>
<UseBuiltIn>False</UseBuiltIn>
</PerformanceCounters>

<TelemetryProcessors>
<BuiltInProcessors>
<Processor type="FixedRateSamplingTelemetryProcessor">
<Add name="SamplingPercentage" value="50" />
<ExcludedTypes>
<ExcludedType>Request</ExcludedType>
</ExcludedTypes>
<IncludedTypes>
<IncludedType>Event</IncludedType>
</IncludedTypes>
</Processor>
</BuiltInProcessors>
</TelemetryProcessors>
</ApplicationInsights>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="SimpleCalculator_1" version="3.0">
<display-name>SimpleTelemetry</display-name>
<filter>
<filter-name>ApplicationInsightsWebFilter</filter-name>
<filter-class>com.microsoft.applicationinsights.web.internal.WebRequestTrackingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ApplicationInsightsWebFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.microsoft.applicationinsights.smoketest;

import com.microsoft.applicationinsights.internal.schemav2.Envelope;
import org.junit.*;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

public class FixedRateSamplingTest extends AiSmokeTest {
@Test
@TargetUri("/fixedRateSampling")
public void testFixedRateSamplingInExcludedTypes() {
assertEquals(1, mockedIngestion.getCountForType("RequestData"));
assertEquals(100.0, getSampleRate("RequestData", 0), Math.ulp(50.0));
}

@Test
@TargetUri(value = "/fixedRateSampling", delay = 10000)
public void testFixedRateSamplingInIncludedTypes() {
int count = mockedIngestion.getCountForType("EventData");
assertThat(count, both(greaterThanOrEqualTo(40)).and(lessThanOrEqualTo(60)));
assertEquals(50.0, getSampleRate("EventData", 0), Math.ulp(50.0));
}

@Test
@TargetUri("/fixedRateSampling")
public void testFixedRateSamplingNotInExcludedTypes() {
assertEquals(1, mockedIngestion.getCountForType("MessageData"));
assertEquals(100.0, getSampleRate("MessageData", 0), Math.ulp(50.0));
}

protected double getSampleRate(String type, int index) {
Envelope envelope = mockedIngestion.getItemsByType(type).get(index);
return envelope.getSampleRate();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jbosseap6
jbosseap7
tomcat7
tomcat8
tomcat85
jetty9
48 changes: 48 additions & 0 deletions test/smoke/testApps/PerfTestAppSpringBoot/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.19.RELEASE'
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'

compileJava.sourceCompatibility = 1.7
compileJava.targetCompatibility = 1.7
compileSmokeTestJava.sourceCompatibility = 1.8
compileSmokeTestJava.targetCompatibility = 1.8

dependencies {
compile springBootStarterJar
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat'
compile 'com.google.guava:guava:20.0'
compile 'org.apache.httpcomponents:httpclient:4.5.3'

compileOnly 'org.apache.tomcat.embed:tomcat-embed-jasper'
compile 'javax.servlet:jstl'

compile project(':test:smoke:framework:testCases')

providedCompile 'javax.servlet:javax.servlet-api:3.0.1'

providedRuntime 'mysql:mysql-connector-java:5.1.44'

smokeTestCompile 'com.google.guava:guava:23.0'
testCompile 'com.google.guava:guava:23.0' // VSCODE intellisense bug workaround

testCompile group: 'junit', name: 'junit', version: '4.12'
}

configurations {
smokeTestCompile.exclude group:'org.springframework.boot'
smokeTestRuntime.exclude group:'org.springframework.boot'
}

ext.testAppArtifactDir = war.destinationDir
ext.testAppArtifactFilename = war.archiveName
Loading

0 comments on commit 4ebdcdc

Please sign in to comment.