Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: expose TEST_BILLING_ACCOUNT_ID #2475

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dev/tasks/run-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ if [[ "${E2E_GCP_TARGET}" == "real" ]]; then

TEST_ORG_ID=$(gcloud projects get-ancestors ${GCP_PROJECT_ID} | grep organization | cut -f1 -d ' ')
export TEST_ORG_ID

if [[ -z "${TEST_BILLING_ACCOUNT_ID:-}" ]]; then
TEST_BILLING_ACCOUNT_ID=$(gcloud billing projects describe ${GCP_PROJECT_ID} --format='value(billingAccountName)' | cut -f2 -d/)
fi
echo "TEST_BILLING_ACCOUNT_ID=${TEST_BILLING_ACCOUNT_ID}"
export TEST_BILLING_ACCOUNT_ID
fi

# Run e2e tests against real gcp, capturing output
Expand Down
9 changes: 9 additions & 0 deletions hack/record-gcp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ echo "Using project: ${GCP_PROJECT_ID}"
TEST_FOLDER_ID=$(gcloud projects describe ${GCP_PROJECT_ID} --format='value(parent.id)')
export TEST_FOLDER_ID

TEST_ORG_ID=$(gcloud projects get-ancestors ${GCP_PROJECT_ID} | grep organization | cut -f1 -d ' ')
export TEST_ORG_ID

if [[ -z "${TEST_BILLING_ACCOUNT_ID:-}" ]]; then
TEST_BILLING_ACCOUNT_ID=$(gcloud billing projects describe ${GCP_PROJECT_ID} --format='value(billingAccountName)' | cut -f2 -d/)
fi
echo "TEST_BILLING_ACCOUNT_ID=${TEST_BILLING_ACCOUNT_ID}"
export TEST_BILLING_ACCOUNT_ID

# Run e2e tests against real gcp, capturing output
ARTIFACTS=$(pwd)/artifactz/realgcp \
E2E_KUBE_TARGET=envtest \
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: logging.cnrm.cloud.google.com/v1beta1
kind: LoggingLogExclusion
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/state-into-spec: merge
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 3
labels:
cnrm-test: "true"
name: exclusion-${uniqueId}
namespace: ${uniqueId}
spec:
billingAccountRef:
external: billingAccounts/016C6E-5D5038-702920
description: An updated log exclusion
disabled: true
filter: resource.type=gcs_bucket severity<=ERROR sample(insertId, 0.99)
resourceID: exclusion-${uniqueId}
status:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: The resource is up to date
reason: UpToDate
status: "True"
type: Ready
createTime: "1970-01-01T00:00:00Z"
observedGeneration: 3
updateTime: "1970-01-01T00:00:00Z"
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
GET https://logging.googleapis.com/v2/billingAccounts/${billingAccountID}/exclusions/${exclusionID}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

404 Not Found
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

{
"error": {
"code": 404,
"message": "Exclusion does not exist: exclusion-${uniqueId}",
"status": "NOT_FOUND"
}
}

---

POST https://logging.googleapis.com/v2/billingAccounts/${billingAccountID}/exclusions?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

{
"description": "A basic log exclusion",
"filter": "resource.type=gcs_bucket severity\u003cERROR sample(insertId, 0.99)",
"name": "exclusion-${uniqueId}"
}

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",
"description": "A basic log exclusion",
"filter": "resource.type=gcs_bucket severity\u003cERROR sample(insertId, 0.99)",
"name": "exclusion-${uniqueId}",
"updateTime": "2024-04-01T12:34:56.123456Z"
}

---

GET https://logging.googleapis.com/v2/billingAccounts/${billingAccountID}/exclusions/${exclusionID}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

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",
"description": "A basic log exclusion",
"filter": "resource.type=gcs_bucket severity\u003cERROR sample(insertId, 0.99)",
"name": "exclusion-${uniqueId}",
"updateTime": "2024-04-01T12:34:56.123456Z"
}

---

PATCH https://logging.googleapis.com/v2/billingAccounts/${billingAccountID}/exclusions/${exclusionID}?alt=json&updateMask=description%2Cdisabled%2Cfilter
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

{
"description": "An updated log exclusion",
"disabled": true,
"filter": "resource.type=gcs_bucket severity\u003c=ERROR sample(insertId, 0.99)"
}

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",
"description": "An updated log exclusion",
"disabled": true,
"filter": "resource.type=gcs_bucket severity\u003c=ERROR sample(insertId, 0.99)",
"name": "exclusion-${uniqueId}",
"updateTime": "2024-04-01T12:34:56.123456Z"
}

---

GET https://logging.googleapis.com/v2/billingAccounts/${billingAccountID}/exclusions/${exclusionID}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

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",
"description": "An updated log exclusion",
"disabled": true,
"filter": "resource.type=gcs_bucket severity\u003c=ERROR sample(insertId, 0.99)",
"name": "exclusion-${uniqueId}",
"updateTime": "2024-04-01T12:34:56.123456Z"
}

---

DELETE https://logging.googleapis.com/v2/billingAccounts/${billingAccountID}/exclusions/${exclusionID}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

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

{}

---

GET https://logging.googleapis.com/v2/billingAccounts/${billingAccountID}/exclusions/${exclusionID}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

404 Not Found
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

{
"error": {
"code": 404,
"message": "Exclusion does not exist: exclusion-${uniqueId}",
"status": "NOT_FOUND"
}
}
14 changes: 1 addition & 13 deletions tests/e2e/httplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,7 @@ func (x *Normalizer) Preprocess(events []*test.LogEntry) {
if index := strings.Index(u, "?"); index != -1 {
u = u[:index]
}
tokens := strings.Split(u, "/")
n := len(tokens)
if n >= 2 {
kind := tokens[n-2]
id := tokens[n-1]
switch kind {
case "tensorboards":
x.PathIDs[id] = "${tensorboardID}"
case "operations":
x.OperationIDs[id] = true
x.PathIDs[id] = "${operationID}"
}
}
x.ExtractIDsFromLinks(u)
}

for _, event := range events {
Expand Down
13 changes: 10 additions & 3 deletions tests/e2e/replacements.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package e2e

import "strings"
import (
"strings"
)

// Replacements manages replacements of dynamic values, like resource IDs
type Replacements struct {
Expand All @@ -33,8 +35,8 @@ func NewReplacements() *Replacements {
// ExtractIDsFromLinks parses the URL or partial URL, and extracts generated IDs from it.
func (r *Replacements) ExtractIDsFromLinks(link string) {
tokens := strings.Split(link, "/")
n := len(tokens)
if n >= 2 {
for len(tokens) >= 2 {
n := len(tokens)
kind := tokens[n-2]
id := tokens[n-1]
switch kind {
Expand All @@ -54,8 +56,12 @@ func (r *Replacements) ExtractIDsFromLinks(link string) {
r.PathIDs[id] = "${notificationChannelID}"
case "alertPolicies":
r.PathIDs[id] = "${alertPolicyID}"
case "billingAccounts":
r.PathIDs[id] = "${billingAccountID}"
case "conditions":
r.PathIDs[id] = "${conditionID}"
case "exclusions":
r.PathIDs[id] = "${exclusionID}"
case "groups":
r.PathIDs[id] = "${groupID}"
case "uptimeCheckConfigs":
Expand All @@ -64,5 +70,6 @@ func (r *Replacements) ExtractIDsFromLinks(link string) {
r.OperationIDs[id] = true
r.PathIDs[id] = "${operationID}"
}
tokens = tokens[:n-2]
}
}
Loading