-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Java and Spark versions to Garmadon logs (#232)
* ✨ Add Java and Spark versions to Garmadon logs * Fix mostly Checkstyle rules * Fix build --------- Co-authored-by: Jean-Baptiste Catté <[email protected]>
- Loading branch information
Showing
21 changed files
with
371 additions
and
121 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>com.criteo.java</groupId> | ||
<artifactId>garmadon</artifactId> | ||
<version>1.4.0</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>garmadon-jvm-statistics-test-spark-3.5</artifactId> | ||
<version>1.4.0</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.criteo.java</groupId> | ||
<artifactId>garmadon-jvm-statistics</artifactId> | ||
<version>${garmadon.version}</version> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.11.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.spark</groupId> | ||
<artifactId>spark-core_2.12</artifactId> | ||
<version>3.5.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
...s-test-spark-3.5/src/test/java/com/criteo/hadoop/garmadon/jvm/utils/SparkRuntimeTest.java
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,13 @@ | ||
package com.criteo.hadoop.garmadon.jvm.utils; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SparkRuntimeTest extends TestCase { | ||
|
||
public void test_get_3_5_version() { | ||
assertThat(SparkRuntime.getVersion()).isEqualTo("3.5.3"); | ||
} | ||
|
||
} |
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
71 changes: 71 additions & 0 deletions
71
jvm-statistics/src/main/java/com/criteo/hadoop/garmadon/jvm/utils/SparkRuntime.java
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,71 @@ | ||
package com.criteo.hadoop.garmadon.jvm.utils; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
public final class SparkRuntime { | ||
private static final Version VERSION = computeVersion(); | ||
|
||
private SparkRuntime() { | ||
} | ||
|
||
public static String getVersion() throws RuntimeException { | ||
if (VERSION.versionNumber == null) { | ||
throw new RuntimeException("Could not find Spark version. Is this a Spark application?", VERSION.throwable); | ||
} | ||
return VERSION.versionNumber; | ||
} | ||
|
||
static Version computeVersion() { | ||
try { | ||
return computeSpark32Version(); | ||
} catch (Throwable e) { | ||
try { | ||
return computeSpark35Version(); | ||
} catch (Throwable t) { | ||
return new Version(t); | ||
} | ||
} | ||
} | ||
|
||
private static Version computeSpark32Version() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { | ||
Class<?> clazz = Class.forName("org.apache.spark.package$SparkBuildInfo$"); | ||
Field moduleFIeld = clazz.getField("MODULE$"); | ||
Object instance = moduleFIeld.get(null); | ||
Field versionField = clazz.getDeclaredField("spark_version"); | ||
versionField.setAccessible(true); | ||
String version = (String) versionField.get(instance); | ||
return new Version(version); | ||
} | ||
|
||
private static Version computeSpark35Version() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
Class<?> clazz = Class.forName("org.apache.spark.SparkBuildInfo"); | ||
Method versionMethod = clazz.getDeclaredMethod("spark_version"); | ||
String version = (String) versionMethod.invoke(null); | ||
return new Version(version); | ||
} | ||
|
||
final static class Version { | ||
private final String versionNumber; | ||
private final Throwable throwable; | ||
|
||
private Version(String versionNumber) { | ||
this.versionNumber = versionNumber; | ||
this.throwable = null; | ||
} | ||
|
||
private Version(Throwable throwable) { | ||
this.versionNumber = null; | ||
this.throwable = throwable; | ||
} | ||
|
||
public String getVersionNumer() { | ||
return versionNumber; | ||
} | ||
|
||
public Throwable getThrowable() { | ||
return throwable; | ||
} | ||
} | ||
} |
Oops, something went wrong.