Skip to content

Commit

Permalink
fix logmetricprojectref
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Jun 7, 2024
1 parent 53ff50e commit 507c174
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 111 deletions.
2 changes: 2 additions & 0 deletions config/tests/samples/create/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func NewHarnessWithOptions(ctx context.Context, t *testing.T, opts *HarnessOptio
testgcp.TestAttachedClusterName.Set("xks-cluster")
testgcp.TestDependentNoNetworkProjectID.Set("mock-project")
testgcp.TestDependentOrgProjectID.Set("example-project-01")
testgcp.TestDependentFolderProjectID.Set("example-project-02")
testgcp.FirestoreTestProject.Set("cnrm-test-firestore")
testgcp.IdentityPlatformTestProject.Set("kcc-identity-platform")
testgcp.RecaptchaEnterpriseTestProject.Set("kcc-recaptcha-enterprise")
Expand Down Expand Up @@ -355,6 +356,7 @@ func NewHarnessWithOptions(ctx context.Context, t *testing.T, opts *HarnessOptio
ProjectNumber: 12345678,
}
testgcp.TestDependentOrgProjectID.Set("example-project-01")
testgcp.TestDependentFolderProjectID.Set("example-project-02")
testgcp.FirestoreTestProject.Set("cnrm-test-firestore")
testgcp.IdentityPlatformTestProject.Set("kcc-identity-platform")
testgcp.RecaptchaEnterpriseTestProject.Set("kcc-recaptcha-enterprise")
Expand Down
2 changes: 1 addition & 1 deletion config/tests/samples/create/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func updateProjectResourceWithExistingResourceIDs(t *testing.T, unstructs []*uns
}

if projectInFolder {
dp = testgcp.GetDependentFolderProjectID(t)
dp = testgcp.TestDependentFolderProjectID.Get()
} else if projectInOrg {
dp = testgcp.TestDependentOrgProjectID.Get()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/test/controller/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func ReplaceTestVars(t *testing.T, b []byte, uniqueID string, project testgcp.GC
s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestOrgID.Key), fmt.Sprintf("\"%s\"", testgcp.TestOrgID.Get()), -1)
s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentOrgProjectID.Key), fmt.Sprintf("\"%s\"", testgcp.TestDependentOrgProjectID.Get()), -1)
s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentOrgProjectID.Key), fmt.Sprintf("projects/%s", testgcp.TestDependentOrgProjectID.Get()), -1)
s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentFolderProjectID), fmt.Sprintf("projects/%s", testgcp.GetDependentFolderProjectID(t)), -1)
s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentFolderProjectID.Key), fmt.Sprintf("projects/%s", testgcp.TestDependentFolderProjectID.Get()), -1)
s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentOrgProjectIDWithoutQuotation), fmt.Sprintf("%s", testgcp.TestDependentOrgProjectID.Get()), -1)
s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentFolderProjectID), fmt.Sprintf("\"%s\"", testgcp.GetDependentFolderProjectID(t)), -1)
s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentFolderProjectID.Key), fmt.Sprintf("\"%s\"", testgcp.TestDependentFolderProjectID.Get()), -1)
s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentFolder2ProjectID), fmt.Sprintf("projects/%s", testgcp.GetDependentFolder2ProjectID(t)), -1)
s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentNoNetworkProjectID.Key), fmt.Sprintf("projects/%s", testgcp.TestDependentNoNetworkProjectID.Get()), -1)
s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentNoNetworkProjectID.Key), fmt.Sprintf("\"%s\"", testgcp.TestDependentNoNetworkProjectID.Get()), -1)
Expand Down
9 changes: 2 additions & 7 deletions pkg/test/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var (
TestFolder2ID = EnvVar{Key: "TEST_FOLDER_2_ID"}
TestOrgID = EnvVar{Key: "TEST_ORG_ID"}
TestDependentOrgProjectID = EnvVar{Key: "TEST_DEPENDENT_ORG_PROJECT_ID"}
TestDependentFolderProjectID = EnvVar{Key: "TEST_DEPENDENT_FOLDER_PROJECT_ID"}
TestDependentNoNetworkProjectID = EnvVar{Key: "TEST_DEPENDENT_NO_NETWORK_PROJECT_ID"} // A dependent project with default network disabled
TestBillingAccountID = EnvVar{Key: "TEST_BILLING_ACCOUNT_ID"}
IAMIntegrationTestsOrganizationID = EnvVar{Key: "IAM_INTEGRATION_TESTS_ORGANIZATION_ID"}
IAMIntegrationTestsBillingAccountID = EnvVar{Key: "IAM_INTEGRATION_TESTS_BILLING_ACCOUNT_ID"}
Expand All @@ -65,14 +67,12 @@ var (
FirestoreTestProject = EnvVar{Key: "FIRESTORE_TEST_PROJECT"}
IdentityPlatformTestProject = EnvVar{Key: "IDENTITY_PLATFORM_TEST_PROJECT"}
RecaptchaEnterpriseTestProject = EnvVar{Key: "RECAPTCHA_ENTERPRISE_TEST_PROJECT"}
TestDependentNoNetworkProjectID = EnvVar{Key: "TEST_DEPENDENT_NO_NETWORK_PROJECT_ID"} // A dependent project with default network disabled
TestKCCVertexAIIndexBucket = EnvVar{Key: "KCC_VERTEX_AI_INDEX_TEST_BUCKET"}
TestKCCVertexAIIndexDataURI = EnvVar{Key: "KCC_VERTEX_AI_INDEX_TEST_DATA_URI"}
)

const (
TestDependentFolder2ProjectID = "TEST_DEPENDENT_FOLDER_2_PROJECT_ID"
TestDependentFolderProjectID = "TEST_DEPENDENT_FOLDER_PROJECT_ID"
IsolatedTestOrgName = "ISOLATED_TEST_ORG_NAME"
CloudFunctionsTestProject = "CLOUD_FUNCTIONS_TEST_PROJECT"
InterconnectTestProject = "INTERCONNECT_TEST_PROJECT"
Expand All @@ -83,7 +83,6 @@ const (

var (
testDependentFolder2ProjectID = os.Getenv(TestDependentFolder2ProjectID)
testDependentFolderProjectID = os.Getenv(TestDependentFolderProjectID)
isolatedTestOrgName = os.Getenv(IsolatedTestOrgName)
cloudFunctionsTestProject = os.Getenv(CloudFunctionsTestProject)
interconnectTestProject = os.Getenv(InterconnectTestProject)
Expand Down Expand Up @@ -158,10 +157,6 @@ func FindDefaultServiceAccount() (string, error) {
return rawCreds["client_email"], nil
}

func GetDependentFolderProjectID(_ *testing.T) string {
return testDependentFolderProjectID
}

func GetDependentFolder2ProjectID(_ *testing.T) string {
return testDependentFolder2ProjectID
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ spec:
unit: s
valueType: DISTRIBUTION
projectRef:
kind: Project
name: otherproject
resourceID: linearlogmetric-${uniqueId}
valueExtractor: EXTRACT(jsonPayload.response)
Expand All @@ -58,7 +57,7 @@ status:
createTime: "1970-01-01T00:00:00Z"
metricDescriptor:
description: An updated sample log metric
name: projects/other${uniqueId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}
name: projects/example-project-02/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}
type: logging.googleapis.com/user/linearlogmetric-${uniqueId}
observedGeneration: 2
updateTime: "1970-01-01T00:00:00Z"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GET https://cloudresourcemanager.googleapis.com/v1/projects/other${uniqueId}?alt=json&prettyPrint=false
GET https://cloudresourcemanager.googleapis.com/v1/projects/example-project-02?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

403 Forbidden
Expand All @@ -22,6 +22,35 @@ X-Xss-Protection: 0

---

POST https://cloudbilling.googleapis.com/v1/billingAccounts/123456-777777-000001:testIamPermissions?alt=json&prettyPrint=false
Content-Type: application/json
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

{
"permissions": [
"billing.resourceAssociations.create"
]
}

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"permissions": [
"billing.resourceAssociations.create"
]
}

---

POST https://cloudresourcemanager.googleapis.com/v1/projects?alt=json&prettyPrint=false
Content-Type: application/json
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager
Expand All @@ -36,7 +65,7 @@ User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terr
"id": "${testFolderId}",
"type": "folder"
},
"projectId": "other${uniqueId}"
"projectId": "example-project-02"
}

200 OK
Expand Down Expand Up @@ -88,14 +117,65 @@ X-Xss-Protection: 0
},
"name": "projects/${projectNumber}",
"parent": "folders/${testFolderId}",
"projectId": "other${uniqueId}",
"projectId": "example-project-02",
"state": "ACTIVE"
}
}

---

GET https://cloudresourcemanager.googleapis.com/v1/projects/other${uniqueId}?alt=json&prettyPrint=false
PUT https://cloudbilling.googleapis.com/v1/projects/example-project-02/billingInfo?alt=json&prettyPrint=false
Content-Type: application/json
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

{
"billingAccountName": "billingAccounts/123456-777777-000001"
}

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"billingAccountName": "billingAccounts/123456-777777-000001",
"billingEnabled": true,
"name": "projects/example-project-02/billingInfo",
"projectId": "example-project-02"
}

---

GET https://cloudbilling.googleapis.com/v1/projects/example-project-02/billingInfo?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"billingAccountName": "billingAccounts/123456-777777-000001",
"billingEnabled": true,
"name": "projects/example-project-02/billingInfo",
"projectId": "example-project-02"
}

---

GET https://cloudresourcemanager.googleapis.com/v1/projects/example-project-02?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

200 OK
Expand All @@ -121,13 +201,13 @@ X-Xss-Protection: 0
"id": "${testFolderId}",
"type": "folder"
},
"projectId": "other${uniqueId}",
"projectId": "example-project-02",
"projectNumber": "${projectNumber}"
}

---

GET https://cloudbilling.googleapis.com/v1/projects/other${uniqueId}/billingInfo?alt=json&prettyPrint=false
GET https://cloudbilling.googleapis.com/v1/projects/example-project-02/billingInfo?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

200 OK
Expand All @@ -142,15 +222,15 @@ X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"billingAccountName": "",
"billingEnabled": false,
"name": "projects/other${uniqueId}/billingInfo",
"projectId": "other${uniqueId}"
"billingAccountName": "billingAccounts/123456-777777-000001",
"billingEnabled": true,
"name": "projects/example-project-02/billingInfo",
"projectId": "example-project-02"
}

---

GET https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false
GET https://logging.googleapis.com/v2/projects/example-project-02/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5

404 Not Found
Expand All @@ -174,7 +254,7 @@ X-Xss-Protection: 0

---

POST https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics?alt=json&prettyPrint=false
POST https://logging.googleapis.com/v2/projects/example-project-02/metrics?alt=json&prettyPrint=false
Content-Type: application/json
User-Agent: google-api-go-client/0.5

Expand Down Expand Up @@ -260,7 +340,7 @@ X-Xss-Protection: 0
}
],
"metricKind": "DELTA",
"name": "projects/other${uniqueId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"name": "projects/example-project-02/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"unit": "bit",
"valueType": "DISTRIBUTION"
Expand All @@ -272,7 +352,7 @@ X-Xss-Protection: 0

---

GET https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false
GET https://logging.googleapis.com/v2/projects/example-project-02/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5

200 OK
Expand Down Expand Up @@ -316,7 +396,7 @@ X-Xss-Protection: 0
}
],
"metricKind": "DELTA",
"name": "projects/other${uniqueId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"name": "projects/example-project-02/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"unit": "bit",
"valueType": "DISTRIBUTION"
Expand All @@ -328,7 +408,7 @@ X-Xss-Protection: 0

---

PUT https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false
PUT https://logging.googleapis.com/v2/projects/example-project-02/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false
Content-Type: application/json
User-Agent: google-api-go-client/0.5

Expand Down Expand Up @@ -430,7 +510,7 @@ X-Xss-Protection: 0
}
],
"metricKind": "DELTA",
"name": "projects/other${uniqueId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"name": "projects/example-project-02/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}",
"unit": "s",
"valueType": "DISTRIBUTION"
Expand Down Expand Up @@ -466,7 +546,7 @@ X-Xss-Protection: 0

---

DELETE https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false
DELETE https://logging.googleapis.com/v2/projects/example-project-02/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5

200 OK
Expand All @@ -480,77 +560,4 @@ X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{}

---

GET https://cloudresourcemanager.googleapis.com/v1/projects/other${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"createTime": "2024-04-01T12:34:56.123456Z",
"labels": {
"cnrm-test": "true",
"managed-by-cnrm": "true"
},
"lifecycleState": "ACTIVE",
"name": "A second project",
"parent": {
"id": "${testFolderId}",
"type": "folder"
},
"projectId": "other${uniqueId}",
"projectNumber": "${projectNumber}"
}

---

GET https://cloudbilling.googleapis.com/v1/projects/other${uniqueId}/billingInfo?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"billingAccountName": "",
"billingEnabled": false,
"name": "projects/other${uniqueId}/billingInfo",
"projectId": "other${uniqueId}"
}

---

DELETE https://cloudresourcemanager.googleapis.com/v1/projects/other${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{}
Loading

2 comments on commit 507c174

@yuwenma
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried turning on the golden object check on this test #2061

But it gives some awkward behavior: failed without any http or KRM object diff. One thing I found is that in the _http.log, there's one GET 404 request that uses the URL "https://logging.googleapis.com/v2/projects/${projectId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false" which contains ${projectId} but other URL uses the actual project value example-project-02. Do you have any clues what may go wrong? @gemmahou @justinsb

@gemmahou
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried turning on the golden object check on this test #2061

But it gives some awkward behavior: failed without any http or KRM object diff. One thing I found is that in the _http.log, there's one GET 404 request that uses the URL "https://logging.googleapis.com/v2/projects/${projectId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false" which contains ${projectId} but other URL uses the actual project value example-project-02. Do you have any clues what may go wrong? @gemmahou @justinsb

Ah I think I understand what's going on here: This line sets projectID to the annotation cnrm.cloud.google.com/project-id, which is the default project(mock-project) KCC runs. While in this test resource YAML, we specified another project(example-project-02) in projectRef.

I think project-id annotation and projectRef should be the same, if projectRef points to another project, the annotation should be set to that project as well. I need to take a look at the code related to project-id annotation and understand how it works. Maybe @justinsb has a better understanding here.

The other LLM tests passed because both project-id annotation and projectRef are the default mock-project.

Please sign in to comment.