-
Notifications
You must be signed in to change notification settings - Fork 4
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(RD-12769): add execution tags #71
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.lumigo.core.utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.HashMap; | ||
import org.pmw.tinylog.Logger; | ||
|
||
public class ExecutionTags { | ||
private static final int MAX_TAG_KEY_LEN = 100; | ||
private static final int MAX_TAG_VALUE_LEN = 100; | ||
private static final int MAX_TAGS = 50; | ||
private static final String ADD_TAG_ERROR_MSG_PREFIX = "Error adding tag"; | ||
|
||
private static final List<Map<String, String>> tags = new ArrayList<>(); | ||
|
||
private static boolean validateTag(String key, String value, boolean shouldLogErrors) { | ||
key = String.valueOf(key); | ||
value = String.valueOf(value); | ||
if (key.isEmpty() || key.length() > MAX_TAG_KEY_LEN) { | ||
if (shouldLogErrors) { | ||
Logger.error(String.format("%s: key length should be between 1 and %d: %s - %s", | ||
ADD_TAG_ERROR_MSG_PREFIX, MAX_TAG_KEY_LEN, key, value)); | ||
} | ||
return false; | ||
} | ||
if (value.isEmpty() || value.length() > MAX_TAG_VALUE_LEN) { | ||
if (shouldLogErrors) { | ||
Logger.error(String.format("%s: value length should be between 1 and %d: %s - %s", | ||
ADD_TAG_ERROR_MSG_PREFIX, MAX_TAG_VALUE_LEN, key, value)); | ||
} | ||
return false; | ||
} | ||
if (tags.size() >= MAX_TAGS) { | ||
if (shouldLogErrors) { | ||
Logger.error(String.format("%s: maximum number of tags is %d: %s - %s", | ||
ADD_TAG_ERROR_MSG_PREFIX, MAX_TAGS, key, value)); | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private static String normalizeTag(Object val) { | ||
return (val == null) ? null : String.valueOf(val); | ||
} | ||
|
||
public static void addTag(String key, String value, boolean shouldLogErrors) { | ||
try { | ||
Logger.info(String.format("Adding tag: %s - %s", key, value)); | ||
if (!validateTag(key, value, shouldLogErrors)) { | ||
return; | ||
} | ||
Map<String, String> tag = new HashMap<>(); | ||
tag.put("key", normalizeTag(key)); | ||
tag.put("value", normalizeTag(value)); | ||
tags.add(tag); | ||
} catch (Exception err) { | ||
if (shouldLogErrors) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im not sure why you need this condition? you are logging the error either way |
||
Logger.error(ADD_TAG_ERROR_MSG_PREFIX); | ||
} | ||
Logger.error(err.getMessage()); | ||
} | ||
} | ||
|
||
public static List<Map<String, String>> getTags() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets make getTags & clearTags package private methods, I dont want to expose them to users |
||
return new ArrayList<>(tags); | ||
} | ||
|
||
public static void clear() { | ||
tags.clear(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
import io.lumigo.core.instrumentation.agent.Installer; | ||
import io.lumigo.core.network.Reporter; | ||
import io.lumigo.core.utils.EnvUtil; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
@@ -73,4 +75,16 @@ public OUTPUT handleRequest(INPUT input, Context context) { | |
} | ||
|
||
public abstract OUTPUT doHandleRequest(INPUT input, Context context); | ||
|
||
public void addExecutionTag(String key, String value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I talked with Harel and we agreed that we dont want to add this here, lets expose those methods from the |
||
spansContainer.addExecutionTag(key, value); | ||
} | ||
|
||
public void clearExecutionTags() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the only method that should be exposed to the user is |
||
spansContainer.clearExecutionTags(); | ||
} | ||
|
||
public Map<String, String> getExecutionTags() { | ||
return spansContainer.getExecutionTags(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we want the
shouldLogErrors
did you see it in the other tracers?