Skip to content

Instantly share code, notes, and snippets.

View pgomulka's full-sized avatar
🏠
Working from home

Przemyslaw Gomulka pgomulka

🏠
Working from home
View GitHub Profile
@pgomulka
pgomulka / gist:5f5376433a1a242b0016eb2d2e162d02
Created June 27, 2024 14:11
log4j2.properties without console
status = error
######## Server JSON ############################
appender.rolling.type = RollingFile
appender.rolling.name = rolling
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.json
appender.rolling.layout.type = ECSJsonLayout
appender.rolling.layout.dataset = elasticsearch.server
sh-5.0$ cat config/log4j2.file.properties
status = error
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %m%consoleException%n
######## Server JSON ############################
appender.rolling.type = RollingFile
@pgomulka
pgomulka / charge.java
Created March 6, 2024 13:55
charge.java
private void charge(Token token) throws IOException {
if (token != null) {
var sizeInBits = switch (token) {
case FIELD_NAME, VALUE_STRING -> textLength() * Character.SIZE;
case VALUE_EMBEDDED_OBJECT -> calculateBase64Length(binaryValue().length) * Character.SIZE;
case VALUE_NUMBER -> Long.SIZE;
case VALUE_BOOLEAN -> 1;
default -> 0;
};
counter.addAndGet(sizeInBits);
@pgomulka
pgomulka / length.java
Created March 6, 2024 13:52
calculateTextLength
private int calculateTextLength() throws IOException {
char[] charArray = textCharacters();
int byteLength = 0;
int limit = textOffset() + textLength();
for (int i = textOffset(); i < limit; ) {
int codePoint = Character.codePointAt(charArray, i, limit);
int charCount = Character.charCount(codePoint);
i += charCount;
@pgomulka
pgomulka / gist:56d25795306bb210b6bd2c0282dcb119
Created December 5, 2023 15:03
Example apm metrics sent
MockApmServer reading JSON objects: {"metadata":{"service":{"name":"elasticsearch","environment":"dev","agent":{"name":"java","ephemeral_id":"a9df46d3-bdac-4da4-ae7d-5196098b2f1c","version":"1.44.0"},"language":{"name":"Java","version":"21"},"node":{"configured_name":"runTask-0"},"runtime":{"name":"Java","version":"21"},"version":"8.12.0"},"process":{"pid":26482,"ppid":26451,"title":"/Users/przemyslawgomulka/.gradle/jdks/oracle_corporation-21-aarch64-os_x/jdk-21.jdk/Contents/Home/bin/java"},"system":{"architecture":"aarch64","hostname":"przemyslaws-macbook-pro-2.local","platform":"Mac OS X"}}}
{"metricset":{"timestamp":1701782037090000,"samples":{"system.process.cpu.total.norm.pct":{"value":0.036495748116523105},"jvm.memory.heap.used":{"value":325615048.0},"jvm.memory.non_heap.used":{"value":207566896.0},"jvm.memory.heap.max":{"value":536870912.0},"jvm.fd.used":{"value":482.0},"jvm.gc.alloc":{"value":209842672.0},"jvm.memory.non_heap.committed":{"value":213909504.0},"system.cpu.total.norm.pct":{"value":0.565
@pgomulka
pgomulka / gist:11e41c466c7b4b1607c5ed596d06586e
Created October 22, 2023 11:41
total sum of segment size
total sum of segment size
curl -H "Authorization: ApiKey $API_KEY" -H "Content-Type: application/json" \
"${ENV_URL}/api/v1/admin/serverless/projects/${PROJECT_TYPE}/${PROJECT_ID}/_proxy/_cat/segments/.ds-logs-kubernetes.container_logs-default-2023.10.12-000001?v"
index shard prirep ip segment generation docs.count docs.deleted size size.memory committed searchable version compound
.ds-logs-kubernetes.container_logs-default-2023.10.12-000001 0 p 10.2.96.111 _qyd 34933 39873257 0 13.1gb 0 true true 9.8.0 false
.ds-logs-kubernetes.container_logs-default-2023.10.12-000001 0 p 10.2.96.111 _10ep 47185 14514879 0 4.5gb 0 true true 9.8.0 false
.ds-logs-kubernetes.container_logs-default-2023.10.12-000001 0 p 10.2.96.111 _1kqm 73534 30088453 0 9.9gb 0 true true 9.8.0 false
.ds-logs-kuberne
@pgomulka
pgomulka / gist:f5896cae9d073e24d70e0beae4ba0215
Created October 22, 2023 10:39
allocation explain response
{
"note": "No shard was specified in the explain API request, so this response explains a randomly chosen unassigned shard. There may be other unassigned shards in this cluster which cannot be assigned for different reasons. It may not be possible to assign this shard until one of the other shards is assigned correctly. To explain the allocation of other shards (whether assigned or unassigned) you must specify the target shard in the request to this API.",
"index": ".ds-logs-kubernetes.container_logs-default-2023.10.12-000001",
"shard": 0,
"primary": false,
"current_state": "unassigned",
"unassigned_info": {
"reason": "UNPROMOTABLE_REPLICA",
"at": "2023-10-22T08:52:24.099Z",
"details": "failed shard on node [lQ3Agb-VQBy9d9g0t3DwCg]: shard failure, reason [merge failed], failure org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: merge_exception: java.lang.IllegalStateException: this writer hit an unrecoverable error; cannot merge\n\tat org.elasticsearch.index.engine.Int
./gradlew run --with-apm-server
ps aux | grep java
przemyslawgomulka 81083 0.3 10.7 429330592 7206672 ?? Ss 3:22PM 5:02.59 /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home/bin/java -XX:+HeapDumpOnOutOfMemoryError -Xss2m --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Dfile.encoding=UTF-8 -Duser.country=PL -Duser.language=en -Duser.variant -cp /Users/przemyslawgomulka/.gradle/w
@pgomulka
pgomulka / gist:675a34b9f83fd32400598320b0da3ae8
Created September 27, 2023 12:45
security manager - getclassloader apm
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:488) ~[?:?]
at java.security.AccessController.checkPermission(AccessController.java:1071) ~[?:?]
at java.lang.SecurityManager.checkPermission(SecurityManager.java:411) ~[?:?]
at java.lang.ClassLoader.checkClassLoaderPermission(ClassLoader.java:2084) ~[?:?]
at java.lang.ClassLoader.getSystemClassLoader(ClassLoader.java:1972) ~[?:?]
at net.bytebuddy.dynamic.ClassFileLocator$ForClassLoader$WeaklyReferenced.of(ClassFileLocator.java:522) ~[elastic-apm-agent-1.42.1-SNAPSHOT.jar:1.42.1-SNAPSHOT]
at net.bytebuddy.agent.builder.AgentBuilder$LocationStrategy$ForClassLoader$2.classFileLocator(AgentBuilder.java:4728) ~[elastic-apm-agent-1.42.1-SNAPSHOT.jar:1.42.1-SNAPSHOT]
at net.bytebuddy.agent.builder.AgentBuilder$LocationStrategy$Compound.classFileLocator(AgentBuilder.java:4852
@pgomulka
pgomulka / gist:cb194edc0567f9482a563298e857652c
Created September 14, 2023 16:06
apm logs with exceptions
2023-09-13 09:54:11,193 [elasticsearch[runCluster-0][management][T#3]] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - decrement references to 'retention_lease_background_sync' 00-fa2d8898c7a57528153c837ca4197e9e-4ac43b6bcd40ee8e-00 (4f7dd38c) (3)
2023-09-13 09:54:11,219 [elasticsearch[runCluster-0][management][T#3]] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - decrement references to 'retention_lease_background_sync' 00-fa2d8898c7a57528153c837ca4197e9e-4ac43b6bcd40ee8e-00 (4f7dd38c) (2)
2023-09-13 09:54:11,219 [elasticsearch[runCluster-0][management][T#3]] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - decrement references to 'indices:admin/seq_no/retention_lease_background_sync[p]' 00-fa2d8898c7a57528153c837ca4197e9e-4ac43b6bcd40ee8e-00 (79b3a0f9) (1)
2023-09-13 09:54:11,312 [elasticsearch[runCluster-0][management][T#4]] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to '' 00-a92e53732a60448e8714d9559c23c5c1-50c7fa9781693e6d-00 (12318586)