Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 Upgrade to Spring Boot 2.7.0 #46

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@Library('jenkins-ci-automation@master') _

BlibliPipeline ([
type : "java",
modules: [
Docker: null,
Analysis: null
],
deploy_branch_regex : "(master|release/.+)",
application : [
tribe : "rnd",
squad : "backend",
service_name : "blibli-backend-framework"
]
])
2 changes: 1 addition & 1 deletion blibli-backend-framework-aggregate-query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.9-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
3 changes: 1 addition & 2 deletions blibli-backend-framework-api-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.9-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -19,7 +19,6 @@
<dependency>
<groupId>com.blibli.oss</groupId>
<artifactId>blibli-backend-framework-sleuth</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blibli.oss.backend.apiclient.sleuth;

import brave.Tracer;
import brave.propagation.ExtraFieldPropagation;
import brave.baggage.BaggageField;
import com.blibli.oss.backend.apiclient.interceptor.GlobalApiClientInterceptor;
import com.blibli.oss.backend.apiclient.properties.ApiClientProperties;
import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration;
Expand All @@ -23,7 +23,7 @@ public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next)
if (properties.getSleuth().isEnabled() && tracer.currentSpan() != null) {
return Mono.fromCallable(() -> {
ClientRequest.Builder builder = ClientRequest.from(request);
ExtraFieldPropagation.getAll(tracer.currentSpan().context()).forEach((key, value) -> {
BaggageField.getAllValues(tracer.currentSpan().context()).forEach((key, value) -> {
builder.header(SleuthConfiguration.HTTP_BAGGAGE_PREFIX + key, value);
});
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blibli.oss.backend.apiclient.controller;

import brave.Tracer;
import brave.propagation.ExtraFieldPropagation;
import brave.baggage.BaggageField;
import com.blibli.oss.backend.apiclient.client.SleuthApiClient;
import com.blibli.oss.backend.apiclient.client.model.GenericResponse;
import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration;
Expand Down Expand Up @@ -33,8 +33,8 @@ public class SleuthController {
)
public Mono<Map<String, String>> first(@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName) {
ExtraFieldPropagation.set(tracer.currentSpan().context(), "FirstName", firstName);
ExtraFieldPropagation.set(tracer.currentSpan().context(), "LastName", lastName);
BaggageField.getByName(tracer.currentSpan().context(), "FirstName").updateValue(tracer.currentSpan().context(), firstName);
BaggageField.getByName(tracer.currentSpan().context(), "LastName").updateValue(tracer.currentSpan().context(), lastName);
return sleuthApiClient.second();
}

Expand All @@ -44,8 +44,8 @@ public Mono<Map<String, String>> first(@RequestParam("firstName") String firstNa
)
public Mono<Map<String, String>> second(ServerWebExchange exchange) {
Map<String, String> map = new HashMap<>();
map.put("firstName", ExtraFieldPropagation.get(tracer.currentSpan().context(), "FirstName"));
map.put("lastName", ExtraFieldPropagation.get(tracer.currentSpan().context(), "LastName"));
map.put("firstName", BaggageField.getByName(tracer.currentSpan().context(), "FirstName").getValue(tracer.currentSpan().context()));
map.put("lastName", BaggageField.getByName(tracer.currentSpan().context(), "LastName").getValue(tracer.currentSpan().context()));
map.put("headerFirstName", exchange.getRequest().getHeaders().getFirst(SleuthConfiguration.HTTP_BAGGAGE_PREFIX + "firstname"));
map.put("headerLastName", exchange.getRequest().getHeaders().getFirst(SleuthConfiguration.HTTP_BAGGAGE_PREFIX + "lastname"));
return Mono.just(map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ blibli.backend.apiclient.configs.sleuthApiClient.url=http://localhost:15234
blibli.backend.apiclient.configs.helloApiClient.url=http://localhost:8089
blibli.backend.apiclient.configs.helloApiClient.fallback=com.blibli.oss.backend.apiclient.client.HelloApiClientFallback

spring.http.log-request-details=true
spring.mvc.log-request-details=true
logging.level.org.springframework.web.reactive.function.client.ExchangeFunctions=TRACE
logging.level.reactor.netty.http.client=DEBUG

Expand All @@ -17,6 +17,7 @@ blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.maximum-pool-
blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.queue-size=100
blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.queue-type=linked

spring.sleuth.baggage-keys[0]=FirstName
spring.sleuth.baggage.local-fields[0]=FirstName
spring.sleuth.baggage.remote-fields[0]=FirstName

blibli.backend.apiclient.sleuth.enabled=true
2 changes: 1 addition & 1 deletion blibli-backend-framework-command/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.9-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion blibli-backend-framework-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.9-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion blibli-backend-framework-external-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.9-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blibli.oss.backend.externalapi.helper;

import brave.propagation.ExtraFieldPropagation;
import brave.baggage.BaggageField;
import brave.propagation.TraceContext;
import com.blibli.oss.backend.externalapi.model.ExternalSession;
import com.blibli.oss.backend.externalapi.properties.ExternalApiProperties;
Expand Down Expand Up @@ -28,11 +28,11 @@ public static ExternalSession getExternalSession(HttpHeaders headers, ExternalAp

public static ExternalSession fromSleuth(TraceContext traceContext) {
ExternalSession.ExternalSessionBuilder builder = ExternalSession.builder()
.userId(ExtraFieldPropagation.get(traceContext, ExternalSessionSleuth.USER_ID))
.sessionId(ExtraFieldPropagation.get(traceContext, ExternalSessionSleuth.SESSION_ID))
.member(Boolean.parseBoolean(ExtraFieldPropagation.get(traceContext, ExternalSessionSleuth.IS_MEMBER)));
.userId(BaggageField.getByName(traceContext, ExternalSessionSleuth.USER_ID).getValue(traceContext))
.sessionId(BaggageField.getByName(traceContext, ExternalSessionSleuth.SESSION_ID).getValue(traceContext))
.member(Boolean.parseBoolean(BaggageField.getByName(traceContext, ExternalSessionSleuth.IS_MEMBER).getValue(traceContext)));

String additionalParameters = ExtraFieldPropagation.get(traceContext, ExternalSessionSleuth.ADDITIONAL_PARAMETERS);
String additionalParameters = BaggageField.getByName(traceContext, ExternalSessionSleuth.ADDITIONAL_PARAMETERS).getValue(traceContext);
if (Objects.nonNull(additionalParameters)) {
String[] split = additionalParameters.split("\n");
for (String pair : split) {
Expand All @@ -45,16 +45,16 @@ public static ExternalSession fromSleuth(TraceContext traceContext) {
}

public static ExternalSession toSleuth(TraceContext traceContext, ExternalSession externalSession) {
ExtraFieldPropagation.set(traceContext, ExternalSessionSleuth.USER_ID, externalSession.getUserId());
ExtraFieldPropagation.set(traceContext, ExternalSessionSleuth.SESSION_ID, externalSession.getSessionId());
ExtraFieldPropagation.set(traceContext, ExternalSessionSleuth.IS_MEMBER, String.valueOf(externalSession.isMember()));
BaggageField.getByName(traceContext, ExternalSessionSleuth.USER_ID).updateValue(traceContext, externalSession.getUserId());
BaggageField.getByName(traceContext, ExternalSessionSleuth.SESSION_ID).updateValue(traceContext, externalSession.getSessionId());
BaggageField.getByName(traceContext, ExternalSessionSleuth.IS_MEMBER).updateValue(traceContext, String.valueOf(externalSession.isMember()));

if (!externalSession.getAdditionalParameters().isEmpty()) {
StringBuilder builder = new StringBuilder();
externalSession.getAdditionalParameters().forEach((key, value) -> {
builder.append(key).append("=").append(value).append("\n");
});
ExtraFieldPropagation.set(traceContext, ExternalSessionSleuth.ADDITIONAL_PARAMETERS, builder.toString());
BaggageField.getByName(traceContext, ExternalSessionSleuth.ADDITIONAL_PARAMETERS).updateValue(traceContext, builder.toString());
}

return externalSession;
Expand Down
2 changes: 1 addition & 1 deletion blibli-backend-framework-internal-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.9-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blibli.oss.backend.internalapi.helper;

import brave.propagation.ExtraFieldPropagation;
import brave.baggage.BaggageField;
import brave.propagation.TraceContext;
import com.blibli.oss.backend.internalapi.model.InternalSession;
import com.blibli.oss.backend.internalapi.properties.InternalApiProperties;
Expand Down Expand Up @@ -33,19 +33,19 @@ private static List<String> getRoles(String roles) {

public static InternalSession fromSleuth(TraceContext traceContext) {
return InternalSession.builder()
.userId(ExtraFieldPropagation.get(traceContext, InternalSessionSleuth.USER_ID))
.userName(ExtraFieldPropagation.get(traceContext, InternalSessionSleuth.USER_NAME))
.roles(getRoles(ExtraFieldPropagation.get(traceContext, InternalSessionSleuth.ROLES)))
.userId(BaggageField.getByName(traceContext, InternalSessionSleuth.USER_ID).getValue(traceContext))
.userName(BaggageField.getByName(traceContext, InternalSessionSleuth.USER_NAME).getValue(traceContext))
.roles(getRoles(BaggageField.getByName(traceContext, InternalSessionSleuth.ROLES).getValue(traceContext)))
.build();
}

public static InternalSession toSleuth(TraceContext traceContext, InternalSession externalSession) {
ExtraFieldPropagation.set(traceContext, InternalSessionSleuth.USER_ID, externalSession.getUserId());
ExtraFieldPropagation.set(traceContext, InternalSessionSleuth.USER_NAME, externalSession.getUserName());
BaggageField.getByName(traceContext, InternalSessionSleuth.USER_ID).updateValue(traceContext, externalSession.getUserId());
BaggageField.getByName(traceContext, InternalSessionSleuth.USER_NAME).updateValue(traceContext, externalSession.getUserName());

StringJoiner stringJoiner = new StringJoiner(",");
externalSession.getRoles().forEach(stringJoiner::add);
ExtraFieldPropagation.set(traceContext, InternalSessionSleuth.ROLES, stringJoiner.toString());
BaggageField.getByName(traceContext, InternalSessionSleuth.ROLES).updateValue(traceContext, stringJoiner.toString());

return externalSession;
}
Expand Down
2 changes: 1 addition & 1 deletion blibli-backend-framework-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.9-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
18 changes: 17 additions & 1 deletion blibli-backend-framework-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.9-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -30,6 +30,22 @@
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
import com.blibli.oss.backend.kafka.interceptor.InterceptorUtil;
import com.blibli.oss.backend.kafka.interceptor.log.LogKafkaConsumerInterceptor;
import com.blibli.oss.backend.kafka.interceptor.log.LogKafkaProducerInterceptor;
import com.blibli.oss.backend.kafka.listener.KafkaListenerBeanProcessor;
import com.blibli.oss.backend.kafka.listener.aspectj.KafkaListenerAspect;
import com.blibli.oss.backend.kafka.producer.KafkaProducer;
import com.blibli.oss.backend.kafka.properties.KafkaProperties;
import com.blibli.oss.backend.kafka.repository.KafkaProducerAwareBeanProcessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.KafkaListenerConfigUtils;
import org.springframework.kafka.config.KafkaListenerEndpointRegistry;
import org.springframework.kafka.core.KafkaTemplate;

@Configuration
@EnableConfigurationProperties({
KafkaProperties.class
})
@EnableConfigurationProperties({KafkaProperties.class})
public class KafkaAutoConfiguration implements ApplicationContextAware {

@Setter
Expand Down Expand Up @@ -51,15 +48,10 @@ public KafkaProducerAwareBeanProcessor kafkaProducerAwareBeanProcessor(KafkaProd
return new KafkaProducerAwareBeanProcessor(kafkaProducer);
}

@SuppressWarnings("rawtypes")
@Bean(KafkaListenerConfigUtils.KAFKA_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
public KafkaListenerBeanProcessor kafkaListenerBeanProcessor() {
return new KafkaListenerBeanProcessor();
}

@Bean(KafkaListenerConfigUtils.KAFKA_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME)
public KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry() {
return new KafkaListenerEndpointRegistry();
@Bean
@ConditionalOnProperty(value = "blibli.backend.kafka.aspectj", havingValue = "true", matchIfMissing = true)
public KafkaListenerAspect kafkaListenerAspect() {
return new KafkaListenerAspect();
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.blibli.oss.backend.kafka.interceptor;

import com.blibli.oss.backend.kafka.model.ProducerEvent;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.core.OrderComparator;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Slf4j
public final class InterceptorUtil {

public static ProducerEvent fireBeforeSend(ProducerEvent producerEvent, List<KafkaProducerInterceptor> producerInterceptors) {
Expand All @@ -19,24 +22,42 @@ public static ProducerEvent fireBeforeSend(ProducerEvent producerEvent, List<Kaf
return result;
}

public static boolean fireBeforeConsume(ConsumerRecord<String, String> producerEvent, List<KafkaConsumerInterceptor> producerInterceptors) {
for (KafkaConsumerInterceptor interceptor : producerInterceptors) {
if (interceptor.beforeConsume(producerEvent)) {
return true;
public static boolean fireBeforeConsume(Object bean, Method method, List<KafkaConsumerInterceptor> kafkaConsumerInterceptors, ConsumerRecord<String, String> event) {
for (KafkaConsumerInterceptor interceptor : kafkaConsumerInterceptors) {
try {
if (interceptor.isSupport(bean, method)) {
if (interceptor.beforeConsume(event)) {
return true;
}
}
} catch (Throwable throwable) {
log.error("Error while invoke interceptor", throwable);
}
}
return false;
}

public static void fireAfterSuccessConsume(ConsumerRecord<String, String> producerEvent, List<KafkaConsumerInterceptor> producerInterceptors) {
for (KafkaConsumerInterceptor interceptor : producerInterceptors) {
interceptor.afterSuccessConsume(producerEvent);
public static void fireAfterSuccessConsume(Object bean, Method method, List<KafkaConsumerInterceptor> kafkaConsumerInterceptors, ConsumerRecord<String, String> event) {
for (KafkaConsumerInterceptor interceptor : kafkaConsumerInterceptors) {
try {
if (interceptor.isSupport(bean, method)) {
interceptor.afterSuccessConsume(event);
}
} catch (Throwable throwable) {
log.error("Error while invoke interceptor", throwable);
}
}
}

public static void fireAfterErrorConsume(ConsumerRecord<String, String> producerEvent, Throwable throwable, List<KafkaConsumerInterceptor> producerInterceptors) {
for (KafkaConsumerInterceptor interceptor : producerInterceptors) {
interceptor.afterFailedConsume(producerEvent, throwable);
public static void fireAfterErrorConsume(Object bean, Method method, List<KafkaConsumerInterceptor> kafkaConsumerInterceptors, ConsumerRecord<String, String> event, Throwable throwable) {
for (KafkaConsumerInterceptor interceptor : kafkaConsumerInterceptors) {
try {
if (interceptor.isSupport(bean, method)) {
interceptor.afterFailedConsume(event, throwable);
}
} catch (Throwable e) {
log.error("Error while invoke interceptor", e);
}
}
}

Expand Down
Loading