Skip to content

Commit 2a5e909

Browse files
authored
Merge pull request #320 from snyk/chore/ci-improvements
Chore/ci improvements
2 parents bf0ecdf + 2fdc0f0 commit 2a5e909

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
"test": "npm run lint && npm run build && npm run test:unit && npm run test:integration",
88
"test:unit": "NODE_ENV=test tap test/unit",
99
"test:system": "tap test/system --timeout=600",
10-
"test:integration": "TEST_PLATFORM=kind CREATE_CLUSTER=true tap test/integration/kubernetes.test.ts --timeout=1200",
11-
"test:integration:kind": "TEST_PLATFORM=kind CREATE_CLUSTER=true tap test/integration/kubernetes.test.ts --timeout=1200",
12-
"test:integration:eks": "TEST_PLATFORM=eks CREATE_CLUSTER=false tap test/integration/kubernetes.test.ts --timeout=1200",
10+
"test:integration": "TEST_PLATFORM=kind CREATE_CLUSTER=true tap test/integration/kubernetes.test.ts --timeout=900",
11+
"test:integration:kind": "TEST_PLATFORM=kind CREATE_CLUSTER=true tap test/integration/kubernetes.test.ts --timeout=900",
12+
"test:integration:eks": "TEST_PLATFORM=eks CREATE_CLUSTER=false tap test/integration/kubernetes.test.ts --timeout=900",
1313
"test:coverage": "npm run test:unit -- --coverage",
1414
"test:watch": "tsc-watch --onSuccess 'npm run test:unit'",
15-
"test:apk": "TEST_PLATFORM=kind CREATE_CLUSTER=true PACKAGE_MANAGER=apk tap test/integration/package-manager.test.ts --timeout=7200",
16-
"test:apt": "TEST_PLATFORM=kind CREATE_CLUSTER=true PACKAGE_MANAGER=apt tap test/integration/package-manager.test.ts --timeout=7200",
17-
"test:rpm": "TEST_PLATFORM=kind CREATE_CLUSTER=true PACKAGE_MANAGER=rpm tap test/integration/package-manager.test.ts --timeout=7200",
15+
"test:apk": "TEST_PLATFORM=kind CREATE_CLUSTER=true PACKAGE_MANAGER=apk tap test/integration/package-manager.test.ts --timeout=900",
16+
"test:apt": "TEST_PLATFORM=kind CREATE_CLUSTER=true PACKAGE_MANAGER=apt tap test/integration/package-manager.test.ts --timeout=900",
17+
"test:rpm": "TEST_PLATFORM=kind CREATE_CLUSTER=true PACKAGE_MANAGER=rpm tap test/integration/package-manager.test.ts --timeout=900",
1818
"start": "bin/start",
1919
"prepare": "npm run build",
2020
"build": "tsc",

src/supervisor/kuberenetes-api-wrappers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import * as sleep from 'sleep-promise';
44
export const ATTEMPTS_MAX = 3;
55
export const DEFAULT_SLEEP_SEC = 1;
66
export const MAX_SLEEP_SEC = 5;
7-
type IKubernetesApiFunction = () => Promise<any>;
8-
9-
export async function retryKubernetesApiRequest(func: IKubernetesApiFunction) {
7+
type IKubernetesApiFunction<ResponseType> = () => Promise<ResponseType>;
108

9+
export async function retryKubernetesApiRequest<ResponseType>(
10+
func: IKubernetesApiFunction<ResponseType>
11+
): Promise<ResponseType> {
1112
for (let attempt = 1; attempt <= ATTEMPTS_MAX; attempt++) {
1213
try {
1314
return await func();
@@ -29,6 +30,8 @@ export async function retryKubernetesApiRequest(func: IKubernetesApiFunction) {
2930
await sleep(sleepSeconds * 1000);
3031
}
3132
}
33+
34+
throw new Error('Could not receive a response from the Kubernetes API');
3235
}
3336

3437
export function calculateSleepSeconds(httpResponse: http.IncomingMessage): number {

src/transmitter/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface IKubernetesMonitorMetadata {
3636
export interface IDepGraphPayload {
3737
imageLocator: IImageLocator;
3838
agentId: string;
39-
dependencyGraph?: any;
39+
dependencyGraph?: string;
4040
metadata: IKubernetesMonitorMetadata;
4141
}
4242

test/helpers/kubernetes-upstream.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {
77
import { WorkloadLocatorValidator, WorkloadMetadataValidator } from './types';
88
import config = require('../../src/common/config');
99

10-
const toneDownFactor = 5;
11-
const maxPodChecks = 600 / toneDownFactor;
10+
const UPSTREAM_POLLING_CONFIGURATION = {
11+
WAIT_BETWEEN_REQUESTS_MS: 5000,
12+
MAXIMUM_REQUESTS: 120,
13+
};
1214

1315
export async function getUpstreamResponseBody(
1416
relativeUrl: string,
@@ -22,16 +24,17 @@ export async function getUpstreamResponseBody(
2224
export async function validateUpstreamStoredData(
2325
validatorFn: WorkloadLocatorValidator,
2426
relativeUrl: string,
25-
remainingChecks: number = maxPodChecks,
27+
remainingChecks: number = UPSTREAM_POLLING_CONFIGURATION.MAXIMUM_REQUESTS,
2628
): Promise<boolean> {
2729
while (remainingChecks > 0) {
30+
console.log(`Pinging upstream for existing data (${remainingChecks} checks remaining)...`);
2831
const responseBody = await getUpstreamResponseBody(relativeUrl);
2932
const workloads: IWorkloadLocator[] | undefined = responseBody.workloads;
3033
const result = validatorFn(workloads);
3134
if (result) {
3235
return true;
3336
}
34-
await sleep(1000 * toneDownFactor);
37+
await sleep(UPSTREAM_POLLING_CONFIGURATION.WAIT_BETWEEN_REQUESTS_MS);
3538
remainingChecks--;
3639
}
3740
return false;
@@ -40,17 +43,18 @@ export async function validateUpstreamStoredData(
4043
export async function validateUpstreamStoredMetadata(
4144
validatorFn: WorkloadMetadataValidator,
4245
relativeUrl: string,
43-
remainingChecks: number = maxPodChecks,
46+
remainingChecks: number = UPSTREAM_POLLING_CONFIGURATION.MAXIMUM_REQUESTS,
4447
): Promise<boolean> {
4548
while (remainingChecks > 0) {
49+
console.log(`Pinging upstream for existing metadata (${remainingChecks} checks remaining)...`);
4650
const responseBody = await getUpstreamResponseBody(relativeUrl);
4751
const workloadInfo: IWorkloadMetadata | undefined =
4852
responseBody.workloadInfo;
4953
const result = validatorFn(workloadInfo);
5054
if (result) {
5155
return true;
5256
}
53-
await sleep(1000 * toneDownFactor);
57+
await sleep(UPSTREAM_POLLING_CONFIGURATION.WAIT_BETWEEN_REQUESTS_MS);
5458
remainingChecks--;
5559
}
5660
return false;

0 commit comments

Comments
 (0)