Skip to content
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

Closes #818 and #819 - Branches of which a Mapping originated now displayed in UI. #869

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Button } from 'primereact/button';
import dateformat from 'dateformat';
import TimeAgo from 'react-timeago';
import { map } from 'lodash';
import classnames from 'classnames';

import ConfigurationDownload from '../mappings/ConfigurationDownload';
import { linkPrefix } from '../../../lib/configuration';
Expand Down Expand Up @@ -202,6 +203,45 @@ class StatusTable extends React.Component {
return <AgentMappingCell data={rowData} />;
};

sourceBranchTemplate = (rowData) => {
let branch = 'Unknown Branch';
if (rowData.sourceBranch) {
branch = rowData.sourceBranch;
}
const isLiveBranch = branch === 'live';
const iconClass = classnames('pi', {
'pi-circle-on': isLiveBranch,
'pi-circle-off': !isLiveBranch,
live: isLiveBranch,
workspace: !isLiveBranch,
});

return (
<>
<style jsx>{`
.this {
display: flex;
align-items: center;
}
.pi {
margin-right: 0.5rem;
}
.pi.live {
color: #ef5350;
}
.pi.workspace {
color: #616161;
}
`}</style>

<div className="this">
<i className={iconClass}></i>
<span>{branch}</span>
</div>
</>
);
};

lastFetchTemplate = ({ lastConfigFetch }) => {
return <TimeAgo date={lastConfigFetch} formatter={timeFormatter} />;
};
Expand All @@ -228,7 +268,7 @@ class StatusTable extends React.Component {
<div className="this">
<style jsx>{`
.this :global(.p-datatable) {
min-width: 1280px;
min-width: 1430px;
}

.this :global(.p-datatable) :global(th) {
Expand Down Expand Up @@ -271,6 +311,7 @@ class StatusTable extends React.Component {
style={{ width: '175px' }}
/>
<Column header="Agent Mapping" field="mappingFilter" body={this.agentMappingTemplate} sortable />
<Column header="Source Branch" field="sourceBranch" body={this.sourceBranchTemplate} style={{ width: '150px' }} sortable />
<Column header="Last Fetch" field="lastConfigFetch" body={this.lastFetchTemplate} sortable style={{ width: '200px' }} />
</DataTable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public class AgentStatus {
* If null, this means that no matching mapping was found.
*/
private String mappingName;

/**
* The branch of which the mapping delivered to the agent originates.
*/
private String sourceBranch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class AgentStatusManager {
*/
@PostConstruct
public void reset() {
attributesToAgentStatusCache = CacheBuilder
.newBuilder()
attributesToAgentStatusCache = CacheBuilder.newBuilder()
.maximumSize(config.getMaxAgents())
.expireAfterWrite(config.getAgentEvictionDelay().toMillis(), TimeUnit.MILLISECONDS)
.build();
Expand All @@ -59,6 +58,9 @@ public void notifyAgentConfigurationFetched(Map<String, String> agentAttributes,
.attributes(agentAttributes)
.lastConfigFetch(new Date())
.mappingName(resultConfiguration == null ? null : resultConfiguration.getMapping().getName())
.sourceBranch(resultConfiguration == null ? null : resultConfiguration.getMapping()
.getSourceBranch()
.getBranchName())
.build();

Object statusKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.mockito.junit.jupiter.MockitoExtension;
import rocks.inspectit.ocelot.agentconfiguration.AgentConfiguration;
import rocks.inspectit.ocelot.config.model.InspectitServerSettings;
import rocks.inspectit.ocelot.file.versioning.Branch;
import rocks.inspectit.ocelot.mappings.model.AgentMapping;

import java.time.Duration;
Expand Down Expand Up @@ -40,99 +41,80 @@ class NotifyAgentConfigurationFetched {

@Test
void testWithAgentIdHeader() {
AgentMapping agentMapping = AgentMapping.builder()
.name("test-conf")
.build();
AgentConfiguration config = AgentConfiguration.builder()
.mapping(agentMapping)
.configYaml("")
.build();
Branch testBranch = Branch.WORKSPACE;
AgentMapping agentMapping = AgentMapping.builder().name("test-conf").sourceBranch(testBranch).build();
AgentConfiguration config = AgentConfiguration.builder().mapping(agentMapping).configYaml("").build();
Map<String, String> attributes = ImmutableMap.of("service", "test");

manager.notifyAgentConfigurationFetched(attributes, Collections.singletonMap(HEADER_AGENT_ID, "aid"), config);

assertThat(manager.getAgentStatuses())
.hasSize(1)
.anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isEqualTo("test-conf");
assertThat(status.getMetaInformation().getAgentId()).isEqualTo("aid");
assertThat(status.getLastConfigFetch()).isNotNull();
});
assertThat(manager.getAgentStatuses()).hasSize(1).anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isEqualTo("test-conf");
assertThat(status.getMetaInformation().getAgentId()).isEqualTo("aid");
assertThat(status.getSourceBranch()).isEqualTo("workspace");
assertThat(status.getLastConfigFetch()).isNotNull();
});
}

@Test
void testNoMappingFound() {
Map<String, String> attributes = ImmutableMap.of("service", "test");
manager.notifyAgentConfigurationFetched(attributes, Collections.emptyMap(), null);

assertThat(manager.getAgentStatuses())
.hasSize(1)
.anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isNull();
assertThat(status.getMetaInformation()).isNull();
assertThat(status.getLastConfigFetch()).isNotNull();
});
assertThat(manager.getAgentStatuses()).hasSize(1).anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isNull();
assertThat(status.getMetaInformation()).isNull();
assertThat(status.getSourceBranch()).isNull();
assertThat(status.getLastConfigFetch()).isNotNull();
});
}


@Test
void testMappingFound() {
AgentMapping agentMapping = AgentMapping.builder()
.name("test-conf")
.build();
AgentConfiguration conf = AgentConfiguration.builder()
.mapping(agentMapping)
.configYaml("")
.build();
Branch testBranch = Branch.WORKSPACE;
AgentMapping agentMapping = AgentMapping.builder().name("test-conf").sourceBranch(testBranch).build();
AgentConfiguration conf = AgentConfiguration.builder().mapping(agentMapping).configYaml("").build();
Map<String, String> attributes = ImmutableMap.of("service", "test");

manager.notifyAgentConfigurationFetched(attributes, Collections.emptyMap(), conf);

assertThat(manager.getAgentStatuses())
.hasSize(1)
.anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isEqualTo("test-conf");
assertThat(status.getLastConfigFetch()).isNotNull();
});
assertThat(manager.getAgentStatuses()).hasSize(1).anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isEqualTo("test-conf");
assertThat(status.getSourceBranch()).isEqualTo("workspace");
assertThat(status.getLastConfigFetch()).isNotNull();
});
}

@Test
void testOverriding() throws Exception {
AgentMapping agentMapping = AgentMapping.builder()
.name("test-conf")
.build();
AgentConfiguration conf = AgentConfiguration.builder()
.mapping(agentMapping)
.configYaml("")
.build();
Branch testBranch = Branch.WORKSPACE;
AgentMapping agentMapping = AgentMapping.builder().name("test-conf").sourceBranch(testBranch).build();
AgentConfiguration conf = AgentConfiguration.builder().mapping(agentMapping).configYaml("").build();
Map<String, String> attributes = ImmutableMap.of("service", "test");

manager.notifyAgentConfigurationFetched(attributes, Collections.emptyMap(), null);

assertThat(manager.getAgentStatuses())
.hasSize(1)
.anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isNull();
assertThat(status.getLastConfigFetch()).isNotNull();
});
assertThat(manager.getAgentStatuses()).hasSize(1).anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isNull();
assertThat(status.getLastConfigFetch()).isNotNull();
});

Date firstFetch = manager.getAgentStatuses().iterator().next().getLastConfigFetch();

Thread.sleep(1);

manager.notifyAgentConfigurationFetched(attributes, Collections.emptyMap(), conf);

assertThat(manager.getAgentStatuses())
.hasSize(1)
.anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isEqualTo("test-conf");
assertThat(status.getLastConfigFetch()).isAfter(firstFetch);
});
assertThat(manager.getAgentStatuses()).hasSize(1).anySatisfy(status -> {
assertThat(status.getAttributes()).isEqualTo(attributes);
assertThat(status.getMappingName()).isEqualTo("test-conf");
assertThat(status.getSourceBranch()).isEqualTo("workspace");
assertThat(status.getLastConfigFetch()).isAfter(firstFetch);
});
}
}
}