Skip to content

Commit

Permalink
Merge pull request #1288 from balena-io/add-optional-logs-host-var
Browse files Browse the repository at this point in the history
Add optional LOGS_HOST env var for log-stream subdomain
  • Loading branch information
flowzone-app[bot] authored May 8, 2023
2 parents bb6bdd7 + 94fc7a0 commit c412ed1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/confd/conf.d/env.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ keys = [
"MIXPANEL_TOKEN",
"PRODUCTION_MODE",
"REDIS_HOST",
"LOGS_HOST",
"LOKI_HOST",
"LOKI_PORT",
"LOKI_WRITE_PCT",
Expand Down
1 change: 1 addition & 0 deletions config/confd/templates/env.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ IMAGE_STORAGE_PREFIX={{if getenv "IMAGE_STORAGE_PREFIX"}}{{getenv "IMAGE_STORAGE
IMAGE_STORAGE_SECRET_KEY={{getenv "IMAGE_STORAGE_SECRET_KEY"}}
JSON_WEB_TOKEN_EXPIRY_MINUTES={{getenv "JSON_WEB_TOKEN_EXPIRY_MINUTES"}}
JSON_WEB_TOKEN_SECRET='{{getenv "JSON_WEB_TOKEN_SECRET"}}'
{{if getenv "LOGS_HOST"}}LOGS_HOST={{getenv "LOGS_HOST"}}{{end}}
MAX_CONNECTIONS=75
MIXPANEL_TOKEN={{getenv "MIXPANEL_TOKEN"}}
NODE_ENV={{if eq (getenv "PRODUCTION_MODE") "true"}}production{{else}}development{{end}}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.test-custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
IMAGE_STORAGE_SECRET_KEY: SECRET_KEY
JSON_WEB_TOKEN_EXPIRY_MINUTES: 10080
JSON_WEB_TOKEN_SECRET: purple
LOGS_HOST: logs.balenadev.io
METRICS_MAX_REPORT_INTERVAL_SECONDS: 3
MIXPANEL_TOKEN: mixpanel_token
NUM_WORKERS: 1
Expand Down
3 changes: 3 additions & 0 deletions src/features/device-config/device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
REGISTRY2_HOST,
VPN_HOST,
VPN_PORT,
LOGS_HOST,
} from '../../lib/config';

// `osVersion == null` means assume "latest"
Expand Down Expand Up @@ -120,6 +121,8 @@ export const generateConfig = async (
delta: `https://${DELTA_HOST}`,
registry: REGISTRY2_HOST,
vpn: VPN_HOST,
// If undefined, balena-device-config won't generate a logs endpoint
logs: LOGS_HOST != null ? `https://${LOGS_HOST}` : undefined,
},
version: osVersion,
},
Expand Down
1 change: 1 addition & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const JSON_WEB_TOKEN_EXPIRY_MINUTES = intVar(
'JSON_WEB_TOKEN_EXPIRY_MINUTES',
);
export const JSON_WEB_TOKEN_SECRET = requiredVar('JSON_WEB_TOKEN_SECRET');
export const LOGS_HOST = optionalVar('LOGS_HOST');
export const MIXPANEL_TOKEN = requiredVar('MIXPANEL_TOKEN');
export const NODE_ENV = optionalVar('NODE_ENV');
export const NODE_EXTRA_CA_CERTS = optionalVar('NODE_EXTRA_CA_CERTS');
Expand Down
15 changes: 15 additions & 0 deletions test/05_device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,20 @@ describe('generate device config', function () {
`Provisioning Key for app ${this.application.id}`,
);
});

it('should contain logsEndpoint in response config', async function () {
const { body } = await supertest(this.user)
.post('/download-config')
.send({
appId: this.application.id,
version: 'v2.24.0',
deviceType: 'raspberrypi3',
})
.expect(200)
.expect('content-type', /^application\/json/);

expect(body).to.have.a.property('logsEndpoint');
expect(body.logsEndpoint).to.match(/^https\:\/\//);
});
});
});
1 change: 1 addition & 0 deletions typings/balena-device-config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare module 'balena-device-config' {
delta: string;
registry: string;
vpn?: string;
logs?: string;
};

mixpanel?: {
Expand Down

0 comments on commit c412ed1

Please sign in to comment.