Skip to content

Commit dfca243

Browse files
committed
manifests: Enable query log file config for Prometheus
Prometheus and via prometheus-operator, provide the ability to log all PromQL queries to a file. This change enables CMO to support passing through that feature to Prometheus CR and the Prometheus pod for both platform monitoring and UWM. https://prometheus.io/docs/guides/query-log/
1 parent f98493b commit dfca243

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

pkg/manifests/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ type PrometheusK8sConfig struct {
177177
RemoteWrite []RemoteWriteSpec `json:"remoteWrite"`
178178
TelemetryMatches []string `json:"-"`
179179
AlertmanagerConfigs []AdditionalAlertmanagerConfig `json:"additionalAlertmanagerConfigs"`
180+
QueryLogFile string `json:"queryLogFile"`
180181
}
181182

182183
type AdditionalAlertmanagerConfig struct {
@@ -494,6 +495,7 @@ type PrometheusRestrictedConfig struct {
494495
EnforcedSampleLimit *uint64 `json:"enforcedSampleLimit"`
495496
EnforcedTargetLimit *uint64 `json:"enforcedTargetLimit"`
496497
AlertmanagerConfigs []AdditionalAlertmanagerConfig `json:"additionalAlertmanagerConfigs"`
498+
QueryLogFile string `json:"queryLogFile"`
497499
}
498500

499501
func (u *UserWorkloadConfiguration) applyDefaults() {

pkg/manifests/manifests.go

+20-12
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,10 @@ func (f *Factory) PrometheusK8s(host string, grpcTLS *v1.Secret, trustedCABundle
12811281
}
12821282
}
12831283

1284+
if f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.QueryLogFile != "" {
1285+
p.Spec.QueryLogFile = f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.QueryLogFile
1286+
}
1287+
12841288
telemetryEnabled := f.config.ClusterMonitoringConfiguration.TelemeterClientConfig.IsEnabled()
12851289
if telemetryEnabled && f.config.RemoteWrite {
12861290

@@ -1574,6 +1578,10 @@ func (f *Factory) PrometheusUserWorkload(grpcTLS *v1.Secret) (*monv1.Prometheus,
15741578
p.Spec.Thanos.Image = &f.config.Images.Thanos
15751579
}
15761580

1581+
if f.config.UserWorkloadConfiguration.Prometheus.QueryLogFile != "" {
1582+
p.Spec.QueryLogFile = f.config.UserWorkloadConfiguration.Prometheus.QueryLogFile
1583+
}
1584+
15771585
for i, container := range p.Spec.Containers {
15781586
if container.Name == "kube-rbac-proxy" || container.Name == "kube-rbac-proxy-thanos" {
15791587
p.Spec.Containers[i].Image = f.config.Images.KubeRbacProxy
@@ -2166,21 +2174,21 @@ type GrafanaDatasources struct {
21662174
}
21672175

21682176
type SecureJSONData struct {
2169-
BasicAuthPassword string `json:"basicAuthPassword"`
2177+
BasicAuthPassword string `json:"basicAuthPassword"`
21702178
}
21712179

21722180
type GrafanaDatasource struct {
2173-
Access string `json:"access"`
2174-
BasicAuth bool `json:"basicAuth"`
2175-
SecureJSONData SecureJSONData `json:"secureJsonData"`
2176-
BasicAuthUser string `json:"basicAuthUser"`
2177-
Editable bool `json:"editable"`
2178-
JsonData *GrafanaJsonData `json:"jsonData"`
2179-
Name string `json:"name"`
2180-
OrgId int `json:"orgId"`
2181-
Type string `json:"type"`
2182-
Url string `json:"url"`
2183-
Version int `json:"version"`
2181+
Access string `json:"access"`
2182+
BasicAuth bool `json:"basicAuth"`
2183+
SecureJSONData SecureJSONData `json:"secureJsonData"`
2184+
BasicAuthUser string `json:"basicAuthUser"`
2185+
Editable bool `json:"editable"`
2186+
JsonData *GrafanaJsonData `json:"jsonData"`
2187+
Name string `json:"name"`
2188+
OrgId int `json:"orgId"`
2189+
Type string `json:"type"`
2190+
Url string `json:"url"`
2191+
Version int `json:"version"`
21842192
}
21852193

21862194
type GrafanaJsonData struct {

pkg/manifests/manifests_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ func TestPrometheusK8sConfiguration(t *testing.T) {
948948
datacenter: eu-west
949949
remoteWrite:
950950
- url: "https://test.remotewrite.com/api/write"
951+
queryLogFile: /tmp/test
951952
ingress:
952953
baseAddress: monitoring-demo.staging.core-os.net
953954
`)
@@ -1053,6 +1054,10 @@ ingress:
10531054
if p.Spec.RemoteWrite[0].URL != "https://test.remotewrite.com/api/write" {
10541055
t.Fatal("Prometheus remote-write is not configured correctly")
10551056
}
1057+
1058+
if p.Spec.QueryLogFile != "/tmp/test" {
1059+
t.Fatal("Prometheus query logis not configured correctly")
1060+
}
10561061
}
10571062

10581063
func TestPrometheusK8sAdditionalAlertManagerConfigsSecret(t *testing.T) {

0 commit comments

Comments
 (0)