Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
karle0wne committed Oct 29, 2024
1 parent c1a2f0b commit 80f0f69
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 35 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@
<artifactId>guava</artifactId>
<version>32.0.0-jre</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>1.29.0-alpha</version>
</dependency>

<!--test-->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ public class DummyCallbackNotifierImpl implements CallbackNotifier {

@Override
public void sendDisputeAlreadyCreated(Dispute dispute) {
log.debug("Trying to call DummyCallbackNotifierImpl.sendDisputeAlreadyCreated() {}", dispute.getId());
}

@Override
public void sendDisputePoolingExpired(Dispute dispute) {
log.debug("Trying to call DummyCallbackNotifierImpl.sendDisputePoolingExpired() {}", dispute.getId());
}

@Override
public void sendDisputeReadyForCreateAdjustment(List<Dispute> disputes) {
log.debug("Trying to call DummyCallbackNotifierImpl.sendDisputeReadyForCreateAdjustment() {}", disputes.size());
}

@Override
public void sendDisputeFailedReviewRequired(Dispute dispute, String errorCode, String errorDescription) {
log.debug("Trying to call DummyCallbackNotifierImpl.sendDisputeFailedReviewRequired() {}", dispute.getId());
}
}
68 changes: 68 additions & 0 deletions src/main/java/dev/vality/disputes/config/OtelConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package dev.vality.disputes.config;

import dev.vality.disputes.config.properties.OtelProperties;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Slf4j
@Configuration
@RequiredArgsConstructor
public class OtelConfig {

private final OtelProperties otelProperties;

@Value("${spring.application.name}")
private String applicationName;

@Bean
public OpenTelemetry openTelemetryConfig() {
var resource = Resource.getDefault()
.merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, applicationName)));
var sdkTracerProvider = SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(OtlpHttpSpanExporter.builder()
.setEndpoint(otelProperties.getResource())
.setTimeout(Duration.ofMillis(otelProperties.getTimeout()))
.build())
.build())
.setSampler(Sampler.alwaysOn())
.setResource(resource)
.build();
var openTelemetrySdk = OpenTelemetrySdk.builder()
.setTracerProvider(sdkTracerProvider)
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
.build();
registerGlobalOpenTelemetry(openTelemetrySdk);
return openTelemetrySdk;
}

private static void registerGlobalOpenTelemetry(OpenTelemetry openTelemetry) {
try {
GlobalOpenTelemetry.set(openTelemetry);
} catch (Exception e) {
log.warn("please initialize the ObservabilitySdk before starting the application");
GlobalOpenTelemetry.resetForTest();
try {
GlobalOpenTelemetry.set(openTelemetry);
} catch (Exception ex) {
log.warn("unable to set GlobalOpenTelemetry", ex);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.vality.disputes.config.properties;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "otel")
public class OtelProperties {

private String resource;
private Long timeout;

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Boolean routeUrlEquals(ProviderData providerData) {

@Override
public DisputeCreatedResult createDispute(Dispute dispute, List<Attachment> attachments, ProviderData providerData) {
log.debug("Trying to call DummyRemoteClientImpl.createDispute() {}", dispute.getId());
providerData.setRouteUrl(routeUrl);
return DisputeCreatedResult.successResult(new DisputeCreatedSuccessResult(UUID.randomUUID().toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -33,56 +32,44 @@ public DisputeCreatedResult createDispute(DisputeParams disputeParams) {
}

@Override
@SneakyThrows
public void sendDisputeAlreadyCreated(DisputeAlreadyCreated disputeAlreadyCreated) {
try {
log.debug("Trying to call adminCallbackDisputesTgBotClient.sendDisputeAlreadyCreated() {}", disputeAlreadyCreated.getId());
adminCallbackDisputesTgBotClient.notify(
new NotificationParamsRequest(List.of(Notification.disputeAlreadyCreated(disputeAlreadyCreated))));
log.debug("adminCallbackDisputesTgBotClient.sendDisputeAlreadyCreated() has been called {}", disputeAlreadyCreated.getId());
} catch (TException e) {
log.error("Failed to call adminCallbackDisputesTgBotClient.sendDisputeAlreadyCreated() with id: {}}", disputeAlreadyCreated.getId(), e);
}
log.debug("Trying to call adminCallbackDisputesTgBotClient.sendDisputeAlreadyCreated() {}", disputeAlreadyCreated.getId());
adminCallbackDisputesTgBotClient.notify(
new NotificationParamsRequest(List.of(Notification.disputeAlreadyCreated(disputeAlreadyCreated))));
log.debug("adminCallbackDisputesTgBotClient.sendDisputeAlreadyCreated() has been called {}", disputeAlreadyCreated.getId());
}

@Override
@SneakyThrows
public void sendDisputePoolingExpired(DisputePoolingExpired disputePoolingExpired) {
try {
log.debug("Trying to call adminCallbackDisputesTgBotClient.sendDisputePoolingExpired() {}", disputePoolingExpired.getId());
adminCallbackDisputesTgBotClient.notify(
new NotificationParamsRequest(List.of(Notification.disputePoolingExpired(disputePoolingExpired))));
log.debug("adminCallbackDisputesTgBotClient.sendDisputePoolingExpired() has been called {}", disputePoolingExpired.getId());
} catch (TException e) {
log.error("Failed to call adminCallbackDisputesTgBotClient.sendDisputePoolingExpired() with id: {}}", disputePoolingExpired.getId(), e);
}
log.debug("Trying to call adminCallbackDisputesTgBotClient.sendDisputePoolingExpired() {}", disputePoolingExpired.getId());
adminCallbackDisputesTgBotClient.notify(
new NotificationParamsRequest(List.of(Notification.disputePoolingExpired(disputePoolingExpired))));
log.debug("adminCallbackDisputesTgBotClient.sendDisputePoolingExpired() has been called {}", disputePoolingExpired.getId());
}

@Override
@SneakyThrows
public void sendDisputeReadyForCreateAdjustment(List<DisputeReadyForCreateAdjustment> disputeReadyForCreateAdjustments) {
var ids = disputeReadyForCreateAdjustments.stream()
.map(DisputeReadyForCreateAdjustment::getId)
.map(String::valueOf)
.collect(Collectors.joining(", "));
try {
log.debug("Trying to call adminCallbackDisputesTgBotClient.sendDisputeReadyForCreateAdjustment() {}", ids);
var notifications = disputeReadyForCreateAdjustments.stream()
.map(Notification::disputeReadyForCreateAdjustment)
.collect(Collectors.toList());
adminCallbackDisputesTgBotClient.notify(new NotificationParamsRequest(notifications));
log.debug("adminCallbackDisputesTgBotClient.sendDisputeReadyForCreateAdjustment() has been called {}", ids);
} catch (TException e) {
log.error("Failed to call adminCallbackDisputesTgBotClient.sendDisputeReadyForCreateAdjustment() with id: {}}", ids, e);
}
log.debug("Trying to call adminCallbackDisputesTgBotClient.sendDisputeReadyForCreateAdjustment() {}", ids);
var notifications = disputeReadyForCreateAdjustments.stream()
.map(Notification::disputeReadyForCreateAdjustment)
.collect(Collectors.toList());
adminCallbackDisputesTgBotClient.notify(new NotificationParamsRequest(notifications));
log.debug("adminCallbackDisputesTgBotClient.sendDisputeReadyForCreateAdjustment() has been called {}", ids);
}

@Override
@SneakyThrows
public void sendDisputeFailedReviewRequired(DisputeFailedReviewRequired disputeFailedReviewRequired) {
try {
log.debug("Trying to call adminCallbackDisputesTgBotClient.sendDisputeFailedReviewRequired() {}", disputeFailedReviewRequired.getId());
adminCallbackDisputesTgBotClient.notify(
new NotificationParamsRequest(List.of(Notification.disputeFailedReviewRequired(disputeFailedReviewRequired))));
log.debug("adminCallbackDisputesTgBotClient.sendDisputeFailedReviewRequired() has been called {}", disputeFailedReviewRequired.getId());
} catch (TException e) {
log.error("Failed to call adminCallbackDisputesTgBotClient.sendDisputeFailedReviewRequired() with id: {}}", disputeFailedReviewRequired.getId(), e);
}
log.debug("Trying to call adminCallbackDisputesTgBotClient.sendDisputeFailedReviewRequired() {}", disputeFailedReviewRequired.getId());
adminCallbackDisputesTgBotClient.notify(
new NotificationParamsRequest(List.of(Notification.disputeFailedReviewRequired(disputeFailedReviewRequired))));
log.debug("adminCallbackDisputesTgBotClient.sendDisputeFailedReviewRequired() has been called {}", disputeFailedReviewRequired.getId());
}
}
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ http-client:
connectionTimeout: 10000
maxTotalPooling: 200
defaultMaxPerRoute: 200

otel:
resource: http://localhost:4318/v1/traces
timeout: 60000

0 comments on commit 80f0f69

Please sign in to comment.