-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathBaseHash.java
More file actions
60 lines (50 loc) · 1.73 KB
/
BaseHash.java
File metadata and controls
60 lines (50 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package datadog.trace.api;
import datadog.trace.util.FNV64Hash;
public final class BaseHash {
private static volatile long baseHash;
private static volatile String baseHashStr;
private static volatile String lastContainerTagsHash;
private BaseHash() {}
public static void recalcBaseHash(String containerTagsHash) {
lastContainerTagsHash = containerTagsHash;
updateBaseHash(calc(containerTagsHash));
}
static void recalcBaseHash() {
updateBaseHash(calc(lastContainerTagsHash));
}
public static void updateBaseHash(long hash) {
baseHash = hash;
baseHashStr = Long.toString(hash);
}
public static long getBaseHash() {
return baseHash;
}
public static String getBaseHashStr() {
return baseHashStr;
}
public static long calc(String containerTagsHash) {
return calc(
Config.get().getServiceName(),
Config.get().getEnv(),
Config.get().getPrimaryTag(),
ProcessTags.getTagsForSerialization(),
containerTagsHash);
}
private static long calc(
CharSequence serviceName,
CharSequence env,
String primaryTag,
CharSequence processTags,
String containerTagsHash) {
long hash = FNV64Hash.generateHash(serviceName.toString(), FNV64Hash.Version.v1);
hash = FNV64Hash.continueHash(hash, env.toString(), FNV64Hash.Version.v1);
if (primaryTag != null) hash = FNV64Hash.continueHash(hash, primaryTag, FNV64Hash.Version.v1);
if (processTags != null) {
hash = FNV64Hash.continueHash(hash, processTags.toString(), FNV64Hash.Version.v1);
if (containerTagsHash != null && !containerTagsHash.isEmpty()) {
hash = FNV64Hash.continueHash(hash, containerTagsHash, FNV64Hash.Version.v1);
}
}
return hash;
}
}