Skip to content

Commit cdb351f

Browse files
committed
Merge branch 'main' into dean/skip-tests-fe-be
2 parents 62fbfd1 + 71c9089 commit cdb351f

File tree

7 files changed

+103
-24
lines changed

7 files changed

+103
-24
lines changed

.github/actions/setup-go/action.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,32 @@ runs:
88
with:
99
cache: true
1010
go-version: "1.20.5"
11+
12+
- name: Cache go
13+
uses: buildjet/cache@v3
14+
with:
15+
# ~/go/pkg is the same across operating systems.
16+
path: |
17+
~/go/pkg
18+
~/.cache/go-build
19+
~/AppData/Local/go-build
20+
~/Library/Caches/go-build
21+
# Job name must be included in the key for effective
22+
# test cache reuse.
23+
key: go-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }}
24+
restore-keys: |
25+
go-${{ runner.os }}-${{ github.job }}-
26+
go-${{ runner.os }}-
27+
go-
28+
1129
- name: Install gotestsum
1230
uses: jaxxstorm/action-install-gh-release@v1.10.0
1331
with:
1432
repo: gotestyourself/gotestsum
1533
tag: v1.9.0
34+
35+
# It isn't necessary that we ever do this, but it helps
36+
# separate the "setup" from the "run" times.
37+
- name: go mod download
38+
shell: bash
39+
run: go mod download -x

.github/workflows/ci.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,18 @@ jobs:
247247
echo "cover=false" >> $GITHUB_OUTPUT
248248
fi
249249
250+
# By default Go will use the number of logical CPUs, which
251+
# is a fine default.
252+
PARALLEL_FLAG=""
253+
if [ "${{ matrix.os }}" == "windows-2019" ]; then
254+
# Windows appears more I/O bound, so we increase parallelism
255+
# to make better use of CPU.
256+
PARALLEL_FLAG="-parallel=16"
257+
fi
258+
250259
export TS_DEBUG_DISCO=true
251-
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" --packages="./..." -- -parallel=8 -timeout=7m -short -failfast $COVERAGE_FLAGS
260+
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
261+
--packages="./..." -- $PARALLEL_FLAG -short -failfast $COVERAGE_FLAGS
252262
253263
- name: Print test stats
254264
if: success() || failure()
@@ -257,13 +267,6 @@ jobs:
257267
# so we need to print the test stats to the log.
258268
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
259269
260-
- uses: actions/upload-artifact@v3
261-
if: success() || failure()
262-
with:
263-
name: gotests-${{ matrix.os }}.xml
264-
path: ./gotests.xml
265-
retention-days: 30
266-
267270
- uses: ./.github/actions/upload-datadog
268271
if: always()
269272
with:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,15 @@ test: test-clean
610610

611611
# When updating -timeout for this test, keep in sync with
612612
# test-go-postgres (.github/workflows/coder.yaml).
613+
# Do add coverage flags so that test caching works.
613614
test-postgres: test-clean test-postgres-docker
614615
# The postgres test is prone to failure, so we limit parallelism for
615616
# more consistent execution.
616617
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum \
617618
--junitfile="gotests.xml" \
618619
--jsonfile="gotests.json" \
619620
--packages="./..." -- \
620-
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
621-
-coverpkg=./... \
621+
-timeout=20m \
622622
-failfast
623623
.PHONY: test-postgres
624624

scaletest/scaletest.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ fi
8484
if [[ -z "${SCALETEST_PROMETHEUS_REMOTE_WRITE_USER}" ]] || [[ -z "${SCALETEST_PROMETHEUS_REMOTE_WRITE_PASSWORD}" ]]; then
8585
echo "SCALETEST_PROMETHEUS_REMOTE_WRITE_USER or SCALETEST_PROMETHEUS_REMOTE_WRITE_PASSWORD not specified."
8686
echo "No prometheus metrics will be collected!"
87-
read -pr "Continue (y/N)? " choice
88-
case "$choice" in
89-
y | Y | yes | YES) ;;
90-
*) exit 1 ;;
91-
esac
87+
read -p "Continue (y/N)? " -n1 -r
88+
if [[ "${REPLY}" != [yY] ]]; then
89+
exit 1
90+
fi
9291
fi
9392

9493
SCALETEST_SCENARIO_VARS="${PROJECT_ROOT}/scaletest/terraform/scenario-${SCALETEST_SCENARIO}.tfvars"

scaletest/terraform/coder.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ resource "kubernetes_namespace" "coder_namespace" {
3434
]
3535
}
3636

37-
resource "random_password" "postgres-admin-password" {
37+
resource "random_password" "coder-postgres-password" {
3838
length = 12
3939
}
4040

41-
resource "random_password" "coder-postgres-password" {
41+
resource "random_password" "prometheus-postgres-password" {
4242
length = 12
4343
}
4444

scaletest/terraform/gcp_db.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,13 @@ resource "google_sql_user" "coder" {
5151
# required for postgres, otherwise user fails to delete
5252
deletion_policy = "ABANDON"
5353
}
54+
55+
resource "google_sql_user" "prometheus" {
56+
project = var.project_id
57+
instance = google_sql_database_instance.db.id
58+
name = "${var.name}-prometheus"
59+
type = "BUILT_IN"
60+
password = random_password.prometheus-postgres-password.result
61+
# required for postgres, otherwise user fails to delete
62+
deletion_policy = "ABANDON"
63+
}

scaletest/terraform/prometheus.tf

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
locals {
2-
prometheus_helm_repo = "https://charts.bitnami.com/bitnami"
3-
prometheus_helm_chart = "kube-prometheus"
4-
prometheus_helm_version = null // just use latest
5-
prometheus_release_name = "prometheus"
6-
prometheus_namespace = "prometheus"
7-
prometheus_remote_write_enabled = var.prometheus_remote_write_password != ""
2+
prometheus_helm_repo = "https://charts.bitnami.com/bitnami"
3+
prometheus_helm_chart = "kube-prometheus"
4+
prometheus_exporter_helm_repo = "https://prometheus-community.github.io/helm-charts"
5+
prometheus_exporter_helm_chart = "prometheus-postgres-exporter"
6+
prometheus_release_name = "prometheus"
7+
prometheus_exporter_release_name = "prometheus-postgres-exporter"
8+
prometheus_namespace = "prometheus"
9+
prometheus_remote_write_enabled = var.prometheus_remote_write_password != ""
810
}
911

1012
# Create a namespace to hold our Prometheus deployment.
@@ -37,7 +39,6 @@ resource "helm_release" "prometheus-chart" {
3739
repository = local.prometheus_helm_repo
3840
chart = local.prometheus_helm_chart
3941
name = local.prometheus_release_name
40-
version = local.prometheus_helm_version
4142
namespace = kubernetes_namespace.prometheus_namespace.metadata.0.name
4243
values = [<<EOF
4344
alertmanager:
@@ -97,6 +98,48 @@ prometheus:
9798
]
9899
}
99100

101+
resource "kubernetes_secret" "prometheus-postgres-password" {
102+
type = "kubernetes.io/basic-auth"
103+
metadata {
104+
name = "prometheus-postgres"
105+
namespace = kubernetes_namespace.prometheus_namespace.metadata.0.name
106+
}
107+
data = {
108+
username = google_sql_user.prometheus.name
109+
password = google_sql_user.prometheus.password
110+
}
111+
}
112+
113+
# Install Prometheus Postgres exporter helm chart
114+
resource "helm_release" "prometheus-exporter-chart" {
115+
repository = local.prometheus_exporter_helm_repo
116+
chart = local.prometheus_exporter_helm_chart
117+
name = local.prometheus_exporter_release_name
118+
namespace = local.prometheus_namespace
119+
values = [<<EOF
120+
affinity:
121+
nodeAffinity:
122+
requiredDuringSchedulingIgnoredDuringExecution:
123+
nodeSelectorTerms:
124+
- matchExpressions:
125+
- key: "cloud.google.com/gke-nodepool"
126+
operator: "In"
127+
values: ["${google_container_node_pool.misc.name}"]
128+
config:
129+
datasource:
130+
host: "${google_sql_database_instance.db.private_ip_address}"
131+
user: "${google_sql_user.prometheus.name}"
132+
database: "${google_sql_database.coder.name}"
133+
passwordSecret:
134+
name: "${kubernetes_secret.prometheus-postgres-password.metadata.0.name}"
135+
key: password
136+
autoDiscoverDatabases: true
137+
serviceMonitor:
138+
enabled: true
139+
EOF
140+
]
141+
}
142+
100143
# NOTE: this is created as a local file before being applied
101144
# as the kubernetes_manifest resource needs to be run separately
102145
# after creating a cluster, and we want this to be brought up

0 commit comments

Comments
 (0)