Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Update the flag names and default value of the dbname flag (#32)
Browse files Browse the repository at this point in the history
Also the deployment in the helm-chart is simplified to use
the TS_PROM environment variables to set the connection
flags.
  • Loading branch information
atanasovskib committed Apr 20, 2020
1 parent 3db8552 commit a4df54c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ The Timescale-Prometheus Connector is a Go project managed by go modules. You ca
any directory and on the first build it will download it's required dependencies.

```bash
# Fetch the source code of Outflux in any directory
# Fetch the source code of Timescale-Prometheus in any directory
$ git clone git@github.com:timescale/timescale-prometheus.git
$ cd ./timescale-prometheus

Expand Down
26 changes: 18 additions & 8 deletions helm-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ on Kubernetes. This chart will do the following:

## Prerequisites

The chart expects that the password used to connect to TimescaleDB is
created before the chart is deployed.
You can set the secret name by modifying the `password.secretTemplate` value.
### Database Name

The name of the database the Timescale-Prometheus connector will connect to by default
is set to `timescale`. You can change it by modifying the `connection.dbName` value.
The database **must be created before** starting the connector.

### Password

The chart expects that the password used to connect to TimescaleDB is stored in a
Kubernetes Secret created before the chart is deployed.
You can set the secret name by modifying the `connection.password.secretTemplate` value.
Templating is supported and you can use:
```yaml
password:
secretTemplate: "{{ .Release.Name }}-timescaledb-passwords"
connection:
password:
secretTemplate: "{{ .Release.Name }}-timescaledb-passwords"
```

## Installing
Expand Down Expand Up @@ -49,9 +58,10 @@ helm install --name my-release -f myvalues.yaml .
| `image` | The image (with tag) to pull | `timescale/timescale-prometheus` |
| `replicaCount` | Number of pods for the connector | `1` |
| `connection.user` | Username to connect to TimescaleDB with | `postgres` |
| `password.secretTemplate` | The template for generating the name of a secret object which will hold the db password | `{{ .Release.Name }}-timescaledb-passwords` |
| `host.nameTemplate` | The template for generating the hostname of the db | `{{ .Release.Name }}.{{ .Release.Namespace}}.svc.cluster.local` |
| `port` | Port the db listens to | `5432` |
| `connection.password.secretTemplate` | The template for generating the name of a secret object which will hold the db password | `{{ .Release.Name }}-timescaledb-passwords` |
| `connection.host.nameTemplate` | The template for generating the hostname of the db | `{{ .Release.Name }}.{{ .Release.Namespace}}.svc.cluster.local` |
| `connection.port` | Port the db listens to | `5432` |
| `connection.dbName` | Database name in TimescaleDB to connect to | `timescale` |
| `service.port` | Port the connector pods will accept connections on | `9201` |
| `service.loadBalancer.enabled` | If enabled will create an LB for the connector, ClusterIP otherwise | `true` |
| `service.loadBalancer.annotations`| Annotations to set to the LB service | `service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "4000"` |
Expand Down
4 changes: 3 additions & 1 deletion helm-chart/templates/cronjob-dropchunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
spec:
containers:
- name: {{ .Chart.Name }}-drop-chunk
image: postgres:11-alpine
image: postgres:12-alpine
args:
- psql
- -c
Expand All @@ -32,4 +32,6 @@ spec:
key: {{ .Values.connection.user }}
- name: PGHOST
value: {{ tpl .Values.connection.host.nameTemplate . }}
- name: PGDATABASE
value: {{ .Values.connection.dbName }}
restartPolicy: OnFailure
22 changes: 9 additions & 13 deletions helm-chart/templates/deployment-connector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,21 @@ spec:
- containerPort: 9201
name: connector-port
env:
- name: PGPORT
- name: TS_PROM_DB_PORT
value: {{ .Values.connection.port | quote }}
- name: PGUSER
- name: TS_PROM_DB_USER
value: {{ .Values.connection.user }}
- name: PGPASSWORD
- name: TS_PROM_DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ tpl .Values.connection.password.secretTemplate . }}
key: {{ .Values.connection.user }}
- name: PGHOST
value: {{ tpl .Values.connection.host.nameTemplate . }}
args:
[
-pg-ssl-mode=require,
-pg-host=$(PGHOST),
-pg-user=$(PGUSER),
-pg-password=$(PGPASSWORD),
-pg-port=$(PGPORT)
]
- name: TS_PROM_DB_HOST
value: {{ tpl .Values.connection.host.nameTemplate . }}
- name: TS_PROM_DB_NAME
value: {{ .Values.connection.dbName }}
- name: TS_PROM_DB_SSL_MODE
value: require
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 2 }}
Expand Down
4 changes: 4 additions & 0 deletions helm-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ connection:
# nameTemplate: {{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local
nameTemplate: "{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local"
port: 5432
# database name in which to store the metrics
# must be created before start
dbName: timescale


# settings for the service to be created that will expose
# the timescale-prometheus deployment
Expand Down
16 changes: 8 additions & 8 deletions pkg/pgclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ type Config struct {

// ParseFlags parses the configuration flags specific to PostgreSQL and TimescaleDB
func ParseFlags(cfg *Config) *Config {
flag.StringVar(&cfg.host, "pg-host", "localhost", "The PostgreSQL host")
flag.IntVar(&cfg.port, "pg-port", 5432, "The PostgreSQL port")
flag.StringVar(&cfg.user, "pg-user", "postgres", "The PostgreSQL user")
flag.StringVar(&cfg.password, "pg-password", "", "The PostgreSQL password")
flag.StringVar(&cfg.database, "pg-database", "postgres", "The PostgreSQL database")
flag.StringVar(&cfg.sslMode, "pg-ssl-mode", "disable", "The PostgreSQL connection ssl mode")
flag.IntVar(&cfg.dbConnectRetries, "pg-db-connect-retries", 0, "How many times to retry connecting to the database")
flag.StringVar(&cfg.host, "db-host", "localhost", "The TimescaleDB host")
flag.IntVar(&cfg.port, "db-port", 5432, "The TimescaleDB port")
flag.StringVar(&cfg.user, "db-user", "postgres", "The TimescaleDB user")
flag.StringVar(&cfg.password, "db-password", "", "The TimescaleDB password")
flag.StringVar(&cfg.database, "db-name", "timescale", "The TimescaleDB database")
flag.StringVar(&cfg.sslMode, "db-ssl-mode", "disable", "The TimescaleDB connection ssl mode")
flag.IntVar(&cfg.dbConnectRetries, "db-connect-retries", 0, "How many times to retry connecting to the database")
return cfg
}

// Client sends Prometheus samples to PostgreSQL
// Client sends Prometheus samples to TimescaleDB
type Client struct {
Connection *pgxpool.Pool
ingestor *pgmodel.DBIngestor
Expand Down

0 comments on commit a4df54c

Please sign in to comment.