Skip to content

Commit

Permalink
Write GKE metrics with the apprioate labels (#2626)
Browse files Browse the repository at this point in the history
Also makes preperations to expose the sidecar proxy.
  • Loading branch information
jianglai authored Dec 18, 2024
1 parent da8df1f commit c9c61e4
Show file tree
Hide file tree
Showing 30 changed files with 887 additions and 760 deletions.
10 changes: 5 additions & 5 deletions common/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ org.jacoco:org.jacoco.core:0.8.12=jacocoAnt
org.jacoco:org.jacoco.report:0.8.12=jacocoAnt
org.javassist:javassist:3.28.0-GA=checkstyle
org.jspecify:jspecify:0.3.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
org.junit.jupiter:junit-jupiter-api:5.11.3=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.11.3=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.11.3=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.11.3=testCompileClasspath,testRuntimeClasspath
org.junit:junit-bom:5.11.3=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.11.4=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.11.4=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.11.4=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.11.4=testCompileClasspath,testRuntimeClasspath
org.junit:junit-bom:5.11.4=testCompileClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-commons:9.7=jacocoAnt
org.ow2.asm:asm-tree:9.7=jacocoAnt
Expand Down
2 changes: 0 additions & 2 deletions config/dependency-license/allowed_licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@
{
// "Apache License, Version 2.0".
"moduleLicense": null,
"moduleVersion": "26.26.0",
"moduleName": "com.google.cloud:libraries-bom"
},
{
Expand Down Expand Up @@ -370,7 +369,6 @@
// "Apache License, Version 2.0".
{
"moduleLicense": null,
"moduleVersion": "1.33.0",
"moduleName": "io.opentelemetry:opentelemetry-bom"
},
{
Expand Down
365 changes: 206 additions & 159 deletions core/gradle.lockfile

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
import com.google.monitoring.metrics.MetricReporter;
import com.google.monitoring.metrics.MetricWriter;
import com.google.monitoring.metrics.stackdriver.StackdriverWriter;
import dagger.Lazy;
import dagger.Module;
import dagger.Provides;
import google.registry.config.CredentialModule.ApplicationDefaultCredential;
import google.registry.config.RegistryConfig.Config;
import google.registry.util.Clock;
import google.registry.util.GoogleCredentialsBundle;
import google.registry.util.MetricParameters;
import google.registry.util.RegistryEnvironment;
import javax.inject.Named;
import javax.inject.Singleton;
import org.joda.time.Duration;
Expand Down Expand Up @@ -66,23 +69,28 @@ static Monitoring provideMonitoring(
@Provides
static MetricWriter provideMetricWriter(
Monitoring monitoringClient,
Lazy<MetricParameters> gkeParameters,
@Config("projectId") String projectId,
@Config("stackdriverMaxQps") int maxQps,
@Config("stackdriverMaxPointsPerRequest") int maxPointsPerRequest,
@Named("spoofedGceInstanceId") String instanceId) {
// The MonitoredResource for GAE apps is not writable (and missing fields anyway) so we just
// use the gce_instance resource type instead.
MonitoredResource resource =
RegistryEnvironment.isOnJetty()
? new MonitoredResource()
.setType("gke_container")
.setLabels(gkeParameters.get().makeLabelsMap())
:
// The MonitoredResource for GAE apps is not writable (and missing fields anyway) so we
// just use the gce_instance resource type instead.
new MonitoredResource()
.setType("gce_instance")
.setLabels(
ImmutableMap.of(
// The "zone" field MUST be a valid GCE zone, so we fake one.
"zone", SPOOFED_GCE_ZONE, "instance_id", instanceId));

return new StackdriverWriter(
monitoringClient,
projectId,
new MonitoredResource()
.setType("gce_instance")
.setLabels(
ImmutableMap.of(
// The "zone" field MUST be a valid GCE zone, so we fake one.
"zone", SPOOFED_GCE_ZONE, "instance_id", instanceId)),
maxQps,
maxPointsPerRequest);
monitoringClient, projectId, resource, maxQps, maxPointsPerRequest);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ public void handleRequest(HttpServletRequest req, HttpServletResponse rsp) throw
GkeService service = Action.ServiceGetter.get(route.get().action());
String expectedDomain = RegistryConfig.getServiceUrl(service).getHost();
String actualDomain = req.getServerName();
if (!Objects.equals(actualDomain, expectedDomain)) {
// If the hostname is "localhost", it must have come from the sidecar proxy.
if (!Objects.equals("localhost", actualDomain)
&& !Objects.equals(actualDomain, expectedDomain)) {
logger.atWarning().log(
"Actual domain %s does not match expected domain %s", actualDomain, expectedDomain);
rsp.sendError(SC_NOT_FOUND);
Expand Down
4 changes: 2 additions & 2 deletions db/buildscript-gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2=classpath
com.fasterxml.jackson:jackson-bom:2.15.2=classpath
gradle.plugin.org.flywaydb:gradle-plugin-publishing:11.0.1=classpath
org.flywaydb.flyway:org.flywaydb.flyway.gradle.plugin:11.0.1=classpath
org.flywaydb:flyway-core:11.0.1=classpath
org.flywaydb:flyway-database-postgresql:11.0.1=classpath
org.flywaydb:flyway-core:11.1.0=classpath
org.flywaydb:flyway-database-postgresql:11.1.0=classpath
empty=
14 changes: 7 additions & 7 deletions db/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ org.checkerframework:checker-qual:3.12.0=checkstyle
org.checkerframework:checker-qual:3.33.0=annotationProcessor,errorprone,testAnnotationProcessor
org.checkerframework:checker-qual:3.42.0=testCompileClasspath
org.checkerframework:checker-qual:3.43.0=deploy_jar,runtimeClasspath,testRuntimeClasspath
org.flywaydb:flyway-core:11.0.1=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.flywaydb:flyway-database-postgresql:11.0.1=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.flywaydb:flyway-core:11.1.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.flywaydb:flyway-database-postgresql:11.1.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath
org.jacoco:org.jacoco.agent:0.8.12=jacocoAgent,jacocoAnt
org.jacoco:org.jacoco.ant:0.8.12=jacocoAnt
Expand All @@ -102,11 +102,11 @@ org.jacoco:org.jacoco.report:0.8.12=jacocoAnt
org.javassist:javassist:3.28.0-GA=checkstyle
org.jetbrains:annotations:17.0.0=testCompileClasspath,testRuntimeClasspath
org.jspecify:jspecify:0.3.0=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.11.3=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.11.3=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.11.3=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.11.3=testCompileClasspath,testRuntimeClasspath
org.junit:junit-bom:5.11.3=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.11.4=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.11.4=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.11.4=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.11.4=testCompileClasspath,testRuntimeClasspath
org.junit:junit-bom:5.11.4=testCompileClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-analysis:9.2=deploy_jar,runtimeClasspath,testRuntimeClasspath
org.ow2.asm:asm-commons:9.2=deploy_jar,runtimeClasspath,testRuntimeClasspath
Expand Down
2 changes: 1 addition & 1 deletion jetty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ tasks.register('deployQueue', Exec) {
}

tasks.register('deployNomulus', Exec) {
dependsOn('pushNomulusImage', 'deployCloudSchedulerAndQueue')
dependsOn('pushNomulusImage', ':proxy:pushProxyImage', 'deployCloudSchedulerAndQueue')
configure verifyDeploymentConfig
commandLine './deploy-nomulus-for-env.sh', "${rootProject.environment}", "${rootProject.baseDomain}"
}
Expand Down
4 changes: 4 additions & 0 deletions jetty/deploy-nomulus-for-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ do
do
sed s/GCP_PROJECT/"${project}"/g "./kubernetes/nomulus-${service}.yaml" | \
sed s/ENVIRONMENT/"${environment}"/g | \
sed s/PROXY_ENV/"${environment}"/g | \
sed s/PROXY_NAME/"proxy"/g | \
kubectl apply -f -
# canary
sed s/GCP_PROJECT/"${project}"/g "./kubernetes/nomulus-${service}.yaml" | \
sed s/ENVIRONMENT/"${environment}"/g | \
sed s/PROXY_ENV/"${environment}_canary"/g | \
sed s/PROXY_NAME/"proxy-canary"/g | \
sed s/"${service}"/"${service}-canary"/g | \
kubectl apply -f -
done
Expand Down
Loading

0 comments on commit c9c61e4

Please sign in to comment.