Skip to content

Commit

Permalink
Merge pull request #8 from xenit-eu/DOCKER-436
Browse files Browse the repository at this point in the history
DOCKER-436 add error logging
  • Loading branch information
todorinskiz authored Sep 12, 2023
2 parents d16ef4c + c130c59 commit 5a22f2b
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ on:
push:
workflow_dispatch:
env:
ORG_GRADLE_PROJECT_alfresco_nexus_username: ${{ secrets.ALFRESCO_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_alfresco_nexus_password: ${{ secrets.ALFRESCO_NEXUS_PASSWORD }}
GRADLE_OPTS: >-
-Dorg.gradle.project.org.alfresco.maven.nexus.username=${{ secrets.ALFRESCO_NEXUS_USERNAME }}
-Dorg.gradle.project.org.alfresco.maven.nexus.password=${{ secrets.ALFRESCO_NEXUS_PASSWORD }}
jobs:
integration-tests:
runs-on: ubuntu-latest
Expand All @@ -22,8 +23,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
cache-read-only: false
arguments: |
integrationTest
arguments: integrationTest
- name: Upload Test Artifact
if: success() || failure()
uses: actions/upload-artifact@v3
Expand Down
15 changes: 3 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@ plugins {
id 'eu.xenit.docker' version '5.4.0' apply false
id 'eu.xenit.docker-compose' version '5.4.0' apply false
}
def copyPropertyValueIfExists(sourcePropertyName, targetPropertyName) {
if (project.hasProperty(sourcePropertyName)) {
project.ext[targetPropertyName] = project.property(sourcePropertyName)
}
}
subprojects {
def baseVersion = System.getenv("TAG_VERSION") ?: 'v0.0.5'
version = baseVersion[1..baseVersion.length() - 1]


copyPropertyValueIfExists('alfresco_nexus_username', 'org.alfresco.maven.nexus.username')
copyPropertyValueIfExists('alfresco_nexus_password', 'org.alfresco.maven.nexus.password')



ext {
junitJupiterVersion = '5.4.2'
}
repositories {
mavenCentral()
maven {
Expand Down
5 changes: 3 additions & 2 deletions integration-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ dependencies {
testImplementation group: 'io.rest-assured', name: 'rest-assured', version: '3.0.1'
testImplementation group: 'io.rest-assured', name: 'json-path', version: '3.0.1'
testImplementation group: 'io.rest-assured', name: 'rest-assured-common', version: '3.0.1'
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.4.2"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.4.2"

testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitJupiterVersion}"
testRuntimeOnly group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.2'
}
test {
Expand Down
28 changes: 25 additions & 3 deletions solr-actuators/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ group = 'eu.xenit.solr-actuators'
ext {
solrVersion = '6.6.5'
assVersion = '2.0.6'
mockitoVersion = '2.27.0'
hamcrestVersion = '1.3'
slf4jVersion = '1.7.25'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
withJavadocJar()
withSourcesJar()
}
Expand All @@ -27,9 +30,28 @@ dependencies {
exclude group: 'org.restlet.jee' // Only available in JCenter, not essential in this project.
}
compileOnly "org.alfresco:alfresco-search:${assVersion}"

testImplementation("org.apache.solr:solr-core:${solrVersion}") {
exclude group: 'org.restlet.jee' // Only available in JCenter, not essential in this project.
}
testImplementation "org.alfresco:alfresco-search:${assVersion}"

testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitJupiterVersion}"
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
testImplementation "org.mockito:mockito-junit-jupiter:${mockitoVersion}"
testImplementation "org.mockito:mockito-inline:${mockitoVersion}"
testImplementation "org.hamcrest:hamcrest-all:${hamcrestVersion}"
testImplementation("ch.qos.logback:logback-classic:1.4.7")

testImplementation group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jVersion}"
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: "${slf4jVersion}"

}

artifacts.add('sharedJar', jar)


test {
useJUnitPlatform()
}
apply from: "${rootProject.projectDir}/publish.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.invoke.MethodHandles;
import java.text.MessageFormat;


public class ReadinessHandler extends RequestHandlerBase implements SolrCoreAware {

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final String READY = "ready";
private static final String DOWN = "DOWN";
private static final String UP = "UP";
Expand All @@ -47,10 +49,17 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) {
} catch (SolrException e) {
rsp.add(READY, DOWN);
rsp.setException(e);
log.error("solr readiness probe failed with status :'{}' and message: '{}' ",
e.code(),
e.getMessage());

return;
} catch (Exception e) {
rsp.add(READY, DOWN);
rsp.setException(new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, e.getMessage(), e));
log.error("solr readiness probe failed with status :'{}' and message: '{}' ",
SolrException.ErrorCode.SERVICE_UNAVAILABLE,
e.getMessage());
return;
}
rsp.add(READY, UP);
Expand All @@ -71,7 +80,7 @@ private void checkTransactionResponse(boolean setInfo,

if ((lastTxCommitTimeOnServer == 0 || lastChangeSetCommitTimeOnServer == 0)) {
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE,
"Solr did not yet get latest values from server");
"Solr did not yet get latest values from alfresco server");
}

checkMaxLag(setInfo, rsp,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package eu.xenit.actuators.handler;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import org.alfresco.solr.AlfrescoCoreAdminHandler;
import org.alfresco.solr.TrackerState;
import org.alfresco.solr.tracker.AclTracker;
import org.alfresco.solr.tracker.MetadataTracker;
import org.alfresco.solr.tracker.TrackerRegistry;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;

@ExtendWith(MockitoExtension.class)
class ReadinessHandlerTest {
ReadinessHandler readinessHandler = new ReadinessHandler();
@Mock
SolrQueryRequest req;
@Mock
SolrQueryResponse rsp;
@Mock
SolrCore solrCore;
@Mock
CoreContainer coreContainer;
@Mock
AlfrescoCoreAdminHandler coreAdminHandler;
@Mock
TrackerRegistry trackerRegistry;
@Mock
MetadataTracker metadataTracker;
@Mock
AclTracker aclTracker;
@Mock
SolrParams solrParams;
@Mock

TrackerState metadataTrackerState;
@Mock

TrackerState aclsTrackerState;

@Test
void handleRequestBodyNullPointerExceptionLog() {
ListAppender<ILoggingEvent> listAppender = setupAppender();
//will return null pointer exception on call to anything because nothing is set up
readinessHandler.handleRequestBody(req, rsp);
List<ILoggingEvent> logsList = listAppender.list;
validate(logsList.get(0), Level.ERROR, "solr readiness probe failed with status :'SERVICE_UNAVAILABLE' and message: 'null' ");
}

@Test
void handleRequestBodySolrExceptionLog() {
ListAppender<ILoggingEvent> listAppender = setupAppender();
Mockito.when(req.getCore()).thenReturn(solrCore);
Mockito.when(solrCore.getCoreContainer()).thenReturn(coreContainer);
Mockito.when(req.getParams()).thenReturn(solrParams);
Mockito.when(coreContainer.getMultiCoreHandler()).thenReturn(coreAdminHandler);
Mockito.when(coreAdminHandler.getTrackerRegistry()).thenReturn(trackerRegistry);
Mockito.when(solrCore.getName()).thenReturn("solr");
Mockito.when(trackerRegistry.getTrackerForCore("solr", MetadataTracker.class)).thenReturn(metadataTracker);
Mockito.when(trackerRegistry.getTrackerForCore("solr", AclTracker.class)).thenReturn(aclTracker);

Mockito.when(metadataTracker.getTrackerState()).thenReturn(metadataTrackerState);
Mockito.when(aclTracker.getTrackerState()).thenReturn(aclsTrackerState);

Mockito.when(metadataTrackerState.getLastTxCommitTimeOnServer()).thenReturn(0L);


readinessHandler.handleRequestBody(req, rsp);
List<ILoggingEvent> logsList = listAppender.list;
validate(logsList.get(0), Level.ERROR, "solr readiness probe failed with status :'503' and message: 'Solr did not yet get latest values from alfresco server' ");
}

private ListAppender<ILoggingEvent> setupAppender() {
Logger fooLogger = (Logger) LoggerFactory.getLogger(ReadinessHandler.class);
ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
listAppender.start();
fooLogger.addAppender(listAppender);
return listAppender;
}


private static void validate(ILoggingEvent logEntry, Level logLevel, String expectedMessage) {
Assertions.assertEquals(expectedMessage, logEntry.getFormattedMessage());
Assertions.assertEquals(logLevel, logEntry.getLevel());
}
}

0 comments on commit 5a22f2b

Please sign in to comment.