Skip to content

Commit

Permalink
Fix remaining review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
binarycoded committed Oct 31, 2024
1 parent 6d932a8 commit 6cec64f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public class IdentityManager {

private IdentityManager() {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String pidAtHostname = runtime.getName();
this.identityInfo =
new IdentityInfo(runtime.getPid(), pidAtHostname.split("@")[1], hash(pidAtHostname));
String vmId = runtime.getName();
this.identityInfo = new IdentityInfo(vmId, hash(vmId));
}

public static IdentityManager getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class AgentInfo {

private final long startTime;

private final long pid;

private final String hostname;
private final String vmId;

private final String agentId;

Expand All @@ -50,8 +48,7 @@ private AgentInfo() {
this.otelVersion = AgentVersion.VERSION;
this.javaVersion = System.getProperty("java.version");
this.startTime = runtime.getStartTime();
this.pid = identityInfo.pid();
this.hostname = identityInfo.hostname();
this.vmId = identityInfo.vmId();
this.agentId = identityInfo.agentId();
this.attributes = PropertiesResolver.getAttributes();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@

public final class IdentityInfo {

private final long pid;
private final String hostname;
private final String vmId;
private final String agentId;

public IdentityInfo(long pid, String hostname, String agentId) {
this.pid = pid;
this.hostname = hostname;
public IdentityInfo(String vmId, String agentId) {
this.vmId = vmId;
this.agentId = agentId;
}

public long pid() {
return pid;
}

public String hostname() {
return hostname;
public String vmId() {
return vmId;
}

public String agentId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class IdentityManagerTest {
@Test
void testCreateIdentityManagerSuccessfully() {
RuntimeMXBean mockRuntimeMXBean = mock(RuntimeMXBean.class);
when(mockRuntimeMXBean.getPid()).thenReturn(12345L);
when(mockRuntimeMXBean.getName()).thenReturn("12345@mockedHostName");

try (MockedStatic<ManagementFactory> managementFactoryMockedStatic =
Expand All @@ -33,8 +32,7 @@ void testCreateIdentityManagerSuccessfully() {
IdentityInfo identityInfo = identityManager.getIdentityInfo();

assertNotNull(identityInfo);
assertEquals("mockedHostName", identityInfo.hostname());
assertEquals(12345L, identityInfo.pid());
assertEquals("12345@mockedHostName", identityInfo.vmId());
assertEquals(
"d29aca592fc2071bcef6577d649071d4d54a8ae6cd5c0be0e51f28af2867f207",
identityInfo.agentId());
Expand Down

0 comments on commit 6cec64f

Please sign in to comment.