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

feat: logger #104

Merged
merged 23 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ replay_pid*
!metabase/ojdbc8-full/**
!metabase/InstallCert.class
!Install
.idea
36 changes: 36 additions & 0 deletions charts/nr-metabase/templates/metabase/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "metabase.fullname" . }}
labels:
{{- include "metabase.labels" . | nindent 4 }}
data:
log4j2.xml: |-
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%date %level %logger{2} :: %message%n%throwable">
<replace regex=":basic-auth \\[.*\\]" replacement=":basic-auth [redacted]"/>
</PatternLayout>
</Console>
</Appenders>

<Loggers>
<Logger name="com.mchange" level="ERROR"/>
<Logger name="liquibase" level="ERROR"/>
<Logger name="metabase" level="INFO"/>
<Logger name="metabase-enterprise" level="INFO"/>
<Logger name="metabase.metabot" level="INFO"/>
<Logger name="metabase.plugins" level="INFO"/>
<Logger name="metabase.query-processor.async" level="INFO"/>
<Logger name="metabase.server.middleware" level="INFO"/>
<Logger name="org.quartz" level="INFO"/>
<Logger name="net.snowflake.client.jdbc.SnowflakeConnectString" level="ERROR"/>
<Logger name="net.snowflake.client.core.SessionUtil" level="FATAL"/>

<Root level="WARN">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
18 changes: 12 additions & 6 deletions charts/nr-metabase/templates/metabase/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,26 @@ spec:
path: /api/health
port: http
initialDelaySeconds: 120
periodSeconds: 5
periodSeconds: 30
timeoutSeconds: 3
failureThreshold: 30
failureThreshold: 2
readinessProbe:
httpGet:
path: /api/health
port: http
initialDelaySeconds: 10
periodSeconds: 5
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 50
failureThreshold: 5
resources:
{{- toYaml .Values.metabase.resources | nindent 12 }}

volumeMounts:
- name: log4j
mountPath: /mnt/conf
volumes:
- name: log4j
configMap:
name: {{ template "metabase.fullname" . }}
{{- with .Values.metabase.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
51 changes: 51 additions & 0 deletions metabase/Enc.Java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.util.Base64;
public class Enc {
public static void main(String[] args) throws Exception {
if(args == null){
System.err.println("args is null");
System.exit(1);
}
if(args.length < 2){
System.err.println("args needs to provide key and iv");
System.exit(1);
}
// Your AES-256 key (32 bytes)
String key = args[0];

// The initialization vector (IV) (16 bytes)
String iv = args[1];

// The string to be encrypted
String plaintext = args[2];

// Encrypt the string
byte[] encryptedBytes = encrypt(plaintext, key, iv);
String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes);
System.out.println("Encrypted: " + encryptedText);
System.out.println("\n\n\n\n\n");

// Decrypt the string
String decryptedText = decrypt(Base64.getDecoder().decode(encryptedText), key, iv);
System.out.println("Decrypted: " + decryptedText);
}

public static byte[] encrypt(String plaintext, String key, String iv) throws Exception {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");
IvParameterSpec initVector = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, secretKey, initVector);
return cipher.doFinal(plaintext.getBytes());
}

public static String decrypt(byte[] encryptedBytes, String key, String iv) throws Exception {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");
IvParameterSpec initVector = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.DECRYPT_MODE, secretKey, initVector);
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
return new String(decryptedBytes);
}
}
30 changes: 30 additions & 0 deletions metabase/enc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const crypto = require('crypto');

function encrypt(plaintext, key, iv) {
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), Buffer.from(iv));
let encrypted = cipher.update(plaintext, 'utf8', 'base64');
encrypted += cipher.final('base64');
return encrypted;
}

function decrypt(encryptedText, key, iv) {
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(key), Buffer.from(iv), { 'padding': 'pkcs7' });
let decrypted = decipher.update(encryptedText, 'base64', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}

if (process.argv.length < 4) {
console.error('Usage: node encrypt.js <key> <iv>');
process.exit(1);
}

const key = process.argv[2];
const iv = process.argv[3];
const plaintext = 'abc';

const encryptedText = encrypt(plaintext, key, iv);
console.log('Encrypted:', encryptedText);

const decryptedText = decrypt(encryptedText, key, iv);
console.log('Decrypted:', decryptedText);
28 changes: 23 additions & 5 deletions metabase/run_app.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
DB_HOST_PORT_ENV=${DB_HOST_PORT_ENV}
cert_folder="/opt"
MAX_HEAP=${MAX_HEAP:-750m}
MIN_HEAP=${MIN_HEAP:-750m}
echo "DB_HOST_PORT_ENV is $DB_HOST_PORT_ENV"
if [ -z "$DB_HOST_PORT_ENV" ]; then
DB_HOST_PORT_ENV=nrcdb01.bcgov:1543,nrcdb03.bcgov:1543,nrkdb01.bcgov:1543,nrkdb03.bcgov:1543,nrcdb02.bcgov:1543,nrkdb02.bcgov:1543
Expand All @@ -17,10 +20,25 @@ echo "Adding certs"
echo "DB_PORT is $DB_PORT"
echo "I will try to get the ${DB_HOST}-1 cert"
echo "Connecting to ${DB_HOST}:${DB_PORT}"
java InstallCert --quiet "${DB_HOST}:${DB_PORT}"
keytool -exportcert -alias "$DB_HOST-1" -keystore jssecacerts -storepass changeit -file /opt/"$DB_HOST-1.cer"
keytool -importcert -alias "orakey-$DB_HOST-1" -noprompt -keystore "${JAVA_HOME}"/lib/security/cacerts -storepass changeit -file /opt/"$DB_HOST-1.cer"
openssl s_client -connect "${DB_HOST}:${DB_PORT}" -showcerts </dev/null | openssl x509 -outform pem >"$cert_folder/${DB_HOST}.pem" || exit 1
openssl x509 -outform der -in "$cert_folder/${DB_HOST}.pem" -out "$cert_folder/${DB_HOST}.der" || exit 1
keytool -import -alias "orakey-${DB_HOST}-1" -keystore "${JAVA_HOME}"/lib/security/cacerts -storepass changeit -file "$cert_folder/${DB_HOST}.der" -noprompt || exit 1
done

echo "Starting Metabase"
java -Duser.name=metabase -Xms750m -Xmx750m -XX:TieredStopAtLevel=2 -XX:+UseParallelGC -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=350m -XX:ParallelGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=4 -XX:CICompilerCount=2 -XX:+ExitOnOutOfMemoryError -jar metabase.jar
echo -e "\033[1;33m=====================================\033[0m" # Bright Yellow
echo -e "\033[0;36m _ _ ____ __ __ ____ \033[0m" # Cyan
echo -e "\033[0;36m | \ | | _ \ | \/ | __ ) \033[0m" # Cyan
echo -e "\033[0;36m | \| | |_) | | |\/| | _ \ \033[0m" # Cyan
echo -e "\033[0;36m | |\ | _ < | | | | |_) |\033[0m" # Cyan
echo -e "\033[0;36m |_| \_|_| \_\ |_| |_|____/ \033[0m" # Cyan
echo -e "\033[0;36m \033[0m" # Cyan
echo -e "\033[1;33m=====================================\033[0m" # Bright Yellow

if [ -f /mnt/conf/log4j2.xml ]; then
echo "/mnt/conf/log4j2.xml exists."
java -Duser.name=metabase "-Xms${MIN_HEAP}" "-Xmx${MAX_HEAP}" -XX:TieredStopAtLevel=2 -XX:+UseZGC -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=350m -XX:ParallelGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=4 -XX:CICompilerCount=2 -XX:+ExitOnOutOfMemoryError -Dlog4j.configurationFile=file:/config/log4j2.xml -jar metabase.jar
else
echo "/mnt/conf/log4j2.xml does not exist."
java -Duser.name=metabase "-Xms${MIN_HEAP}" "-Xmx${MAX_HEAP}" -XX:TieredStopAtLevel=2 -XX:+UseZGC -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=350m -XX:ParallelGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=4 -XX:CICompilerCount=2 -XX:+ExitOnOutOfMemoryError -jar metabase.jar
fi

Loading