diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 86d6bcf..3c33918 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -39,7 +39,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
- uses: github/codeql-action/init@v1
+ uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -50,7 +50,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
- uses: github/codeql-action/autobuild@v1
+ uses: github/codeql-action/autobuild@v2
# âšī¸ Command-line programs to run using the OS shell.
# đ https://git.io/JvXDl
@@ -64,4 +64,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v1
+ uses: github/codeql-action/analyze@v2
diff --git a/README.md b/README.md
index 1a358e6..5418e68 100644
--- a/README.md
+++ b/README.md
@@ -393,6 +393,13 @@ Upon completion, the page will be redirected back to the `Identity providers` pa

1. Select Assign.
+### Application Names
+Timestream JDBC driver could get the upper application name, which is collected by Timesteam. The application name is retrieved almost same for all platforms. The idea is to get all running process info by executing an OS specific command first, then do the match in the result set using the current process ID. The command for Windows is `tasklist`, it is `ps` for Linux and macOS. The application name that is retrieved does not contain any path or credential info. The examples could be referred below.
+
+For Windows if you are using a BI tool like DbVisualizer, the application name is `dbvis.exe`.
+For Linux if you are using a BI tool like DbVisualizer, the application name is `dbviscmd.sh` or `dbvisgui.sh` if it is started from command line.
+For macOS if you are using a BI tool like DBeaver, the application name is `dbeaver`.
+
# Developer Documentation
## Building the driver
diff --git a/jdbc/pom.xml b/jdbc/pom.xml
index 0369942..b61d77e 100644
--- a/jdbc/pom.xml
+++ b/jdbc/pom.xml
@@ -70,7 +70,7 @@
1.11.870
- 32.0.0-jre
+ 32.0.1-jre
5.6.2
1.15.3
2.28.2
diff --git a/jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamDriver.java b/jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamDriver.java
index 0d8e176..8902f7e 100644
--- a/jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamDriver.java
+++ b/jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamDriver.java
@@ -20,6 +20,7 @@
import org.slf4j.bridge.SLF4JBridgeHandler;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
@@ -175,9 +176,48 @@ public boolean jdbcCompliant() {
* @return the name of the currently running application.
*/
private static String getApplicationName() {
- // Currently not supported.
- // Need to implement logic to get the process ID of the current process, then check the set of running processes and pick out
+ // What we do is get the process ID of the current process, then check the set of running processes and pick out
// the one that matches the current process. From there we can grab the name of what is running the process.
+ try {
+ final String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
+ final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+
+ String command;
+ if (isWindows) {
+ command = "tasklist /fo csv /nh";
+ } else {
+ command = "ps -eo pid,comm";
+ }
+
+ final Process process = Runtime.getRuntime().exec(command);
+ try (BufferedReader input = new BufferedReader(
+ new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
+ String line;
+ if (isWindows) {
+ while ((line = input.readLine()) != null) {
+ int start = line.indexOf(",");
+ int end = line.indexOf(",", start+1);
+ if (line.substring(start+1, end).contains(pid)){
+ return line.substring(1, line.indexOf(",") - 1);
+ }
+ }
+ } else {
+ while ((line = input.readLine()) != null) {
+ line = line.trim();
+ if (line.startsWith(pid)) {
+ String appPath = line.substring(line.indexOf(" ") + 1);
+ return appPath.substring(appPath.lastIndexOf("/") + 1);
+ }
+ }
+ }
+ }
+ } catch (Exception err) {
+ // Eat the exception and fall through.
+ LOGGER.warning(
+ "An exception has occurred and ignored while retrieving the caller application name: "
+ + err.getLocalizedMessage());
+ }
+
return "Unknown";
}
diff --git a/jdbc/src/test/java/software/amazon/timestream/jdbc/TimestreamDriverTest.java b/jdbc/src/test/java/software/amazon/timestream/jdbc/TimestreamDriverTest.java
index 792e8f6..de51d17 100644
--- a/jdbc/src/test/java/software/amazon/timestream/jdbc/TimestreamDriverTest.java
+++ b/jdbc/src/test/java/software/amazon/timestream/jdbc/TimestreamDriverTest.java
@@ -66,6 +66,16 @@ void testConnectWithNullUrlNullProperties() throws SQLException {
Assertions.assertNull(driver.connect(null, null));
}
+ @Test
+ void testDriverApplicationName() throws SQLException {
+ final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+ if (isWindows) {
+ Assertions.assertEquals("java.exe", TimestreamDriver.APPLICATION_NAME);
+ } else {
+ Assertions.assertEquals("java", TimestreamDriver.APPLICATION_NAME);
+ }
+ }
+
@ParameterizedTest
@ValueSource(strings = {
Constants.URL_PREFIX,
diff --git a/pom.xml b/pom.xml
index 7d4efed..19d7136 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,7 @@
UTF-8
1.11.870
- 32.0.0-jre
+ 32.0.1-jre
5.6.2
1.15.3
3.0.0-M1