Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
###############################################################################
{{- $promEnv := (set (set (deepCopy .) "Values" .Values.prometheus) "Chart" (dict "Name" "prometheus")) }}
{{ if .Values.prometheus.server.enabled }}
TimescaleDB can be accessed via port {{ .Values.prometheus.server.service.servicePort }} on the following DNS name from within your cluster:
Prometheus can be accessed via port {{ .Values.prometheus.server.service.servicePort }} on the following DNS name from within your cluster:
{{ template "prometheus.server.fullname" $promEnv }}.{{ .Release.Namespace }}.svc.cluster.local

{{ if .Values.prometheus.server.ingress.enabled -}}
Expand All @@ -41,10 +41,14 @@ Get the Prometheus server URL by running these commands in the same shell:
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "prometheus.server.fullname" $promEnv }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.prometheus.server.service.servicePort }}
{{- else if contains "ClusterIP" .Values.prometheus.server.service.type }}
{{- if .Values.cli }}
ts-obs {{- template "timescale-observability.cliOptions" . }} prometheus port-forward
{{- else }}
export SERVICE_NAME=$(kubectl get services --namespace {{ .Release.Namespace }} -l "app={{ template "prometheus.name" $promEnv }},component={{ .Values.prometheus.server.name }}" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace {{ .Release.Namespace }} port-forward service/$SERVICE_NAME 9090:{{ .Values.prometheus.server.service.servicePort }}
{{- end }}
{{- end }}
{{- end }}

{{- if .Values.prometheus.server.persistentVolume.enabled }}
{{- else }}
Expand Down Expand Up @@ -136,15 +140,23 @@ TimescaleDB can be accessed via port 5432 on the following DNS name from within

To get your password for superuser run:

{{- if .Values.cli }}
ts-obs {{- template "timescale-observability.cliOptions" . }} timescaledb get-password -U <user>
{{- else }}
# superuser password
PGPASSWORD_POSTGRES=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "timescaledb.fullname" $tsEnv }}-passwords -o jsonpath="{.data.postgres}" | base64 --decode)

# admin password
PGPASSWORD_ADMIN=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "timescaledb.fullname" $tsEnv }}-passwords -o jsonpath="{.data.admin}" | base64 --decode)
{{- end }}

To connect to your database, chose one of these options:

1. Run a postgres pod and connect using the psql cli:

{{- if .Values.cli }}
ts-obs {{- template "timescale-observability.cliOptions" . }} timescaledb connect -U <user>
{{- else }}
# login as superuser
kubectl run -i --tty --rm psql --image=postgres \
--env "PGPASSWORD=$PGPASSWORD_POSTGRES" \
Expand All @@ -156,12 +168,17 @@ To connect to your database, chose one of these options:
--env "PGPASSWORD=$PGPASSWORD_ADMIN" \
--command -- psql -U admin \
-h {{ template "clusterName" $tsEnv }}.{{ .Release.Namespace }}.svc.cluster.local postgres
{{- end }}

2. Directly execute a psql session on the master node

{{- if .Values.cli }}
ts-obs {{- template "timescale-observability.cliOptions" . }} timescaledb connect -m
{{- else }}
MASTERPOD="$(kubectl get pod -o name --namespace {{ .Release.Namespace }} -l release={{ .Release.Name }},role=master)"
kubectl exec -i --tty --namespace {{ .Release.Namespace }} ${MASTERPOD} -- psql -U postgres
{{- end }}
{{- end }}

{{ if .Values.grafana.enabled }}
###############################################################################
Expand All @@ -174,13 +191,22 @@ To connect to your database, chose one of these options:
{{ template "grafana.fullname" $grafanaEnv }}.{{ template "grafana.namespace" $grafanaEnv }}.svc.cluster.local

You can access grafana locally by executing:
{{- if .Values.cli }}
ts-obs {{- template "timescale-observability.cliOptions" . }} grafana port-forward
{{- else }}
kubectl --namespace {{ .Release.Namespace }} port-forward service/{{ template "grafana.fullname" $grafanaEnv }} 8080:{{ .Values.grafana.service.port }}
{{- end }}

Then you can point your browser to http://127.0.0.1:8080/.

{{- if not (or .Values.grafana.persistence.enabled .Values.grafana.timescale.database.enabled) }}

2. Get your '{{ .Values.grafana.adminUser }}' user password by running:
kubectl get secret --namespace {{ template "grafana.namespace" $grafanaEnv }} {{ template "grafana.fullname" $grafanaEnv }} -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
{{- if .Values.cli }}
ts-obs {{- template "timescale-observability.cliOptions" . }} grafana get-password
{{- else }}
kubectl get secret --namespace {{ template "grafana.namespace" $grafanaEnv }} {{ template "grafana.fullname" $grafanaEnv }} -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
{{- end }}

WARNING! Persistence is disabled!!! You will lose your data when
the Grafana pod is terminated.
Expand All @@ -189,7 +215,11 @@ WARNING! Persistence is disabled!!! You will lose your data when
{{- if .Release.IsInstall }}

2. The '{{ .Values.grafana.adminUser }}' user password can be retrieved by:
{{- if .Values.cli }}
ts-obs {{- template "timescale-observability.cliOptions" . }} grafana get-password
{{- else }}
kubectl get secret --namespace {{ template "grafana.namespace" $grafanaEnv }} {{ template "grafana.fullname" $grafanaEnv }} -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
{{- end }}
{{- end -}}
{{- if .Release.IsUpgrade }}

Expand All @@ -200,12 +230,16 @@ WARNING! Persistence is disabled!!! You will lose your data when
{{- end }}

3. You can reset the admin user password with grafana-cli from inside the pod.
{{- if .Values.cli }}
ts-obs {{- template "timescale-observability.cliOptions" . }} grafana change-password <password-you-want-to-set>
{{- else }}
First attach yourself to the grafana container:
GRAFANAPOD="$(kubectl get pod -o name --namespace {{ .Release.Namespace }} -l app.kubernetes.io/name=grafana)"
kubectl exec -it ${GRAFANAPOD} -c grafana -- /bin/sh

And then execute in the shell:
grafana-cli admin reset-admin-password <password-you-want-to-set>
{{- end }}
{{- end }}

🚀 Happy observing!
🚀 Happy observing!
10 changes: 10 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ Create the name of the service account to use
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
CLI release name and namespace
*/}}
{{- define "timescale-observability.cliOptions" -}}
{{- if ne .Release.Name "ts-obs" }} -n {{ .Release.Name }}
{{- end -}}
{{- if ne .Release.Namespace "default" }} --namespace {{ .Release.Namespace }}
{{- end -}}
{{- end -}}
1 change: 1 addition & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# https://github.com/timescale/timescaledb-kubernetes/tree/master/charts/timescaledb-single
# Check out the various configuration options (administration guide) at:
# https://github.com/timescale/timescaledb-kubernetes/blob/master/charts/timescaledb-single/admin-guide.md
cli: false
timescaledb-single:
# disable the chart if an existing TimescaleDB instance is used
enabled: true
Expand Down
117 changes: 117 additions & 0 deletions install-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/sh

set -eu

INSTALLROOT=${INSTALLROOT:-"${HOME}/.ts-obs"}
TS_OBS_VERSION=${TS_OBS_VERSION:-0.1.0-alpha.4.1}

happyexit() {
echo ""
echo "Add the ts-obs CLI to your path with:"
echo ""
echo " export PATH=\$PATH:${INSTALLROOT}/bin"
echo ""
echo "After starting your cluster, run"
echo ""
echo " ts-obs install"
echo ""
exit 0
}

validate_checksum() {
filename=$1
SHA=$(curl -sfL "${url}.sha256")
echo ""
echo "Validating checksum..."

case $checksumbin in
*openssl)
checksum=$($checksumbin dgst -sha256 "${filename}" | sed -e 's/^.* //')
;;
*shasum)
checksum=$($checksumbin -a256 "${filename}" | sed -e 's/^.* //')
;;
esac

if [ "$checksum" != "$SHA" ]; then
echo "Checksum validation failed." >&2
return 1
fi
echo "Checksum valid."
return 0
}

OS=$(uname -s)
arch=$(uname -m)
case $OS in
CYGWIN* | MINGW64*)
OS=windows.exe
;;
Darwin)
;;
Linux)
case $arch in
x86_64)
;;
*)
echo "Timescale Observability does not support $OS/$arch. Please open an issue with your platform details."
exit 1
;;
esac
;;
*)
echo "Timescale Observability does not support $OS/$arch. Please open an issue with your platform details."
exit 1
;;
esac
OS=$(echo $OS | tr '[:upper:]' '[:lower:]')

checksumbin=$(command -v openssl) || checksumbin=$(command -v shasum) || {
echo "Failed to find checksum binary. Please install openssl or shasum."
exit 1
}

tmpdir=$(mktemp -d /tmp/ts-obs.XXXXXX)
srcfile="ts-obs-${TS_OBS_VERSION}-${OS}"
dstfile="${INSTALLROOT}/bin/ts-obs-${TS_OBS_VERSION}"
url="https://github.com/timescale/timescale-observability/releases/download/${TS_OBS_VERSION}/${srcfile}"

if [ -e "${dstfile}" ]; then
if validate_checksum "${dstfile}"; then
echo ""
echo "ts-obs ${TS_OBS_VERSION} was already downloaded; making it the default"
echo ""
echo "To force re-downloading, delete '${dstfile}' then run me again."
(
rm -f "${INSTALLROOT}/bin/ts-obs"
ln -s "${dstfile}" "${INSTALLROOT}/bin/ts-obs"
)
happyexit
fi
fi

(
cd "$tmpdir"

echo "Downloading ${srcfile}..."
curl -fLO "${url}"
echo "Download complete!"

if ! validate_checksum "${srcfile}"; then
exit 1
fi
echo ""
)

(
mkdir -p "${INSTALLROOT}/bin"
mv "${tmpdir}/${srcfile}" "${dstfile}"
chmod +x "${dstfile}"
rm -f "${INSTALLROOT}/bin/ts-obs"
ln -s "${dstfile}" "${INSTALLROOT}/bin/ts-obs"
)

rm -r "$tmpdir"
echo "ts-obs ${TS_OBS_VERSION} was successfully installed 🎉"
echo ""
happyexit
26 changes: 26 additions & 0 deletions ts-obs/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod download
builds:
- env:
- CGO_ENABLED=0
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
12 changes: 8 additions & 4 deletions ts-obs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is a CLI tool for installing and managing the Timescale Observability Helm
## Quick Start

__Dependencies__: [Go](https://golang.org/doc/install), [Helm](https://helm.sh/docs/intro/install/)

To install the CLI, run `go install` from inside the `ts-obs` folder.
Then, copy the `ts-obs` binary from `$GOPATH/bin` to your `/bin` folder.

Expand All @@ -26,16 +27,17 @@ The following are the commands possible with the CLI.
|---------------------------|---------------------------------------------------------------------------|------------------------------------------------------|
| `ts-obs helm install` | Installs the Timescale Observability Helm chart. | `--filename`, `-f` : file to load configuration from |
| `ts-obs helm uninstall` | Uninstalls the Timescale Observability Helm chart. | None |
| `ts-obs helm get-yaml` | Writes the YAML configuration of the Timescale Observability Helm chart. | None |
| `ts-obs helm show-values` | Prints the YAML configuration of the Timescale Observability Helm chart. | None |
| `ts-obs helm delete-data` | Deletes persistent volume claims associated with Timescale Observability. | None |

### TimescaleDB Commands

| Command | Description | Flags |
|-----------------------------------|------------------------------------------------------------|---------------------------------------------|
| `ts-obs timescaledb connect` | Connects to the Timescale database running in the cluster. | `--user`, `-U` : user to login with <br> `--master`, `-m` : directly execute session on master node |
| `ts-obs timescaledb port-forward` | Port-forwards TimescaleDB to localhost. | `--port`, `-p` : port to listen from |
| `ts-obs timescaledb get-password` | Gets the password for a user in the Timescale database. | `--user`, `-U` : user whose password to get |
| `ts-obs timescaledb connect` | Connects to the Timescale database running in the cluster. | `--user`, `-U` : user to login with <br> `--master`, `-m` : directly execute session on master node |
| `ts-obs timescaledb port-forward` | Port-forwards TimescaleDB to localhost. | `--port`, `-p` : port to listen from |
| `ts-obs timescaledb get-password` | Gets the password for a user in the Timescale database. | `--user`, `-U` : user whose password to get |
| `ts-obs timescaledb change-password` | Changes the password for a user in the Timescale database. | `--user`, `-U` : user whose password to get |

### Grafana Commands

Expand Down Expand Up @@ -66,6 +68,8 @@ The following are the commands possible with the CLI.

## Global Flags

The following are global flags that can be used with any of the above commands:

| Flag | Description |
|----------------|----------------------|
| `--name`, `-n` | Helm release name |
Expand Down
14 changes: 0 additions & 14 deletions ts-obs/cmd/chunkIntervalGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,13 @@ var chunkIntervalGetCmd = &cobra.Command{

func init() {
chunkIntervalCmd.AddCommand(chunkIntervalGetCmd)
chunkIntervalGetCmd.Flags().StringP("user", "U", "postgres", "database user name")
chunkIntervalGetCmd.Flags().StringP("dbname", "d", "postgres", "database name to connect to")
}

func chunkIntervalGet(cmd *cobra.Command, args []string) error {
var err error

metric := args[0]

var user string
user, err = cmd.Flags().GetString("user")
if err != nil {
return fmt.Errorf("could not get chunk interval for %v: %w", metric, err)
}

var dbname string
dbname, err = cmd.Flags().GetString("dbname")
if err != nil {
return fmt.Errorf("could not get chunk interval for %v: %w", metric, err)
}

pool, err := OpenConnectionToDB(namespace, name, user, dbname, FORWARD_PORT_TSDB)
if err != nil {
return fmt.Errorf("could not get chunk interval for %v: %w", metric, err)
Expand Down
14 changes: 0 additions & 14 deletions ts-obs/cmd/chunkIntervalReset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,13 @@ var chunkIntervalResetCmd = &cobra.Command{

func init() {
chunkIntervalCmd.AddCommand(chunkIntervalResetCmd)
chunkIntervalResetCmd.Flags().StringP("user", "U", "postgres", "database user name")
chunkIntervalResetCmd.Flags().StringP("dbname", "d", "postgres", "database name to connect to")
}

func chunkIntervalReset(cmd *cobra.Command, args []string) error {
var err error

metric := args[0]

var user string
user, err = cmd.Flags().GetString("user")
if err != nil {
return fmt.Errorf("could not reset chunk interval for %v: %w", metric, err)
}

var dbname string
dbname, err = cmd.Flags().GetString("dbname")
if err != nil {
return fmt.Errorf("could not reset chunk interval for %v: %w", metric, err)
}

pool, err := OpenConnectionToDB(namespace, name, user, dbname, FORWARD_PORT_TSDB)
if err != nil {
return fmt.Errorf("could not reset chunk interval for %v: %w", metric, err)
Expand Down
Loading