Skip to content

Commit

Permalink
Service: Support configuring host and port thru config and environmen…
Browse files Browse the repository at this point in the history
…t variables (grafana#40)

Support configuring service host and port thru config and 
environment variables.

Co-authored-by: Marcus Efraimsson <[email protected]>
  • Loading branch information
kaey and marefr committed Jan 19, 2020
1 parent d60c0b6 commit c284d18
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"service": {
"host": null,
"port": 8081,
"metrics": {
"enabled": false,
Expand Down
1 change: 1 addition & 0 deletions dev.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"service": {
"host": "localhost",
"port": 8081,
"metrics": {
"enabled": true,
Expand Down
16 changes: 16 additions & 0 deletions docs/remote_rendering_using_docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ The docker image are published at [Docker Hub](https://hub.docker.com/r/grafana/

You can override certain settings by using environment variables.

**HTTP host:**

Change the listening host of the HTTP server. Default is unset and will use the local host.

```bash
export HTTP_HOST=localhost
```

**HTTP port:**

Change the listening port of the HTTP server. Default is `8081`. Setting `0` will automatically assign a port not in use.

```bash
export HTTP_PORT=0
```

**Default timezone:**

Instruct headless Chrome to use a default timezone when not provided by Grafana, .e.g. when rendering panel image of alert. See [ICU’s metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs.
Expand Down
8 changes: 8 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ function populateServiceConfigFromEnv(config: ServiceConfig, env: NodeJS.Process
config.rendering.timezone = env['TZ'];
}

if (env['HTTP_HOST']) {
config.service.host = env['HTTP_HOST'];
}

if (env['HTTP_PORT']) {
config.service.port = parseInt(env['HTTP_PORT'] as string, 10);
}

if (env['IGNORE_HTTPS_ERRORS']) {
config.rendering.ignoresHttpsErrors = env['IGNORE_HTTPS_ERRORS'] === 'true';
}
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface MetricsConfig {

export interface ServiceConfig {
service: {
host?: string;
port: number;
metrics: MetricsConfig;
};
Expand Down Expand Up @@ -52,6 +53,7 @@ const defaultRenderingConfig: RenderingConfig = {

export const defaultServiceConfig: ServiceConfig = {
service: {
host: undefined,
port: 8081,
metrics: {
enabled: false,
Expand Down
15 changes: 13 additions & 2 deletions src/service/http-server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as http from 'http';
import * as net from 'net';
import express = require('express');
import { Logger } from '../logger';
import { Browser } from '../browser';
Expand Down Expand Up @@ -35,8 +37,17 @@ export class HttpServer {
this.log.info(`Ignoring HTTPS errors`);
}

this.app.listen(this.config.service.port);
this.log.info(`HTTP Server started, listening on ${this.config.service.port}`);
if (this.config.service.host) {
const server = this.app.listen(this.config.service.port, this.config.service.host, () => {
const info = server.address() as net.AddressInfo;
this.log.info(`HTTP Server started, listening at http://${this.config.service.host}:${info.port}`);
});
} else {
const server = this.app.listen(this.config.service.port, () => {
const info = server.address() as net.AddressInfo;
this.log.info(`HTTP Server started, listening at http://localhost:${info.port}`);
});
}

const browserInfo = new promClient.Gauge({
name: 'grafana_image_renderer_browser_info',
Expand Down

0 comments on commit c284d18

Please sign in to comment.