Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.
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
5 changes: 5 additions & 0 deletions adoptopenjdk-api-v3-frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<artifactId>jackson-datatype-jsr353</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-core</artifactId>
<version>2.6.2-BETA</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package net.adoptopenjdk.api.v3.metrics

import com.microsoft.applicationinsights.TelemetryClient
import com.microsoft.applicationinsights.telemetry.RequestTelemetry
import org.eclipse.microprofile.metrics.annotation.Timed
import java.io.File
import java.io.FileOutputStream
import java.nio.file.Files
import java.nio.file.Path
import java.util.*
import javax.annotation.Priority
import javax.interceptor.AroundInvoke
import javax.interceptor.Interceptor
import javax.interceptor.InvocationContext
import javax.ws.rs.WebApplicationException
import javax.ws.rs.core.Response

@Timed
@Suppress("unused")
@Interceptor
@Priority(Interceptor.Priority.LIBRARY_BEFORE + 10)
class AppInsightsInterceptor {
private val telemetryClient: TelemetryClient

init {
telemetryClient = loadTelemetryClient()
}

private fun loadTelemetryClient(): TelemetryClient {
val path = saveConfigToFile()
try {
return TelemetryClient()
} finally {
val tmpDir = System.getProperty("java.io.tmpdir")
val isTmpDir = path?.startsWith(tmpDir)
if (isTmpDir != null && isTmpDir) {
path.toFile().deleteRecursively()
}
}
}

// Unfortunate hack to get around that we seem unable to load ApplicationInsights.xml from the classpath
// from inside the module
private fun saveConfigToFile(): Path? {
val inputStream = AppInsightsInterceptor::class.java.classLoader.getResourceAsStream("ApplicationInsights.xml")

inputStream?.use {
val configPath = Files.createTempDirectory("appInsightsConfig").toAbsolutePath()
val configFile = File(configPath.toString(), "ApplicationInsights.xml")
configFile.deleteOnExit()
configPath.toFile().deleteOnExit()
System.setProperty("applicationinsights.configurationDirectory", configPath.toString())

val outputStream = FileOutputStream(configFile)

outputStream.use { fileOut ->
inputStream.copyTo(fileOut)
}

return configPath
}
return null
}

@AroundInvoke
@Throws(Exception::class)
fun timedMethod(context: InvocationContext): Any? {
var response: Any? = null
var success = true
var status = 200
var exception: Throwable? = null

val methodName = context.method.toGenericString()
val start = System.nanoTime()
try {
response = context.proceed()
when (response) {
null -> {
status = 404
success = false
}
is Response -> {
status = response.status
success = response.status < 400
}
else -> {
status = 200
success = true
}
}
} catch (e: Throwable) {
exception = e
success = false
status = if (e is WebApplicationException) {
e.response.status
} else {
500
}
} finally {
try {
val duration = (System.nanoTime() - start) / 1000000
val requestTelemetry = RequestTelemetry(
methodName,
Date(),
duration,
status.toString(),
success
)
telemetryClient.trackRequest(requestTelemetry)
} finally {
if (exception != null) {
throw exception
}
return response
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import net.adoptopenjdk.api.v3.models.Project
import net.adoptopenjdk.api.v3.models.Release
import net.adoptopenjdk.api.v3.models.ReleaseType
import net.adoptopenjdk.api.v3.models.Vendor
import org.eclipse.microprofile.metrics.annotation.Timed
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType
import org.eclipse.microprofile.openapi.annotations.media.Content
Expand Down Expand Up @@ -47,6 +48,7 @@ import javax.ws.rs.core.MediaType
@Tag(name = "Assets")
@Path("/v3/assets/")
@Produces(MediaType.APPLICATION_JSON)
@Timed
class AssetsResource {

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.adoptopenjdk.api.v3.routes

import org.eclipse.microprofile.metrics.annotation.Timed
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.media.Schema
import javax.ws.rs.GET
Expand All @@ -11,6 +12,7 @@ import javax.ws.rs.core.Response
@Path("/v1/")
@Schema(hidden = true)
@Produces(MediaType.TEXT_PLAIN)
@Timed
class V1Route {

// Cant find a way to match nothing and something in the same request, so need 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.adoptopenjdk.api.v3.routes
import net.adoptopenjdk.api.v3.models.VersionData
import net.adoptopenjdk.api.v3.parser.FailedToParse
import net.adoptopenjdk.api.v3.parser.VersionParser
import org.eclipse.microprofile.metrics.annotation.Timed
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse
Expand All @@ -18,6 +19,7 @@ import javax.ws.rs.core.MediaType
@Tag(name = "Version")
@Path("/v3/version/")
@Produces(MediaType.APPLICATION_JSON)
@Timed
class VersionResource {

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.adoptopenjdk.api.v3.routes.info

import net.adoptopenjdk.api.v3.dataSources.APIDataStore
import net.adoptopenjdk.api.v3.models.ReleaseInfo
import org.eclipse.microprofile.metrics.annotation.Timed
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.tags.Tag
import javax.ws.rs.GET
Expand All @@ -12,6 +13,7 @@ import javax.ws.rs.core.MediaType
@Tag(name = "Release Info")
@Path("/v3/info/")
@Produces(MediaType.APPLICATION_JSON)
@Timed
class AvailableReleasesResource {
@GET
@Path("/available_releases/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.adoptopenjdk.api.v3.routes.info

import net.adoptopenjdk.api.v3.dataSources.APIDataStore
import net.adoptopenjdk.api.v3.models.Platforms
import org.eclipse.microprofile.metrics.annotation.Timed
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.tags.Tag
import javax.ws.rs.GET
Expand All @@ -12,6 +13,7 @@ import javax.ws.rs.core.MediaType
@Tag(name = "Release Info")
@Path("/v3/info/")
@Produces(MediaType.APPLICATION_JSON)
@Timed
class PlatformsResource {

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.adoptopenjdk.api.v3.models.ReleaseList
import net.adoptopenjdk.api.v3.models.ReleaseType
import net.adoptopenjdk.api.v3.models.ReleaseVersionList
import net.adoptopenjdk.api.v3.models.Vendor
import org.eclipse.microprofile.metrics.annotation.Timed
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType
import org.eclipse.microprofile.openapi.annotations.media.Schema
Expand All @@ -26,6 +27,7 @@ import javax.ws.rs.core.MediaType
@Tag(name = "Release Info")
@Path("/v3/info")
@Produces(MediaType.APPLICATION_JSON)
@Timed
class ReleaseListResource {

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.adoptopenjdk.api.v3.routes.info

import net.adoptopenjdk.api.v3.dataSources.APIDataStore
import net.adoptopenjdk.api.v3.models.Variants
import org.eclipse.microprofile.metrics.annotation.Timed
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.tags.Tag
import javax.ws.rs.GET
Expand All @@ -12,6 +13,7 @@ import javax.ws.rs.core.MediaType
@Tag(name = "Release Info")
@Path("/v3/info")
@Produces(MediaType.APPLICATION_JSON)
@Timed
class VariantsResource {

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.adoptopenjdk.api.v3.models.Release
import net.adoptopenjdk.api.v3.models.ReleaseType
import net.adoptopenjdk.api.v3.models.StatsSource
import net.adoptopenjdk.api.v3.models.Vendor
import org.eclipse.microprofile.metrics.annotation.Timed
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType
import org.eclipse.microprofile.openapi.annotations.media.Schema
Expand All @@ -29,6 +30,7 @@ import javax.ws.rs.core.Response
@Path("/v3/stats/downloads")
@Produces(MediaType.APPLICATION_JSON)
@Schema(hidden = true)
@Timed
class DownloadStatsResource {
private val statsInterface = net.adoptopenjdk.api.v3.DownloadStatsInterface()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">
<PerformanceCounters>
<UseBuiltIn>true</UseBuiltIn>
</PerformanceCounters>
</ApplicationInsights>
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ quarkus.log.console.enable=true
quarkus.log.file.enable=true

vertx.disableFileCPResolving=true

quarkus.smallrye-metrics.path=/v2/metrics
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<maven.compiler.testTarget>11</maven.compiler.testTarget>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>1.4.1.Final</quarkus.version>
<quarkus.version>1.6.1.Final</quarkus.version>
<surefire-plugin.version>3.0.0-M3</surefire-plugin.version>
</properties>

Expand Down