-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
275 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/SuppressingRunnable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.atlassian.performance.tools.awsinfrastructure | ||
|
||
internal class SuppressingRunnable( | ||
private val delegates: Iterable<Runnable> | ||
) : Runnable { | ||
override fun run() { | ||
val exceptions = delegates.fold(emptyList<Exception>()) { exceptions, runnable -> | ||
val exception = try { | ||
runnable.run() | ||
null | ||
} catch (e: Exception) { | ||
e | ||
} | ||
exceptions + listOfNotNull(exception) | ||
} | ||
|
||
when { | ||
exceptions.isEmpty() -> return | ||
exceptions.size == 1 -> throw exceptions[0] | ||
else -> { | ||
val root = Exception("Multiple exceptions were thrown and are added suppressed into this one") | ||
throw exceptions.fold(root) { root, it -> root.addSuppressed(it); root } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 81 additions & 9 deletions
90
src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/Jira.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,113 @@ | ||
package com.atlassian.performance.tools.awsinfrastructure.api.jira | ||
|
||
import com.atlassian.performance.tools.awsinfrastructure.SuppressingRunnable | ||
import com.atlassian.performance.tools.awsinfrastructure.api.RemoteLocation | ||
import com.atlassian.performance.tools.concurrency.api.submitWithLogContext | ||
import com.atlassian.performance.tools.infrastructure.api.MeasurementSource | ||
import com.atlassian.performance.tools.infrastructure.api.jvm.jmx.JmxClient | ||
import com.atlassian.performance.tools.jvmtasks.api.TaskTimer.time | ||
import com.google.common.util.concurrent.ThreadFactoryBuilder | ||
import org.apache.logging.log4j.LogManager | ||
import org.apache.logging.log4j.Logger | ||
import java.net.URI | ||
import java.util.concurrent.Executors | ||
|
||
class Jira( | ||
/** | ||
* @param extraResultsSources source of results/diagnostics of: reverse proxy, Crowd, LDAP, DVCS, DB, Jira plugins | ||
* or anything that can be integrated with Jira as part of web application provisioning | ||
*/ | ||
class Jira private constructor( | ||
private val nodes: List<StartedNode>, | ||
val jiraHome: RemoteLocation, | ||
val database: RemoteLocation?, | ||
val address: URI, | ||
val jmxClients: List<JmxClient> = emptyList() | ||
val jmxClients: List<JmxClient>, | ||
private val extraResultsSources: List<MeasurementSource> | ||
) : MeasurementSource { | ||
private val logger: Logger = LogManager.getLogger(this::class.java) | ||
|
||
@Deprecated("Use Jira.Builder instead.") | ||
constructor( | ||
nodes: List<StartedNode>, | ||
jiraHome: RemoteLocation, | ||
database: RemoteLocation?, | ||
address: URI, | ||
jmxClients: List<JmxClient> | ||
) : this( | ||
nodes = nodes, | ||
jiraHome = jiraHome, | ||
database = database, | ||
address = address, | ||
jmxClients = jmxClients, | ||
extraResultsSources = emptyList() | ||
) | ||
|
||
@Deprecated("Use Jira.Builder instead.") | ||
constructor( | ||
nodes: List<StartedNode>, | ||
jiraHome: RemoteLocation, | ||
database: RemoteLocation?, | ||
address: URI | ||
) : this( | ||
nodes = nodes, | ||
jiraHome = jiraHome, | ||
database = database, | ||
address = address, | ||
jmxClients = emptyList(), | ||
extraResultsSources = emptyList() | ||
) | ||
|
||
override fun gatherResults() { | ||
if (nodes.isEmpty()) { | ||
logger.warn("No Jira nodes known to JPT, not downloading node results") | ||
val firstNode = nodes.firstOrNull() | ||
val measurementSources = extraResultsSources + nodes + listOfNotNull(firstNode?.let { AnalyticsLogsSource(it) }) | ||
if (measurementSources.isEmpty()) { | ||
logger.warn("No result sources known to Jira, can't download anything") | ||
return | ||
} | ||
val executor = Executors.newFixedThreadPool( | ||
nodes.size.coerceAtMost(4), | ||
measurementSources.size.coerceAtMost(4), | ||
ThreadFactoryBuilder() | ||
.setNameFormat("results-gathering-thread-%d") | ||
.build() | ||
) | ||
nodes.map { executor.submitWithLogContext("gather $it") { it.gatherResults() } } | ||
.forEach { it.get() } | ||
time("gather analytics") { nodes.firstOrNull()?.gatherAnalyticLogs() } | ||
SuppressingRunnable( | ||
measurementSources.map { executor.submitWithLogContext("gather $it") { it.gatherResults() } } | ||
.map { Runnable { it.get() } } | ||
).run() | ||
|
||
executor.shutdownNow() | ||
} | ||
|
||
override fun toString() = "Jira(address=$address)" | ||
|
||
class Builder( | ||
private val address: URI, | ||
private val jiraHome: RemoteLocation | ||
) { | ||
private var database: RemoteLocation? = null | ||
private var nodes: List<StartedNode> = emptyList() | ||
private var jmxClients: List<JmxClient> = emptyList() | ||
private var extraResults: List<MeasurementSource> = emptyList() | ||
|
||
fun database(database: RemoteLocation?) = apply { this.database = database } | ||
fun nodes(nodes: List<StartedNode>) = apply { this.nodes = nodes } | ||
fun jmxClients(jmxClients: List<JmxClient>) = apply { this.jmxClients = jmxClients } | ||
fun extraResults(extraResults: List<MeasurementSource>) = apply { this.extraResults = extraResults } | ||
|
||
fun build() = Jira( | ||
nodes = nodes, | ||
jiraHome = jiraHome, | ||
database = database, | ||
address = address, | ||
jmxClients = jmxClients, | ||
extraResultsSources = extraResults | ||
) | ||
} | ||
|
||
private class AnalyticsLogsSource( | ||
private val node: StartedNode | ||
) : MeasurementSource { | ||
override fun gatherResults() { | ||
node.gatherAnalyticLogs() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...atlassian/performance/tools/awsinfrastructure/api/loadbalancer/DiagnosableLoadBalancer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.atlassian.performance.tools.awsinfrastructure.api.loadbalancer | ||
|
||
import com.atlassian.performance.tools.aws.api.StorageLocation | ||
import com.atlassian.performance.tools.infrastructure.api.loadbalancer.LoadBalancer | ||
|
||
interface DiagnosableLoadBalancer : LoadBalancer { | ||
fun gatherDiagnostics(location: StorageLocation) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...lassian/performance/tools/awsinfrastructure/loadbalancer/LoadBalancerDiagnosticsSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.atlassian.performance.tools.awsinfrastructure.loadbalancer | ||
|
||
import com.atlassian.performance.tools.aws.api.StorageLocation | ||
import com.atlassian.performance.tools.awsinfrastructure.api.loadbalancer.DiagnosableLoadBalancer | ||
import com.atlassian.performance.tools.infrastructure.api.MeasurementSource | ||
|
||
internal class LoadBalancerDiagnosticsSource( | ||
private val loadBalancer: DiagnosableLoadBalancer, | ||
private val location: StorageLocation | ||
) : MeasurementSource { | ||
internal object Extension { | ||
fun DiagnosableLoadBalancer.asMeasurementSource( | ||
location: StorageLocation | ||
) = LoadBalancerDiagnosticsSource( | ||
loadBalancer = this, | ||
location = location | ||
) | ||
} | ||
|
||
override fun gatherResults() { | ||
loadBalancer.gatherDiagnostics(location) | ||
} | ||
} |
Oops, something went wrong.