Skip to content

Commit

Permalink
addressing PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Sep 29, 2020
1 parent e7d9da2 commit 76e0c76
Showing 1 changed file with 124 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,149 +6,158 @@

import { getConnections } from './get_service_map_from_trace_ids';
import { Connection, ConnectionNode } from '../../../common/service_map';
import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';

function getConnectionsPairs(connections: Connection[]) {
return connections
.map((conn) => {
const source = `${conn.source['service.name']}:${conn.source['service.environment']}`;
const destination = `${conn.destination['service.name']}:${conn.destination['service.environment']}`;
if (conn.destination['service.name']) {
return `${source} -> ${destination}`;
}
const destination = conn.destination['service.name']
? `${conn.destination['service.name']}:${conn.destination['service.environment']}`
: conn.destination['span.type'];
return `${source} -> ${destination}`;
})
.filter((_) => _)
.sort();
}

const paths = [
[
{
'service.environment': 'production',
'service.name': 'opbeans-go',
'agent.name': 'go',
},
{
'service.environment': 'production',
'service.name': 'opbeans-java',
'agent.name': 'java',
},
{
'span.subtype': 'http',
'span.destination.service.resource': '172.18.0.6:3000',
'span.type': 'external',
},
],
[
{
'service.environment': 'testing',
'service.name': 'opbeans-python',
'agent.name': 'python',
},
{
'service.environment': 'testing',
'service.name': 'opbeans-node',
'agent.name': 'nodejs',
},
{
'span.subtype': 'http',
'span.destination.service.resource': '172.18.0.6:3000',
'span.type': 'external',
},
],
] as ConnectionNode[][];

describe('getConnections', () => {
describe('if neither service name or environment is given', () => {
it('includes all connections', () => {
const connections = getConnections({
paths,
serviceName: undefined,
environment: undefined,
describe('with environments defined', () => {
const paths = [
[
{
'service.environment': 'production',
'service.name': 'opbeans-go',
'agent.name': 'go',
},
{
'service.environment': 'production',
'service.name': 'opbeans-java',
'agent.name': 'java',
},
{
'span.subtype': 'http',
'span.destination.service.resource': '172.18.0.6:3000',
'span.type': 'external',
},
],
[
{
'service.environment': 'testing',
'service.name': 'opbeans-python',
'agent.name': 'python',
},
{
'service.environment': 'testing',
'service.name': 'opbeans-node',
'agent.name': 'nodejs',
},
{
'span.subtype': 'http',
'span.destination.service.resource': '172.18.0.6:3000',
'span.type': 'external',
},
],
] as ConnectionNode[][];
describe('if neither service name or environment is given', () => {
it('includes all connections', () => {
const connections = getConnections({
paths,
serviceName: undefined,
environment: undefined,
});
const connectionsPairs = getConnectionsPairs(connections);
expect(connectionsPairs).toEqual([
'opbeans-go:production -> opbeans-java:production',
'opbeans-java:production -> external',
'opbeans-node:testing -> external',
'opbeans-python:testing -> opbeans-node:testing',
]);
});
const connectionsPairs = getConnectionsPairs(connections);
expect(connectionsPairs).toEqual([
'opbeans-go:production -> opbeans-java:production',
'opbeans-python:testing -> opbeans-node:testing',
]);
});
});

describe('if service name and environment are given', () => {
it('shows all connections for opbeans-java and production', () => {
const connections = getConnections({
paths,
serviceName: 'opbeans-java',
environment: 'production',
});

const connectionsPairs = getConnectionsPairs(connections);
describe('if service name and environment are given', () => {
it('shows all connections for opbeans-java and production', () => {
const connections = getConnections({
paths,
serviceName: 'opbeans-java',
environment: 'production',
});

expect(connectionsPairs).toEqual([
'opbeans-go:production -> opbeans-java:production',
]);
});
const connectionsPairs = getConnectionsPairs(connections);

it('shows all connections for opbeans-python and testing', () => {
const connections = getConnections({
paths,
serviceName: 'opbeans-python',
environment: 'testing',
expect(connectionsPairs).toEqual([
'opbeans-go:production -> opbeans-java:production',
'opbeans-java:production -> external',
]);
});

const connectionsPairs = getConnectionsPairs(connections);
it('shows all connections for opbeans-python and testing', () => {
const connections = getConnections({
paths,
serviceName: 'opbeans-python',
environment: 'testing',
});

expect(connectionsPairs).toEqual([
'opbeans-python:testing -> opbeans-node:testing',
]);
});
});
const connectionsPairs = getConnectionsPairs(connections);

describe('if service name is given', () => {
it('shows all connections for opbeans-node', () => {
const connections = getConnections({
paths,
serviceName: 'opbeans-node',
environment: undefined,
expect(connectionsPairs).toEqual([
'opbeans-node:testing -> external',
'opbeans-python:testing -> opbeans-node:testing',
]);
});

const connectionsPairs = getConnectionsPairs(connections);

expect(connectionsPairs).toEqual([
'opbeans-python:testing -> opbeans-node:testing',
]);
});
});

describe('if environment is given', () => {
it('shows all connections for testing environment', () => {
const connections = getConnections({
paths,
serviceName: undefined,
environment: 'testing',
});
describe('if service name is given', () => {
it('shows all connections for opbeans-node', () => {
const connections = getConnections({
paths,
serviceName: 'opbeans-node',
environment: undefined,
});

const connectionsPairs = getConnectionsPairs(connections);
const connectionsPairs = getConnectionsPairs(connections);

expect(connectionsPairs).toEqual([
'opbeans-python:testing -> opbeans-node:testing',
]);
});
it('shows all connections for production environment', () => {
const connections = getConnections({
paths,
serviceName: undefined,
environment: 'production',
expect(connectionsPairs).toEqual([
'opbeans-node:testing -> external',
'opbeans-python:testing -> opbeans-node:testing',
]);
});
});

const connectionsPairs = getConnectionsPairs(connections);
describe('if environment is given', () => {
it('shows all connections for testing environment', () => {
const connections = getConnections({
paths,
serviceName: undefined,
environment: 'testing',
});

expect(connectionsPairs).toEqual([
'opbeans-go:production -> opbeans-java:production',
]);
const connectionsPairs = getConnectionsPairs(connections);

expect(connectionsPairs).toEqual([
'opbeans-node:testing -> external',
'opbeans-python:testing -> opbeans-node:testing',
]);
});
it('shows all connections for production environment', () => {
const connections = getConnections({
paths,
serviceName: undefined,
environment: 'production',
});

const connectionsPairs = getConnectionsPairs(connections);

expect(connectionsPairs).toEqual([
'opbeans-go:production -> opbeans-java:production',
'opbeans-java:production -> external',
]);
});
});
});

describe('if environment is "not defined"', () => {
describe('environment is "not defined"', () => {
it('shows all connections where environment is not set', () => {
const environmentNotDefinedPaths = [
[
Expand Down Expand Up @@ -189,12 +198,14 @@ describe('getConnections', () => {
const connections = getConnections({
paths: environmentNotDefinedPaths,
serviceName: undefined,
environment: 'ENVIRONMENT_NOT_DEFINED',
environment: ENVIRONMENT_NOT_DEFINED.value,
});

const connectionsPairs = getConnectionsPairs(connections);
expect(connectionsPairs).toEqual([
'opbeans-go:null -> opbeans-java:null',
'opbeans-java:null -> external',
'opbeans-node:null -> external',
'opbeans-python:null -> opbeans-node:null',
]);
});
Expand Down

0 comments on commit 76e0c76

Please sign in to comment.