Skip to content

Commit 872e8cb

Browse files
committed
feat: allow keep-alive to be configured
1 parent b890321 commit 872e8cb

File tree

10 files changed

+35
-6
lines changed

10 files changed

+35
-6
lines changed

config.default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"QUEUE_LENGTH_LOG_FREQUENCY_MINUTES": 1,
1717
"INTEGRATION_ID": "",
1818
"DEFAULT_KUBERNETES_UPSTREAM_URL": "https://kubernetes-upstream.snyk.io",
19-
"MAX_RETRY_BACKOFF_DURATION_SECONDS": 300
19+
"MAX_RETRY_BACKOFF_DURATION_SECONDS": 300,
20+
"USE_KEEPALIVE": true
2021
}

snyk-monitor/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ spec:
127127
value: {{ .Values.https_proxy }}
128128
- name: NO_PROXY
129129
value: {{ .Values.no_proxy }}
130+
- name: USE_KEEPALIVE
131+
value: {{ quote .Values.use_keepalive }}
130132
- name: LOG_LEVEL
131133
value: {{ .Values.log_level }}
132134
- name: SKIP_K8S_JOBS

snyk-monitor/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ limits:
9191
http_proxy:
9292
https_proxy:
9393
no_proxy:
94+
use_keepalive: true
9495
skip_k8s_jobs:
9596

9697
# Override default (INFO) log level if less verbosity needed

snyk-operator-certified/helm-charts/snyk-monitor/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ spec:
111111
value: {{ .Values.https_proxy }}
112112
- name: NO_PROXY
113113
value: {{ .Values.no_proxy }}
114+
- name: USE_KEEPALIVE
115+
value: {{ quote .Values.use_keepalive }}
114116
- name: LOG_LEVEL
115117
value: {{ .Values.log_level }}
116118
- name: SKIP_K8S_JOBS

snyk-operator-certified/helm-charts/snyk-monitor/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ limits:
8383
http_proxy:
8484
https_proxy:
8585
no_proxy:
86+
use_keepalive: true
8687
skip_k8s_jobs:
8788

8889
# Override default (INFO) log level if less verbosity needed

src/common/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ if (config.SYSDIG_ENDPOINT && config.SYSDIG_TOKEN) {
5959
config.HTTPS_PROXY = process.env['HTTPS_PROXY'];
6060
config.HTTP_PROXY = process.env['HTTP_PROXY'];
6161
config.NO_PROXY = process.env['NO_PROXY'];
62+
config.USE_KEEPALIVE = process.env.USE_KEEPALIVE === 'true';
6263
delete process.env['HTTPS_PROXY'];
6364
delete process.env['HTTP_PROXY'];
6465
delete process.env['NO_PROXY'];

src/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface Config {
3131
HTTPS_PROXY: string | undefined;
3232
HTTP_PROXY: string | undefined;
3333
NO_PROXY: string | undefined;
34+
USE_KEEPALIVE: boolean;
3435
SKIP_K8S_JOBS: boolean;
3536
DEPLOYMENT_NAME: string;
3637
DEPLOYMENT_NAMESPACE: string;

src/transmitter/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ const upstreamUrl =
3636
config.INTEGRATION_API || config.DEFAULT_KUBERNETES_UPSTREAM_URL;
3737

3838
let httpAgent = new HttpAgent({
39-
keepAlive: true,
39+
keepAlive: config.USE_KEEPALIVE,
4040
});
4141

4242
let httpsAgent = new HttpsAgent({
43-
keepAlive: true,
43+
keepAlive: config.USE_KEEPALIVE,
4444
});
4545

4646
function getAgent(u: string): HttpAgent {
@@ -209,9 +209,10 @@ export async function deleteWorkload(
209209
const { response, attempt } = await reqQueue.pushAsync(request);
210210
if (response.statusCode === 404) {
211211
// TODO: maybe we're still building it?
212-
const msg =
213-
'attempted to delete a workload the Upstream service could not find';
214-
logger.info({ payload }, msg);
212+
logger.info(
213+
{ payload },
214+
'attempted to delete a workload the Upstream service could not find',
215+
);
215216
return;
216217
}
217218
if (!isSuccessStatusCode(response.statusCode)) {

test/common/config.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('extractNamespaceName()', () => {
7474
expect(config.HTTPS_PROXY).toBeUndefined();
7575
expect(config.HTTP_PROXY).toBeUndefined();
7676
expect(config.NO_PROXY).toBeUndefined();
77+
expect(config.USE_KEEPALIVE).toEqual(true);
7778
expect(config.SKIP_K8S_JOBS).toEqual(false);
7879
expect(config.WORKERS_COUNT).toEqual(10);
7980
expect(config.SKOPEO_COMPRESSION_LEVEL).toEqual(6);

test/integration/kubernetes.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,24 @@ test('snyk-monitor has log level', async () => {
633633
expect(logLevel.value).toBeTruthy();
634634
});
635635

636+
test('snyk-monitor has keep-alive', async () => {
637+
if (!['Helm'].includes(process.env.DEPLOYMENT_TYPE || '')) {
638+
console.log(
639+
"Not testing USE_KEEPALIVE existence because we're not installing with Helm",
640+
);
641+
return;
642+
}
643+
644+
const snykMonitorDeployment = await kubectl.getDeploymentJson(
645+
'snyk-monitor',
646+
namespace,
647+
);
648+
const env = snykMonitorDeployment.spec.template.spec.containers[0].env;
649+
const useKeepAlive = env.find(({ name }) => name === 'USE_KEEPALIVE');
650+
expect(useKeepAlive.name).toBeTruthy();
651+
expect(useKeepAlive.value).toBe('true');
652+
});
653+
636654
test('service account has annotations that were set on deployment', async () => {
637655
if (process.env.DEPLOYMENT_TYPE !== 'Helm') {
638656
console.log(

0 commit comments

Comments
 (0)