Skip to content

Commit

Permalink
feat(global): support for external and internal api addresses (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
enudler authored Feb 17, 2019
1 parent 850ea89 commit c85fa83
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion deployment/helm/predator/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "predator.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:80 to use your application"
kubectl port-forward $POD_NAME 80:80
kubectl port-forward $POD_NAME 8080:80 --namespace {{ .Release.Namespace }}
{{- end }}
10 changes: 7 additions & 3 deletions deployment/helm/predator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "predator.fullname" . }}
namespace: {{ .Values.namespace }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: {{ include "predator.name" . }}
helm.sh/chart: {{ include "predator.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: 1
namespace: {{ .Values.namespace }}
namespace: {{ .Release.Namespace }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "predator.name" . }}
Expand Down Expand Up @@ -48,13 +48,17 @@ spec:
- name: KUBERNETES_URL
value: {{ .Values.KUBERNETES_URL }}
- name: KUBERNETES_NAMESPACE
value: {{ .Values.namespace }}
value: {{ .Release.Namespace }}
- name: GRAFANA_URL
value: {{ .Values.GRAFANA_URL }}
- name: METRICS_PLUGIN_NAME
value: {{ .Values.METRICS_PLUGIN_NAME }}
- name: METRICS_EXPORT_CONFIG
value: {{ .Values.METRICS_EXPORT_CONFIG }}
- name: INTERNAL_ADDRESS
value: http://{{ include "predator.fullname" . }}.{{ .Release.Namespace }}:{{ .Values.service.port }}
- name: EXTERNAL_ADDRESS
value: {{ .Values.EXTERNAL_ADDRESS }}
ports:
- name: http
containerPort: 80
Expand Down
5 changes: 3 additions & 2 deletions deployment/helm/predator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ tolerations: []

affinity: {}

namespace: predator

JOB_PLATFORM: KUBERNETES
KUBERNETES_URL: https://kubernetes.default.svc
KUBERNETES_TOKEN:
Expand All @@ -62,6 +60,9 @@ DATABASE_USERNAME:
MY_ADDRESS:
DOCKER_NAME: zooz/predator-runner:latest

INTERNAL_ADDRESS:
EXTERNAL_ADDRESS:

METRICS_PLUGIN_NAME:
METRICS_EXPORT_CONFIG:
GRAFANA_URL:
3 changes: 2 additions & 1 deletion src/config/serviceConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let config = {
grafanaUrl: process.env.GRAFANA_URL,
myAddress: process.env.MY_ADDRESS,
externalAddress: process.env.EXTERNAL_ADDRESS || process.env.INTERNAL_ADDRESS,
internalAddress: process.env.INTERNAL_ADDRESS,
concurrencyLimit: process.env.CONCURRENCY_LIMIT || 500,
dockerName: process.env.DOCKER_NAME || 'zooz/predator-runner:latest',
jobPlatform: process.env.JOB_PLATFORM,
Expand Down
3 changes: 2 additions & 1 deletion src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ env.init = function () {
}

let mandatoryVars = [
'JOB_PLATFORM'
'JOB_PLATFORM',
'INTERNAL_ADDRESS'
];

mandatoryVars = mandatoryVars.concat(BY_PLATFORM_MANDATORY_VARS[process.env.JOB_PLATFORM]);
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/models/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function createJobRequest(jobId, runId, jobBody, dockerImage) {
RUN_ID: runId.toString(),
ENVIRONMENT: jobBody.environment,
TEST_ID: jobBody.test_id,
PREDATOR_URL: config.myAddress,
PREDATOR_URL: config.internalAddress,
ARRIVAL_RATE: arrivalRatePerRunner.toString(),
DURATION: jobBody.duration.toString()
};
Expand Down
2 changes: 1 addition & 1 deletion src/reports/models/reportsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getReportResponse(summaryRow) {
let testConfiguration = summaryRow.test_configuration ? JSON.parse(summaryRow.test_configuration) : {};
let lastStats = summaryRow.last_stats ? JSON.parse(summaryRow.last_stats) : {};

let htmlReportUrl = serviceConfig.myAddress + `/v1/tests/${summaryRow.test_id}/reports/${summaryRow.report_id}/html`;
let htmlReportUrl = serviceConfig.externalAddress + `/v1/tests/${summaryRow.test_id}/reports/${summaryRow.report_id}/html`;
let grafanaReportUrl = encodeURI(serviceConfig.grafanaUrl + `?var-Name=${summaryRow.test_name}&from=${new Date(summaryRow.start_time).getTime()}`);

if (summaryRow.end_time) {
Expand Down
4 changes: 2 additions & 2 deletions src/reports/models/statsConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function handleDone(report, job, stats, statsTime, statsData, grafanaRepor
await databaseConnector.insertStats(report.test_id, report.report_id, uuidv4(), statsTime, report.phase, 'aggregate', stats.data);
await databaseConnector.updateReport(report.test_id, report.report_id, 'finished', report.phase, stats.data, statsTime);

const htmlReportUrl = serviceConfig.myAddress + `/v1/tests/${report.test_id}/reports/${report.report_id}/html`;
const htmlReportUrl = serviceConfig.externalAddress + `/v1/tests/${report.test_id}/reports/${report.report_id}/html`;
let webhookMessage = `😎 *Test ${report.test_name} with id: ${report.test_id} is finished.*\n${statsFromatter.getStatsFormatted('aggregate', statsData)}\n<${htmlReportUrl}|View final html report>\n`;

if (grafanaReportUrl) {
Expand All @@ -114,7 +114,7 @@ async function handleAbort(report, job, stats, statsTime, grafanaReportUrl) {
await databaseConnector.updateReport(report.test_id, report.report_id, 'aborted', report.phase, undefined, statsTime);

if (job.webhooks) {
const htmlReportUrl = serviceConfig.myAddress + `/v1/tests/${report.test_id}/reports/${report.report_id}/html`;
const htmlReportUrl = serviceConfig.externalAddress + `/v1/tests/${report.test_id}/reports/${report.report_id}/html`;
let webhookMessage = `😢 *Test ${report.test_name} with id: ${report.test_id} was aborted.*\n<${htmlReportUrl}|View final html report>\n`;
if (grafanaReportUrl) {
webhookMessage += `<${grafanaReportUrl}|View final grafana dashboard report>`;
Expand Down
3 changes: 2 additions & 1 deletion tests/configurations/commonConfiguration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export SMTP_HOST=$RUNNER_IP
export SMTP_PORT=1025
export SMTP_PASSWORD=password
export SMTP_USERNAME=username
export DOCKER_NAME='zooz/predator-runner:latest'
export DOCKER_NAME='zooz/predator-runner:latest'
export INTERNAL_ADDRESS='http://localhost:80'
10 changes: 5 additions & 5 deletions tests/integration-tests/runLocal.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

LOCAL_TEST=true DATABASE_TYPE=cassandra PLATFORM_TYPE=kubernetes ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=mysql PLATFORM_TYPE=kubernetes ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=sqlite PLATFORM_TYPE=kubernetes ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=postgres PLATFORM_TYPE=metronome ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=sqlite PLATFORM_TYPE=docker ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=cassandra JOB_PLATFORM=kubernetes ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=mysql JOB_PLATFORM=kubernetes ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=sqlite JOB_PLATFORM=kubernetes ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=postgres JOB_PLATFORM=metronome ./tests/integration-tests/run.sh
LOCAL_TEST=true DATABASE_TYPE=sqlite JOB_PLATFORM=docker ./tests/integration-tests/run.sh
2 changes: 1 addition & 1 deletion tests/unit-tests/jobs/models/jobManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('Manager tests', function () {
describe('Create new job', function () {
before(() => {
manager.__set__('config.baseUrl', '');
manager.__set__('config.myAddress', 'localhost:80');
manager.__set__('config.internalAddress', 'localhost:80');
manager.__set__('config.environment', '');
manager.__set__('config.concurrencyLimit', '100');
uuidStub.returns('5a9eee73-cf56-47aa-ac77-fad59e961aaf');
Expand Down

0 comments on commit c85fa83

Please sign in to comment.