Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9217422
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 16, 2024
8d41375
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 22, 2024
4473a3d
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 22, 2024
3659653
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 22, 2024
f77f0a1
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 22, 2024
1d9d312
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 22, 2024
5df9e00
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 23, 2024
494d184
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 23, 2024
e4a6137
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 23, 2024
5bf180b
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 23, 2024
9c9c8cc
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 23, 2024
3a2f79d
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 23, 2024
c6ca01f
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 24, 2024
2217ded
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 24, 2024
2c70645
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 24, 2024
f8b8c89
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 24, 2024
777eb5e
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 25, 2024
a2f3885
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 26, 2024
f46ca46
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 29, 2024
7f444ac
igned-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 29, 2024
56a026d
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 30, 2024
e1c4157
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
ejannett Jul 31, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Signed-off-by: Emmanuel Jannetti <emmanuel.jannetti@oracle.com>
warm up pools add reset stats endpoint
  • Loading branch information
ejannett committed Jul 31, 2024
commit e1c4157ad490b5dac03080928c917887d23f36e1
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,27 @@
import com.oracle.jdbc.samples.statementinterceptordemo.services.EmployeeService;
import com.oracle.jdbc.samples.statementinterceptordemo.utils.WebViolationHandler;
import lombok.extern.java.Log;
import oracle.ucp.jdbc.PoolDataSourceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.logging.Logger;

@SpringBootApplication
@Log
public class StatementInterceptorDemoApplication {

@Autowired @Qualifier("interceptedDataSource") DataSource DataSource1;
@Autowired DataSource DataSource2;

public static void main(String[] args) {
SpringApplication.run(StatementInterceptorDemoApplication.class, args);
}
Expand All @@ -49,6 +59,13 @@ public CommandLineRunner commandLineRunner(final EmployeeService service) {
service.initialize();
log.info("Employees data Initialized");

log.info("starting connection pools ...");
// That's ususally not needed but for the sake of the demo
// we forcefully start the pool
((PoolDataSourceImpl)DataSource1).startPool();
((PoolDataSourceImpl)DataSource2).startPool();
log.info("Pools started...");

// add our handler to violation logger
Logger.getLogger(SQLStatementInterceptor.ACTION_LOGGER_NAME)
.addHandler(new WebViolationHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

import lombok.AllArgsConstructor;
import lombok.extern.java.Log;
import oracle.ucp.UniversalConnectionPool;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;
import oracle.ucp.jdbc.PoolDataSourceImpl;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -139,8 +141,6 @@ public DataSource getInterceptedDataSource() throws SQLException {
dataSource.setConnectionProperty("oracle.jdbc.provider.traceEventListener",
"com.oracle.jdbc.samples.interceptor.SQLStatementInterceptorProvider");



String rules;
try {
rules = getStatementRulesAsJSONString();
Expand Down Expand Up @@ -168,10 +168,7 @@ public DataSource getInterceptedDataSource() throws SQLException {
public JdbcTemplate getInterceptedJdbcTemplate() throws SQLException {
long start = System.currentTimeMillis();
InstrumentedJdbcTemplate t = new InstrumentedJdbcTemplate(getInterceptedDataSource(), "traced");
// be sure the pool is warm
t.execute("SELECT 1 FROM DUAL");
log.log(Level.INFO,"traced template init time " + (System.currentTimeMillis() - start) + "ms");
t.getStatistic().clear();
return t;
}

Expand All @@ -186,10 +183,7 @@ public JdbcTemplate getInterceptedJdbcTemplate() throws SQLException {
public JdbcTemplate getJdbcTemplate() throws SQLException {
long start = System.currentTimeMillis();
InstrumentedJdbcTemplate t = new InstrumentedJdbcTemplate(getDataSource(), "untraced");
// be sure the pool is warm
t.execute("SELECT 1 FROM DUAL");
log.log(Level.INFO,"untraced template init time " + (System.currentTimeMillis() - start) + "ms");
t.getStatistic().clear();
return t;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public class Statistic {
/**
* minimum operation time in milliseconds
*/
private double minTime;
private double minTime = -1.0;
/**
* maximum operation time in milliseconds
*/
private double maxTime;
private double maxTime = -1.0;;
/**
* total operation time in milliseconds
*/
Expand All @@ -61,10 +61,11 @@ public class Statistic {
*/
public void accumulate(long l) {
if (l < minTime || minTime == -1.0) {
minTime = l;
}
minTime = l;
if (l > maxTime)
if (l > maxTime) {
maxTime = l;
}
count++;
totalTime += l;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ public interface StatisticService {
* @return the statistic or null if no such statistic for this tag is found
*/
Statistic getRequestStatistics(String tag);

/**
* Resets all registered statistics.
* All counters will be set ot zero
*/
void resetAllStatistics();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ public Statistic getRequestStatistics(String tag) {
.findFirst()
.orElse(null);
}

@Override
public void resetAllStatistics() {
allStats.stream().forEach(s->{s.clear();});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
import com.oracle.jdbc.samples.statementinterceptordemo.utils.WebViolationHandler;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.java.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
Expand Down Expand Up @@ -108,6 +110,12 @@ public ModelAndView getStats() {
return modelAndView;
}

@DeleteMapping("interceptor/stats")
public @ResponseBody ResponseEntity<String> delete() {
statService.resetAllStatistics();
return new ResponseEntity<String>("DELETE Response", HttpStatus.OK);
}

@GetMapping("interceptor/logs")
public ModelAndView getLogs(HttpServletRequest request,
@RequestParam(name = "uuid", required = true) String uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ connection-factory-class-name=oracle.jdbc.pool.OracleDataSource
username=${DATABASE_USER}
password=${DATABASE_PASSWORD}
url=${DATABASE_URL}
sql-for-validate-connection=select * from dual
sql-for-validate-connection=select 1 from dual
connection-pool-name=DemoUcpPool
initial-pool-size=1
min-pool-size=1
max-pool-size=5
initial-pool-size=5
min-pool-size=2
max-pool-size=10