|
1 | 1 | /* (C) 2024 */
|
2 | 2 | package rocks.inspectit.gepard.agent.internal.identity.model;
|
3 | 3 |
|
4 |
| -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; |
5 |
| -import com.fasterxml.jackson.annotation.PropertyAccessor; |
6 |
| -import com.fasterxml.jackson.core.JsonProcessingException; |
7 |
| -import com.fasterxml.jackson.databind.ObjectMapper; |
8 | 4 | import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig;
|
9 | 5 | import io.opentelemetry.javaagent.tooling.AgentVersion;
|
10 | 6 | import java.lang.management.ManagementFactory;
|
11 | 7 | import java.lang.management.RuntimeMXBean;
|
| 8 | +import java.time.Instant; |
12 | 9 | import java.util.Map;
|
13 | 10 | import java.util.Objects;
|
14 | 11 | import rocks.inspectit.gepard.agent.internal.identity.IdentityManager;
|
15 | 12 | import rocks.inspectit.gepard.agent.internal.properties.PropertiesResolver;
|
| 13 | +import rocks.inspectit.gepard.commons.model.agent.Agent; |
16 | 14 |
|
17 | 15 | /** Meta-information about the current agent */
|
18 |
| -public class AgentInfo { |
| 16 | +public final class AgentInfo { |
19 | 17 |
|
| 18 | + /** Global instance of agent information */ |
20 | 19 | public static final AgentInfo INFO = new AgentInfo();
|
21 | 20 |
|
22 |
| - private static final ObjectMapper mapper = |
23 |
| - new ObjectMapper().setVisibility(PropertyAccessor.FIELD, Visibility.ANY); |
24 |
| - |
25 |
| - private final String serviceName; |
26 |
| - |
27 |
| - private final String gepardVersion; |
28 |
| - |
29 |
| - private final String otelVersion; |
30 |
| - |
31 |
| - private final String javaVersion; |
32 |
| - |
33 |
| - private final long startTime; |
34 |
| - |
35 |
| - private final String vmId; |
| 21 | + private final Agent agent; |
36 | 22 |
|
37 | 23 | private final String agentId;
|
38 | 24 |
|
39 |
| - private final Map<String, String> attributes; |
40 |
| - |
41 | 25 | private AgentInfo() {
|
42 | 26 | IdentityManager identityManager = IdentityManager.getInstance();
|
43 | 27 | IdentityInfo identityInfo = identityManager.getIdentityInfo();
|
44 |
| - RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); |
45 | 28 |
|
46 |
| - this.serviceName = getServiceNameFromSdk(); |
47 |
| - this.gepardVersion = "0.0.1"; |
48 |
| - this.otelVersion = AgentVersion.VERSION; |
49 |
| - this.javaVersion = System.getProperty("java.version"); |
50 |
| - this.startTime = runtime.getStartTime(); |
51 |
| - this.vmId = identityInfo.vmId(); |
| 29 | + this.agent = createAgent(identityInfo); |
52 | 30 | this.agentId = identityInfo.agentId();
|
53 |
| - this.attributes = PropertiesResolver.getAttributes(); |
54 | 31 | }
|
55 | 32 |
|
56 | 33 | /**
|
57 |
| - * @return The agent information as JSON string |
58 |
| - * @throws JsonProcessingException corrupted agent information |
| 34 | + * Creates an agent model with the current meta-information. |
| 35 | + * |
| 36 | + * @param identityInfo the agent's identity info |
| 37 | + * @return the created agent model |
| 38 | + */ |
| 39 | + private Agent createAgent(IdentityInfo identityInfo) { |
| 40 | + RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); |
| 41 | + |
| 42 | + String serviceName = getServiceNameFromSdk(); |
| 43 | + String gepardVersion = "0.0.1"; |
| 44 | + String otelVersion = AgentVersion.VERSION; |
| 45 | + String javaVersion = System.getProperty("java.version"); |
| 46 | + Instant startTime = Instant.ofEpochMilli(runtime.getStartTime()); |
| 47 | + String vmId = identityInfo.vmId(); |
| 48 | + Map<String, String> attributes = PropertiesResolver.getAttributes(); |
| 49 | + |
| 50 | + return new Agent( |
| 51 | + serviceName, gepardVersion, otelVersion, javaVersion, startTime, vmId, attributes); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @return the agent meta-information |
| 56 | + */ |
| 57 | + public Agent getAgent() { |
| 58 | + return agent; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return the agent id |
59 | 63 | */
|
60 |
| - public static String getAsString() throws JsonProcessingException { |
61 |
| - return mapper.writeValueAsString(INFO); |
| 64 | + public String getAgentId() { |
| 65 | + return agentId; |
62 | 66 | }
|
63 | 67 |
|
64 | 68 | /**
|
|
0 commit comments