Skip to content

Commit c9c61e4

Browse files
authored
Write GKE metrics with the apprioate labels (#2626)
Also makes preperations to expose the sidecar proxy.
1 parent da8df1f commit c9c61e4

File tree

30 files changed

+887
-760
lines changed

30 files changed

+887
-760
lines changed

common/gradle.lockfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ org.jacoco:org.jacoco.core:0.8.12=jacocoAnt
5656
org.jacoco:org.jacoco.report:0.8.12=jacocoAnt
5757
org.javassist:javassist:3.28.0-GA=checkstyle
5858
org.jspecify:jspecify:0.3.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
59-
org.junit.jupiter:junit-jupiter-api:5.11.3=testCompileClasspath,testRuntimeClasspath
60-
org.junit.jupiter:junit-jupiter-engine:5.11.3=testCompileClasspath,testRuntimeClasspath
61-
org.junit.platform:junit-platform-commons:1.11.3=testCompileClasspath,testRuntimeClasspath
62-
org.junit.platform:junit-platform-engine:1.11.3=testCompileClasspath,testRuntimeClasspath
63-
org.junit:junit-bom:5.11.3=testCompileClasspath,testRuntimeClasspath
59+
org.junit.jupiter:junit-jupiter-api:5.11.4=testCompileClasspath,testRuntimeClasspath
60+
org.junit.jupiter:junit-jupiter-engine:5.11.4=testCompileClasspath,testRuntimeClasspath
61+
org.junit.platform:junit-platform-commons:1.11.4=testCompileClasspath,testRuntimeClasspath
62+
org.junit.platform:junit-platform-engine:1.11.4=testCompileClasspath,testRuntimeClasspath
63+
org.junit:junit-bom:5.11.4=testCompileClasspath,testRuntimeClasspath
6464
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
6565
org.ow2.asm:asm-commons:9.7=jacocoAnt
6666
org.ow2.asm:asm-tree:9.7=jacocoAnt

config/dependency-license/allowed_licenses.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@
305305
{
306306
// "Apache License, Version 2.0".
307307
"moduleLicense": null,
308-
"moduleVersion": "26.26.0",
309308
"moduleName": "com.google.cloud:libraries-bom"
310309
},
311310
{
@@ -370,7 +369,6 @@
370369
// "Apache License, Version 2.0".
371370
{
372371
"moduleLicense": null,
373-
"moduleVersion": "1.33.0",
374372
"moduleName": "io.opentelemetry:opentelemetry-bom"
375373
},
376374
{

core/gradle.lockfile

Lines changed: 206 additions & 159 deletions
Large diffs are not rendered by default.

core/src/main/java/google/registry/monitoring/whitebox/StackdriverModule.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
import com.google.monitoring.metrics.MetricReporter;
2222
import com.google.monitoring.metrics.MetricWriter;
2323
import com.google.monitoring.metrics.stackdriver.StackdriverWriter;
24+
import dagger.Lazy;
2425
import dagger.Module;
2526
import dagger.Provides;
2627
import google.registry.config.CredentialModule.ApplicationDefaultCredential;
2728
import google.registry.config.RegistryConfig.Config;
2829
import google.registry.util.Clock;
2930
import google.registry.util.GoogleCredentialsBundle;
31+
import google.registry.util.MetricParameters;
32+
import google.registry.util.RegistryEnvironment;
3033
import javax.inject.Named;
3134
import javax.inject.Singleton;
3235
import org.joda.time.Duration;
@@ -66,23 +69,28 @@ static Monitoring provideMonitoring(
6669
@Provides
6770
static MetricWriter provideMetricWriter(
6871
Monitoring monitoringClient,
72+
Lazy<MetricParameters> gkeParameters,
6973
@Config("projectId") String projectId,
7074
@Config("stackdriverMaxQps") int maxQps,
7175
@Config("stackdriverMaxPointsPerRequest") int maxPointsPerRequest,
7276
@Named("spoofedGceInstanceId") String instanceId) {
73-
// The MonitoredResource for GAE apps is not writable (and missing fields anyway) so we just
74-
// use the gce_instance resource type instead.
77+
MonitoredResource resource =
78+
RegistryEnvironment.isOnJetty()
79+
? new MonitoredResource()
80+
.setType("gke_container")
81+
.setLabels(gkeParameters.get().makeLabelsMap())
82+
:
83+
// The MonitoredResource for GAE apps is not writable (and missing fields anyway) so we
84+
// just use the gce_instance resource type instead.
85+
new MonitoredResource()
86+
.setType("gce_instance")
87+
.setLabels(
88+
ImmutableMap.of(
89+
// The "zone" field MUST be a valid GCE zone, so we fake one.
90+
"zone", SPOOFED_GCE_ZONE, "instance_id", instanceId));
91+
7592
return new StackdriverWriter(
76-
monitoringClient,
77-
projectId,
78-
new MonitoredResource()
79-
.setType("gce_instance")
80-
.setLabels(
81-
ImmutableMap.of(
82-
// The "zone" field MUST be a valid GCE zone, so we fake one.
83-
"zone", SPOOFED_GCE_ZONE, "instance_id", instanceId)),
84-
maxQps,
85-
maxPointsPerRequest);
93+
monitoringClient, projectId, resource, maxQps, maxPointsPerRequest);
8694
}
8795

8896
@Provides

core/src/main/java/google/registry/request/RequestHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ public void handleRequest(HttpServletRequest req, HttpServletResponse rsp) throw
143143
GkeService service = Action.ServiceGetter.get(route.get().action());
144144
String expectedDomain = RegistryConfig.getServiceUrl(service).getHost();
145145
String actualDomain = req.getServerName();
146-
if (!Objects.equals(actualDomain, expectedDomain)) {
146+
// If the hostname is "localhost", it must have come from the sidecar proxy.
147+
if (!Objects.equals("localhost", actualDomain)
148+
&& !Objects.equals(actualDomain, expectedDomain)) {
147149
logger.atWarning().log(
148150
"Actual domain %s does not match expected domain %s", actualDomain, expectedDomain);
149151
rsp.sendError(SC_NOT_FOUND);

db/buildscript-gradle.lockfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2=classpath
99
com.fasterxml.jackson:jackson-bom:2.15.2=classpath
1010
gradle.plugin.org.flywaydb:gradle-plugin-publishing:11.0.1=classpath
1111
org.flywaydb.flyway:org.flywaydb.flyway.gradle.plugin:11.0.1=classpath
12-
org.flywaydb:flyway-core:11.0.1=classpath
13-
org.flywaydb:flyway-database-postgresql:11.0.1=classpath
12+
org.flywaydb:flyway-core:11.1.0=classpath
13+
org.flywaydb:flyway-database-postgresql:11.1.0=classpath
1414
empty=

db/gradle.lockfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ org.checkerframework:checker-qual:3.12.0=checkstyle
9292
org.checkerframework:checker-qual:3.33.0=annotationProcessor,errorprone,testAnnotationProcessor
9393
org.checkerframework:checker-qual:3.42.0=testCompileClasspath
9494
org.checkerframework:checker-qual:3.43.0=deploy_jar,runtimeClasspath,testRuntimeClasspath
95-
org.flywaydb:flyway-core:11.0.1=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
96-
org.flywaydb:flyway-database-postgresql:11.0.1=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
95+
org.flywaydb:flyway-core:11.1.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
96+
org.flywaydb:flyway-database-postgresql:11.1.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
9797
org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath
9898
org.jacoco:org.jacoco.agent:0.8.12=jacocoAgent,jacocoAnt
9999
org.jacoco:org.jacoco.ant:0.8.12=jacocoAnt
@@ -102,11 +102,11 @@ org.jacoco:org.jacoco.report:0.8.12=jacocoAnt
102102
org.javassist:javassist:3.28.0-GA=checkstyle
103103
org.jetbrains:annotations:17.0.0=testCompileClasspath,testRuntimeClasspath
104104
org.jspecify:jspecify:0.3.0=testCompileClasspath,testRuntimeClasspath
105-
org.junit.jupiter:junit-jupiter-api:5.11.3=testCompileClasspath,testRuntimeClasspath
106-
org.junit.jupiter:junit-jupiter-engine:5.11.3=testCompileClasspath,testRuntimeClasspath
107-
org.junit.platform:junit-platform-commons:1.11.3=testCompileClasspath,testRuntimeClasspath
108-
org.junit.platform:junit-platform-engine:1.11.3=testCompileClasspath,testRuntimeClasspath
109-
org.junit:junit-bom:5.11.3=testCompileClasspath,testRuntimeClasspath
105+
org.junit.jupiter:junit-jupiter-api:5.11.4=testCompileClasspath,testRuntimeClasspath
106+
org.junit.jupiter:junit-jupiter-engine:5.11.4=testCompileClasspath,testRuntimeClasspath
107+
org.junit.platform:junit-platform-commons:1.11.4=testCompileClasspath,testRuntimeClasspath
108+
org.junit.platform:junit-platform-engine:1.11.4=testCompileClasspath,testRuntimeClasspath
109+
org.junit:junit-bom:5.11.4=testCompileClasspath,testRuntimeClasspath
110110
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
111111
org.ow2.asm:asm-analysis:9.2=deploy_jar,runtimeClasspath,testRuntimeClasspath
112112
org.ow2.asm:asm-commons:9.2=deploy_jar,runtimeClasspath,testRuntimeClasspath

jetty/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ tasks.register('deployQueue', Exec) {
111111
}
112112

113113
tasks.register('deployNomulus', Exec) {
114-
dependsOn('pushNomulusImage', 'deployCloudSchedulerAndQueue')
114+
dependsOn('pushNomulusImage', ':proxy:pushProxyImage', 'deployCloudSchedulerAndQueue')
115115
configure verifyDeploymentConfig
116116
commandLine './deploy-nomulus-for-env.sh', "${rootProject.environment}", "${rootProject.baseDomain}"
117117
}

jetty/deploy-nomulus-for-env.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ do
3636
do
3737
sed s/GCP_PROJECT/"${project}"/g "./kubernetes/nomulus-${service}.yaml" | \
3838
sed s/ENVIRONMENT/"${environment}"/g | \
39+
sed s/PROXY_ENV/"${environment}"/g | \
40+
sed s/PROXY_NAME/"proxy"/g | \
3941
kubectl apply -f -
4042
# canary
4143
sed s/GCP_PROJECT/"${project}"/g "./kubernetes/nomulus-${service}.yaml" | \
4244
sed s/ENVIRONMENT/"${environment}"/g | \
45+
sed s/PROXY_ENV/"${environment}_canary"/g | \
46+
sed s/PROXY_NAME/"proxy-canary"/g | \
4347
sed s/"${service}"/"${service}-canary"/g | \
4448
kubectl apply -f -
4549
done

0 commit comments

Comments
 (0)