From 6eb0206c524e778dba550a39d4b197d009215806 Mon Sep 17 00:00:00 2001 From: Ilia Krustev Date: Wed, 30 Oct 2019 13:02:38 +0200 Subject: [PATCH 1/4] Log REST request body. --- .../nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java b/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java index 0d492556..c47762da 100644 --- a/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java +++ b/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java @@ -90,8 +90,10 @@ public class RetryExecutor { Future response, int retries) { + LOGGER.debug("body: {}", body); Handler>> handler = ar -> { if (isOk(ar)) { + LOGGER.debug("sent body: {}", body); response.complete(ar.result().body()); return; } -- GitLab From d2bf097d9f84ebcab07b1cd8ef07fd5dd0f6f7b4 Mon Sep 17 00:00:00 2001 From: Ilia Krustev Date: Thu, 31 Oct 2019 14:31:40 +0200 Subject: [PATCH 2/4] Log rest request body and correlate it with the request outcome. --- .../vertxutil/restclient/RetryExecutor.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java b/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java index c47762da..bfd5646f 100644 --- a/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java +++ b/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java @@ -1,5 +1,6 @@ package com.nynjacoin.nccs.lib.vertxutil.restclient; +import com.nynjacoin.nccs.lib.util.UuidGenerator; import io.vertx.core.AsyncResult; import io.vertx.core.Future; import io.vertx.core.Handler; @@ -10,6 +11,7 @@ import io.vertx.ext.web.client.HttpRequest; import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.codec.BodyCodec; import java.util.Objects; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -84,21 +86,34 @@ public class RetryExecutor { return response; } + private static final Level BODY_LOG_LEVEL = Level.DEBUG; + + private void execute( + HttpRequest request, + JsonObject body, + Future response, + int retries) { + + String requestId = UuidGenerator.generate(); + LOGGER.log(BODY_LOG_LEVEL, "{}: sending {}", requestId, body); + execute(requestId, request, body, response, retries); + } + private void execute( + String requestId, HttpRequest request, JsonObject body, Future response, int retries) { - LOGGER.debug("body: {}", body); Handler>> handler = ar -> { if (isOk(ar)) { - LOGGER.debug("sent body: {}", body); + LOGGER.debug("{}: OK", requestId); response.complete(ar.result().body()); return; } if (retries < maxRetries && mustRetry(ar)) { - LOGGER.warn("Retriable failure to {}: {}", request, getError(ar)); + LOGGER.warn("{}: retryable failure: {}", requestId, getError(ar)); int newRetries = retries + 1; long retryAfter = retryMilliseconds * newRetries; vertx.setTimer( @@ -107,7 +122,10 @@ public class RetryExecutor { ); } else { Throwable t = getThrowable(ar); - LOGGER.error("Failure to {}: {}", request.toString(), t.getMessage()); + if (BODY_LOG_LEVEL.isLessSpecificThan(LOGGER.getLevel())) { + LOGGER.debug("{}: failed to send {}", requestId, body); + } + LOGGER.error("{}: FAILURE: {}", requestId, t.getMessage()); response.fail(t); } }; -- GitLab From c545d57a05a1b9e374d001d6c3f58caec9c6c5c5 Mon Sep 17 00:00:00 2001 From: "A.Popov" Date: Wed, 30 Oct 2019 14:54:52 +0200 Subject: [PATCH 3/4] Fixed jenkins file --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 60327d91..6370bbe7 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -165,7 +165,7 @@ pipeline { dir( "flux-deploy-staging"){ sh 'ls -l' - sh 'sed -i "0,/tag:/ s/tag.*/tag: $IMAGE_BUILD_TAG.'+gitHash+'/" releases/callconf/callconf.yaml' + sh 'sed -i "0,/tag:/ s/tag.*/tag: $IMAGE_BUILD_TAG.'+gitHash+'/" releases/calling-service/callconf.yaml' sh "git add releases/callconf/callconf.yaml" sh 'git config --global push.default simple' -- GitLab From fcec8ddda2ece2c4e9bdf4955dab95fb4bb9c64b Mon Sep 17 00:00:00 2001 From: "A.Popov" Date: Tue, 5 Nov 2019 14:04:35 +0200 Subject: [PATCH 4/4] Jenkinsfile refactored in order to be applicable for all development environments --- Jenkinsfile | 71 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6370bbe7..94f0060d 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,6 +26,42 @@ def helmBuildAndPushToRegistry( } } +def prompt(msg) { + try{ + timeout(time: 24, unit: 'SECONDS') { + try { + input msg + echo "User gave approval" + return true + } catch (ignored) { + echo "User pressed NO" + return false + } + } + } catch (ignored){ + echo "Nothing is pressed and prompt timed out" + return false + } +} + +def deploy(String fluxRepo){ + withCredentials([usernamePassword(credentialsId: 'nynjaci-github-push-token', + usernameVariable:'GIT_USERNAME', + passwordVariable:'GIT_PASSWORD')]) { + sh 'git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NYNJA-MC/flux-deploy-'+fluxRepo + dir( "flux-deploy-"+fluxRepo) { + sh 'ls -l' + sh 'sed -i "0,/tag:/ s/tag.*/tag: $IMAGE_BUILD_TAG.'+gitHash+'/" releases/callconf/callconf.yaml' + sh "git add releases/callconf/callconf.yaml" + + sh 'git config --global push.default simple' + sh 'git config --global user.email "ci@nynja.biz"' + sh 'git config --global user.name "Nynja CI"' + sh 'git commit -m "Updated $APP_NAME tag to $IMAGE_BUILD_TAG."' + gitHash + sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NYNJA-MC/flux-deploy-"+fluxRepo+" @:master" + } + } +} pipeline { environment { @@ -139,7 +175,6 @@ pipeline { stage('Create image') { steps { container('calling') { - sh "/usr/bin/docker build -t $IMAGE_NAME:$IMAGE_BUILD_TAG."+gitHash+" -t $IMAGE_NAME:$IMAGE_TAG -f components/focus/Dockerfile ." withCredentials([file(credentialsId: 'jenkins-gcr-publisher', variable: 'KEY_FILE')]) { sh 'docker login -u _json_key -p "$(cat $KEY_FILE)" https://eu.gcr.io' @@ -153,31 +188,21 @@ pipeline { sh "docker push $IMAGE_NAME-history:$IMAGE_TAG" } } - timeout(time: 24, unit: 'HOURS') { input 'Deploy to staging ?' } } - post { failure { echo 'Deploy to staging aborted' }} + } + stage('Deploy updated image on dev') { + when { not { branch 'production'}} + steps{ container('calling'){ deploy("dev") } } } stage('Deploy updated image on staging') { - steps{ - container('calling') { - withCredentials([usernamePassword(credentialsId: 'nynjaci-github-push-token', usernameVariable:'GIT_USERNAME', passwordVariable:'GIT_PASSWORD')]) { - sh 'git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NYNJA-MC/flux-deploy-staging' - dir( "flux-deploy-staging"){ - - sh 'ls -l' - sh 'sed -i "0,/tag:/ s/tag.*/tag: $IMAGE_BUILD_TAG.'+gitHash+'/" releases/calling-service/callconf.yaml' - sh "git add releases/callconf/callconf.yaml" - - sh 'git config --global push.default simple' - sh 'git config --global user.email "ci@nynja.biz"' - sh 'git config --global user.name "Nynja CI"' - sh 'git commit -m "Updated $APP_NAME tag to $IMAGE_BUILD_TAG."' + gitHash - sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NYNJA-MC/flux-deploy-staging @:master" - } - } - } - } + when { branch 'production' + expression {prompt('Deploy to staging?')}} + steps{ container('calling') { deploy("staging") } } + } + stage('Deploy updated image on prod') { + when { branch 'production' + expression {prompt('Deploy to PROD?')} } + steps{ container('calling') { deploy("prod") } } } - } } -- GitLab