Skip to content

Commit

Permalink
feat: Configure Google Cloud Telemetry flags on the proxy. (#223)
Browse files Browse the repository at this point in the history
Allow users to configure the --telemetry-prefix --telemetry-project --telemetry-sample-rate flags
on the proxy.

Related to #45
  • Loading branch information
hessjcg authored Feb 28, 2023
1 parent 5be6c3b commit 76b0f39
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,15 @@ spec:
description: HTTPPort the port for Prometheus and health check server. This sets the proxy container's CLI argument `--http-port`
format: int32
type: integer
telemetryPrefix:
description: TelemetryPrefix is the prefix for Cloud Monitoring metrics. This sets the proxy container's CLI argument `--telemetry-prefix`
type: string
telemetryProject:
description: TelemetryProject enables Cloud Monitoring and Cloud Trace with the provided project ID. This sets the proxy container's CLI argument `--telemetry-project`
type: string
telemetrySampleRate:
description: TelemetrySampleRate is the Cloud Trace sample rate. A smaller number means more traces. This sets the proxy container's CLI argument `--telemetry-sample-rate`
type: integer
type: object
type: object
instances:
Expand Down
3 changes: 3 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ _Appears in:_

| Field | Description |
| --- | --- |
| `telemetryProject` _string_ | TelemetryProject enables Cloud Monitoring and Cloud Trace with the provided project ID. This sets the proxy container's CLI argument `--telemetry-project` |
| `telemetryPrefix` _string_ | TelemetryPrefix is the prefix for Cloud Monitoring metrics. This sets the proxy container's CLI argument `--telemetry-prefix` |
| `telemetrySampleRate` _integer_ | TelemetrySampleRate is the Cloud Trace sample rate. A smaller number means more traces. This sets the proxy container's CLI argument `--telemetry-sample-rate` |
| `httpPort` _integer_ | HTTPPort the port for Prometheus and health check server. This sets the proxy container's CLI argument `--http-port` |
| `disableTraces` _boolean_ | DisableTraces disables Cloud Trace testintegration (used with telemetryProject) This sets the proxy container's CLI argument `--disable-traces` |
| `disableMetrics` _boolean_ | DisableMetrics disables Cloud Monitoring testintegration (used with telemetryProject) This sets the proxy container's CLI argument `--disable-metrics` |
Expand Down
9 changes: 9 additions & 0 deletions installer/cloud-sql-proxy-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,15 @@ spec:
description: HTTPPort the port for Prometheus and health check server. This sets the proxy container's CLI argument `--http-port`
format: int32
type: integer
telemetryPrefix:
description: TelemetryPrefix is the prefix for Cloud Monitoring metrics. This sets the proxy container's CLI argument `--telemetry-prefix`
type: string
telemetryProject:
description: TelemetryProject enables Cloud Monitoring and Cloud Trace with the provided project ID. This sets the proxy container's CLI argument `--telemetry-project`
type: string
telemetrySampleRate:
description: TelemetrySampleRate is the Cloud Trace sample rate. A smaller number means more traces. This sets the proxy container's CLI argument `--telemetry-sample-rate`
type: integer
type: object
type: object
instances:
Expand Down
15 changes: 15 additions & 0 deletions internal/api/v1alpha1/authproxyworkload_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ type AdminServerSpec struct {

// TelemetrySpec specifies how the proxy container will expose telemetry.
type TelemetrySpec struct {
// TelemetryProject enables Cloud Monitoring and Cloud Trace with the provided project ID.
// This sets the proxy container's CLI argument `--telemetry-project`
//+kubebuilder:validation:Optional
TelemetryProject *string `json:"telemetryProject,omitempty"`

// TelemetryPrefix is the prefix for Cloud Monitoring metrics.
// This sets the proxy container's CLI argument `--telemetry-prefix`
//+kubebuilder:validation:Optional
TelemetryPrefix *string `json:"telemetryPrefix,omitempty"`

// TelemetrySampleRate is the Cloud Trace sample rate. A smaller number means more traces.
// This sets the proxy container's CLI argument `--telemetry-sample-rate`
//+kubebuilder:validation:Optional
TelemetrySampleRate *int `json:"telemetrySampleRate,omitempty"`

// HTTPPort the port for Prometheus and health check server.
// This sets the proxy container's CLI argument `--http-port`
//+kubebuilder:validation:Optional
Expand Down
15 changes: 15 additions & 0 deletions internal/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions internal/workload/podspec_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,21 @@ func (s *updateState) applyTelemetrySpec(p *cloudsqlapi.AuthProxyWorkload) {
}
tel := p.Spec.AuthProxyContainer.Telemetry

if tel.TelemetrySampleRate != nil {
s.addProxyContainerEnvVar(p, "CSQL_PROXY_TELEMETRY_SAMPLE_RATE", fmt.Sprintf("%d", *tel.TelemetrySampleRate))
}
if tel.DisableTraces != nil && *tel.DisableTraces {
s.addProxyContainerEnvVar(p, "CSQL_PROXY_DISABLE_TRACES", "true")
}
if tel.DisableMetrics != nil && *tel.DisableMetrics {
s.addProxyContainerEnvVar(p, "CSQL_PROXY_DISABLE_METRICS", "true")
}
if tel.TelemetryProject != nil {
s.addProxyContainerEnvVar(p, "CSQL_PROXY_TELEMETRY_PROJECT", *tel.TelemetryProject)
}
if tel.TelemetryPrefix != nil {
s.addProxyContainerEnvVar(p, "CSQL_PROXY_TELEMETRY_PREFIX", *tel.TelemetryPrefix)
}

return
}
Expand Down
12 changes: 9 additions & 3 deletions internal/workload/podspec_updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,12 @@ func TestProxyCLIArgs(t *testing.T) {
AuthProxyContainer: &v1alpha1.AuthProxyContainerSpec{
SQLAdminAPIEndpoint: "https://example.com",
Telemetry: &v1alpha1.TelemetrySpec{
HTTPPort: ptr(int32(9092)),
DisableTraces: &wantTrue,
DisableMetrics: &wantTrue,
HTTPPort: ptr(int32(9092)),
DisableTraces: &wantTrue,
DisableMetrics: &wantTrue,
TelemetryPrefix: ptr("telprefix"),
TelemetryProject: ptr("telproject"),
TelemetrySampleRate: ptr(200),
},
AdminServer: &v1alpha1.AdminServerSpec{
EnableAPIs: []string{"Debug", "QuitQuitQuit"},
Expand All @@ -649,6 +652,9 @@ func TestProxyCLIArgs(t *testing.T) {
},
wantWorkloadEnv: map[string]string{
"CSQL_PROXY_SQLADMIN_API_ENDPOINT": "https://example.com",
"CSQL_PROXY_TELEMETRY_SAMPLE_RATE": "200",
"CSQL_PROXY_TELEMETRY_PROJECT": "telproject",
"CSQL_PROXY_TELEMETRY_PREFIX": "telprefix",
"CSQL_PROXY_HTTP_PORT": "9092",
"CSQL_PROXY_ADMIN_PORT": "9091",
"CSQL_PROXY_DEBUG": "true",
Expand Down

0 comments on commit 76b0f39

Please sign in to comment.