Skip to content

Commit

Permalink
Fix/agenthealthmanager 2.1.1 (#1521)
Browse files Browse the repository at this point in the history
* fix: AgentHealthManger does not handle negative duration while scheduling health checks

Co-authored-by: Claudio Waldvogel <[email protected]>
  • Loading branch information
ClaudioWaldvogel and Claudio Waldvogel authored Sep 5, 2022
1 parent c0a2e1f commit 99a5e21
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/agent_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
pull_request:
branches:
- master
- 1.*.*
- 2.*.*
paths-ignore:
- 'components/**'
- 'inspectit-ocelot-documentation/**'
Expand Down
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ allprojects {

repositories {
mavenCentral()
maven {
name 'Nexus@NT'
url "https://repository.novatec-gmbh.de/content/repositories/3rd_party_libs/"
}
}

apply plugin: 'java'
Expand Down
5 changes: 3 additions & 2 deletions components/inspectit-ocelot-configdocsgenerator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}

sourceCompatibility = 1.8
//to guarantee that the Configuration Server is compatible with Java 8 runtime environments
sourceCompatibility = 1.8 // Java version compatibility to use when compiling Java source.
targetCompatibility = 1.8 // Java version to generate classes for.
6 changes: 3 additions & 3 deletions components/inspectit-ocelot-configurationserver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ cyclonedxBom {
repositories {
mavenCentral()
}

sourceCompatibility = 1.8

//to guarantee that the Configuration Server is compatible with Java 8 runtime environments
sourceCompatibility = 1.8 // Java version compatibility to use when compiling Java source.
targetCompatibility = 1.8 // Java version to generate classes for.
test {
useJUnitPlatform()

Expand Down
5 changes: 4 additions & 1 deletion inspectit-ocelot-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ test {
}

group = 'rocks.inspectit.ocelot'
sourceCompatibility = 1.8

sourceCompatibility = 1.8 // Java version compatibility to use when compiling Java source.
targetCompatibility = 1.8 // Java version to generate classes for.


configurations {
opentelemetry
Expand Down
4 changes: 2 additions & 2 deletions inspectit-ocelot-bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ test {
}
}

sourceCompatibility = 1.8

sourceCompatibility = 1.8 // Java version compatibility to use when compiling Java source.
targetCompatibility = 1.8 // Java version to generate classes for.
jar {
archiveName = "${project.name}.jar"

Expand Down
4 changes: 2 additions & 2 deletions inspectit-ocelot-config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ repositories {
}

group = 'rocks.inspectit.ocelot'
sourceCompatibility = 1.8

sourceCompatibility = 1.8 // Java version compatibility to use when compiling Java source.
targetCompatibility = 1.8 // Java version to generate classes for.
dependencies {
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.NonNull;

import javax.validation.constraints.AssertFalse;
import javax.validation.constraints.AssertTrue;
import java.time.Duration;

/**
Expand All @@ -21,6 +22,17 @@ public class AgentHealthSettings {
@NonNull
private Duration validityPeriod;

/**
* The minimum delay how often the AgentHealthManager checks for invalid agent health events to clear health status.
*/
@NonNull
private Duration minHealthCheckDelay;

@AssertTrue(message = "minHealthCheckDelay must be at least 60 seconds")
public boolean isMin60SecondsDelay() {
return minHealthCheckDelay.toMinutes() >= 1;
}

@AssertFalse(message = "The specified period should not be negative!")
public boolean isNegativeDuration() {
return validityPeriod != null && validityPeriod.isNegative();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ inspectit:
# health changes due to instrumentation errors are valid until the next re-instrumentation
validity-period: 1h

# The minimum delay how often the AgentHealthManager checks for invalid agent health events to clear health status
# By default the delay is calculated based on the last agent health event
# Minimum value is 1m
min-health-check-delay: 1m

# the action tracing mode to use
# options are: OFF, ONLY_ENABLED, ALL_WITHOUT_DEFAULT, ALL_WITH_DEFAULT
action-tracing: ONLY_ENABLED
Expand Down
21 changes: 15 additions & 6 deletions inspectit-ocelot-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ test {
}
}

sourceCompatibility = 1.8

sourceCompatibility = 1.8 // Java version compatibility to use when compiling Java source.
targetCompatibility = 1.8 // Java version to generate classes for.


dependencies {
compileOnly(
Expand All @@ -39,9 +42,6 @@ dependencies {
"io.opentelemetry:opentelemetry-opencensus-shim",


)
buildTools(
'jarcheck:jarcheck:1.5'
)
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"

Expand Down Expand Up @@ -159,9 +159,17 @@ dependencies {

}

apply plugin: 'java'
task compileJarCheck(type: JavaCompile){
source = sourceSets.main.java.srcDirs
include 'com/mindprod/jarcheck/JarCheck.java'
classpath = sourceSets.main.compileClasspath
destinationDir = new File("${buildDir}/classes/java/main")
}

// use jarCheck to make sure all classes in our dependencies are at maximum in version 1.8
task checkDependencyJavaVersions {

def excludes = ["byte-buddy",
// exclude OpenTelemetry as they guarantee JDK 8 support
"opentelemetry",
Expand All @@ -183,15 +191,16 @@ task checkDependencyJavaVersions {
})
if (!isExcluded && file.exists()) {
javaexec {
classpath configurations.buildTools
main = 'com.mindprod.jarcheck.JarCheck'
mainClass = 'com.mindprod.jarcheck.JarCheck'
classpath = sourceSets.main.runtimeClasspath
args = ["$file", "1.0", "1.8"]
standardOutput = new File(jarCheckOutput, "$name-check.log").newOutputStream()
}
}
}
}
}
checkDependencyJavaVersions.dependsOn compileJarCheck

task generateVersionFile {
ext.versionFile = new File(buildDir, "ocelot-version.info")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
package com.mindprod.jarcheck;

import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import static java.lang.System.*;
/*
TODO: check class minor version as well.
*/

/**
* Ensures javac -target versions of the class files in a jar are as expected.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.5 2014-03-23 add support for Java 1.8
* @since 2006-01-16
*/
public final class JarCheck
{
/**
* how many bytes at beginning of class file we read<br> 4=ca-fe-ba-be + 2=minor + 2=major
*/
private static final int chunkLength = 8;

private static final int FIRST_COPYRIGHT_YEAR = 2006;

/**
* undisplayed copyright notice
*/
private static final String EMBEDDED_COPYRIGHT =
"Copyright: (c) 2006-2017 Roedy Green, Canadian Mind Products, http://mindprod.com";

private static final String RELEASE_DATE = "2014-03-23";

/**
* embedded version string.
*/
private static final String VERSION_STRING = "1.5";

/**
* translate class file major version number to human JVM version
*/
private static final HashMap<Integer, String> convertMachineToHuman =
new HashMap<>( 23 );

/**
* translate from human JDK version to class file major version number
*/
private static final HashMap<String, Integer> convertHumanToMachine =
new HashMap<>( 23 );

/**
* expected first 4 bytes of a class file
*/
private static final byte[] expectedMagicNumber =
{ ( byte ) 0xca, ( byte ) 0xfe, ( byte ) 0xba, ( byte ) 0xbe };

static
{
convertHumanToMachine.put( "1.0", 44 );
convertHumanToMachine.put( "1.1", 45 );
convertHumanToMachine.put( "1.2", 46 );
convertHumanToMachine.put( "1.3", 47 );
convertHumanToMachine.put( "1.4", 48 );
convertHumanToMachine.put( "1.5", 49 );
convertHumanToMachine.put( "1.6", 50 );
convertHumanToMachine.put( "1.7", 51 );
convertHumanToMachine.put( "1.8", 52 );
}

static
{
convertMachineToHuman.put( 44, "1.0" );
convertMachineToHuman.put( 45, "1.1" );
convertMachineToHuman.put( 46, "1.2" );
convertMachineToHuman.put( 47, "1.3" );
convertMachineToHuman.put( 48, "1.4" );
convertMachineToHuman.put( 49, "1.5" );
convertMachineToHuman.put( 50, "1.6" );
convertMachineToHuman.put( 51, "1.7" );
convertMachineToHuman.put( 52, "1.8" );
}

/**
* check one jar to make sure all class files have compatible versions.
*
* @param jarFilename name of jar file whose classes are to be tested.
* @param low low bound for major version e.g. 44
* @param high high bound for major version. e.g. 50
*
* @return true if all is ok. False if not, with long on System.err of problems.
*/
private static boolean checkJar( String jarFilename, int low, int high )
{
out.println( "\nChecking jar " + jarFilename );
boolean success = true;
FileInputStream fis;
ZipInputStream zip = null;
try
{
try
{
fis = new FileInputStream( jarFilename );
zip = new ZipInputStream( fis );
// loop for each jar entry
entryLoop:
while ( true )
{
ZipEntry entry = zip.getNextEntry();
if ( entry == null )
{
break;
}
// relative name with slashes to separate dirnames.
String elementName = entry.getName();
if ( !elementName.endsWith( ".class" ) )
{
// ignore anything but a .final class file
continue;
}
byte[] chunk = new byte[ chunkLength ];
int bytesRead = zip.read( chunk, 0, chunkLength );
zip.closeEntry();
if ( bytesRead != chunkLength )
{
err.println( ">> Corrupt class file: "
+ elementName );
success = false;
continue;
}
// make sure magic number signature is as expected.
for ( int i = 0; i < expectedMagicNumber.length; i++ )
{
if ( chunk[ i ] != expectedMagicNumber[ i ] )
{
err.println( ">> Bad magic number in "
+ elementName );
success = false;
continue entryLoop;
}
}
/*
* pick out big-endian ushort major version in last two
* bytes of chunk
*/
int major =
( ( chunk[ chunkLength - 2 ] & 0xff ) << 8 ) + (
chunk[ chunkLength - 1 ]
& 0xff );
/* F I N A L L Y. All this has been leading up to this TEST */
if ( low <= major && major <= high )
{
out.print( " OK " );
out.println( convertMachineToHuman.get( major )
+ " ("
+ major
+ ") "
+ elementName );
// leave success set as previously
}
else
{
err.println( ">> Wrong Version " );
err.println( convertMachineToHuman.get( major )
+ " ("
+ major
+ ") "
+ elementName );
success = false;
}
}
// end while
}
catch ( EOFException e )
{
// normal exit
}
zip.close();
return success;
}
catch ( IOException e )
{
err.println( ">> Problem reading jar file." );
return false;
}
}

/**
* Main command line jarfileName lowVersion highVersion e.g. myjar.jar 1.0 1.8
*
* @param args rot used
*/
public static void main( String[] args )
{
try
{
if ( args.length != 3 )
{
err.println( "usage: java -ea -jar jarcheck.jar jarFileName.jar 1.1 1.7" );
System.exit( 2 );
}
String jarFilename = args[ 0 ];
int low = convertHumanToMachine.get( args[ 1 ] );
int high = convertHumanToMachine.get( args[ 2 ] );
boolean success = checkJar( jarFilename, low, high );
if ( !success )
{
err.println("JarCheck failed for " + jarFilename+". See error messages above.");
System.exit( 1 );
}
}
catch ( NullPointerException e )
{
err.println( "usage: java -ea -jar jarcheck.jar jarFileName.jar 1.1 1.8" );
System.exit( 2 );
}
}
}
Loading

0 comments on commit 99a5e21

Please sign in to comment.