Skip to content

Commit

Permalink
fix: [OS-292] fix database transaction error (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
haniotak authored Mar 26, 2024
1 parent 7734fde commit 35e1b93
Show file tree
Hide file tree
Showing 31 changed files with 584 additions and 125 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# OSCARS Release Notes
### 1.2.4
> Mar 2024
- further opentelemetry integration
- bug fixes for Hibernate commit errors

### 1.2.3
> Mar 2024
- OS-285: fix operational state bugs

### 1.2.2
Expand Down
12 changes: 9 additions & 3 deletions backend/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ spring.security.oauth2.client.registration.keycloak.authorization-grant-type=aut
spring.security.oauth2.client.registration.keycloak.scope=openid

# for opentelemetry
otel.sdk.disabled=true
# otel.propagators=tracecontext,b3
# otel.resource.attributes=environment=dev,xyz=foo
#otel.sdk.disabled=true // uncomment this to disable OTEL
otel.service.name=oscars-backend
otel.service.version=1.2
otel.traces.exporter=otlp
otel.metrics.exporter=otlp
otel.logs.exporter=otlp
otel.exporter.otlp.endpoint=https://eapm2.gc1.dev.stardust.es.net:8200
otel.exporter.otlp.headers=authorization: ApiKey <APIKEY>
otel.resource.attributes=deployment.environment=development


frontend.oauth-client-id=local-oscars-frontend
Expand Down
7 changes: 7 additions & 0 deletions backend/config/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<suffixPattern>%msg</suffixPattern>
</appender>

<logger name="net.es.oscars" level="INFO">
<appender-ref ref="OpenTelemetry"/>
</logger>

<root level="WARN">
<appender-ref ref="FILE"/>
Expand Down Expand Up @@ -70,5 +73,9 @@
<logger name="org.springframework" level="ERROR">
<appender-ref ref="STDOUT" />
</logger>
<appender name="OpenTelemetry"
class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
</appender>


</configuration>
62 changes: 34 additions & 28 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.10</version>
<version>3.2.4</version>
<relativePath/>
</parent>

<groupId>net.es.oscars</groupId>
<artifactId>backend</artifactId>
<name>backend</name>
<version>1.2.3</version>
<version>1.2.4</version>

<description>OSCARS backend</description>
<properties>
Expand All @@ -23,10 +23,6 @@
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-dependency-plugin.version>3.5.0</maven-dependency-plugin.version>

<lombok.version>1.18.30</lombok.version>

<cucumber.options>--tags @unit --strict</cucumber.options>
</properties>

Expand All @@ -40,6 +36,10 @@
<id>nsi</id>
<url>https://gitlab.es.net/api/v4/projects/828/packages/maven</url>
</repository>
<repository>
<id>apache maven</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<profiles>
Expand Down Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -116,32 +116,43 @@
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-web-3.1</artifactId>
<version>2.2.0-alpha</version>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-jdbc</artifactId>
</dependency>


<!-- for serializing JSONBs into psql -->
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-62</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
</dependency>
<!-- for saving Instants -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.2</version>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.15.2</version>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.15.2</version>
<version>2.16.1</version>
</dependency>


Expand All @@ -166,7 +177,7 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
<version>11.0.16</version>
<version>12.0.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
<dependency>
Expand Down Expand Up @@ -225,22 +236,22 @@
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>4.0.2</version>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-features-logging</artifactId>
<version>4.0.2</version>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.5.1</version>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
<version>5.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand Down Expand Up @@ -274,12 +285,12 @@
<dependency>
<groupId>com.github.seancfoley</groupId>
<artifactId>ipaddress</artifactId>
<version>5.4.0</version>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<version>3.14.0</version>
</dependency>

<dependency>
Expand All @@ -303,19 +314,19 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.13.0</version>
<version>7.16.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.13.0</version>
<version>7.16.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>7.13.0</version>
<version>7.16.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->
Expand All @@ -335,11 +346,6 @@
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>11.0.15</version>
</dependency>

</dependencies>

Expand All @@ -351,7 +357,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<version>3.6.1</version>
</plugin>

<plugin>
Expand Down
31 changes: 12 additions & 19 deletions backend/src/main/java/net/es/oscars/app/Startup.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package net.es.oscars.app;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.es.oscars.app.exc.StartupException;
import net.es.oscars.app.props.StartupProperties;
import net.es.oscars.app.syslog.Syslogger;
import net.es.oscars.sb.nso.resv.LegacyPopulator;
import net.es.oscars.topo.beans.TopoException;
import net.es.oscars.topo.pop.ConsistencyException;
Expand All @@ -26,25 +28,16 @@ public class Startup {

private final List<StartupComponent> components;
private final StartupProperties startupProperties;
private final Syslogger syslogger;

private final TopoPopulator topoPopulator;

private final LegacyPopulator legacyPopulator;

@Setter
@Getter
private boolean inStartup = true;
@Setter
@Getter
private boolean inShutdown = false;

public void setInStartup(boolean inStartup) {
this.inStartup = inStartup;
}

public void setInShutdown(boolean inShutdown) {
this.inShutdown = inShutdown;
}


@Bean
public Executor taskExecutor() {
Expand All @@ -53,27 +46,30 @@ public Executor taskExecutor() {

@Autowired
public Startup(StartupProperties startupProperties,
Syslogger syslogger,
TopoPopulator topoPopulator,
UIPopulator uiPopulator, LegacyPopulator legacyPopulator) {
this.startupProperties = startupProperties;
this.topoPopulator = topoPopulator;
this.syslogger = syslogger;
this.legacyPopulator = legacyPopulator;

components = new ArrayList<>();
components.add(uiPopulator);
}

@WithSpan(value="startup")
public void onStart() throws IOException, ConsistencyException, TopoException {
System.out.println(startupProperties.getBanner());
Span currentSpan = Span.current();

currentSpan.addEvent("starting up");
currentSpan.setAttribute("isTestAttribute", true);
log.info("OSCARS starting up");

this.setInStartup(true);
if (startupProperties.getExit()) {
log.info("In Shutdown");
log.info("OSCARS shutting down");
this.setInStartup(false);
this.setInShutdown(true);
syslogger.sendSyslog("OSCARS APPLICATION SHUTDOWN COMPLETED");
System.out.println("Exiting (startup.exit is true)");
System.exit(0);
}
Expand All @@ -89,9 +85,6 @@ public void onStart() throws IOException, ConsistencyException, TopoException {
System.out.println("Exiting..");
System.exit(1);
}
log.info("OSCARS startup successful.");

syslogger.sendSyslog("OSCARS APPLICATION STARTUP COMPLETED");

this.setInStartup(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.es.oscars.app.otel;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.client.RestTemplateCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
@Slf4j
public class RestTemplateConfig {
final
OpenTelemetry openTelemetry;

public RestTemplateConfig(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
}

@Bean
public CustomRestTemplateCustomizer customRestTemplateCustomizer() {
return new CustomRestTemplateCustomizer();
}

public class CustomRestTemplateCustomizer implements RestTemplateCustomizer {
@Override
public void customize(RestTemplate restTemplate) {
log.info("adding otel to rest template");
SpringWebTelemetry telemetry = SpringWebTelemetry.create(openTelemetry);
restTemplate.getInterceptors().add(telemetry.newInterceptor());

}
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class JacksonConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer addLombokIntrospection() {
return jacksonObjectMapperBuilder -> {
log.info("customizing jackson");
jacksonObjectMapperBuilder.failOnUnknownProperties(true);
jacksonObjectMapperBuilder.modules(new JavaTimeModule());
};
Expand Down
Loading

0 comments on commit 35e1b93

Please sign in to comment.