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

Disregard K6_DISCARD_RESPONSE_BODIES #114

Merged
merged 3 commits into from
Sep 6, 2024
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
18 changes: 17 additions & 1 deletion src/internal/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RefinedResponse, ResponseType } from 'k6/http'
import { RefinedResponse, ResponseType, Params } from 'k6/http'

import { AWSConfig } from './config'
import { Endpoint } from './endpoint'
Expand Down Expand Up @@ -27,6 +27,22 @@ export class AWSClient {
readonly awsConfig: AWSConfig
readonly serviceName: string

// Because jslib-aws is mostly used as a way to setup or feed k6 tests, and
// we want the jslib-aws to be able to disregard k6's discardResponseBodies: meaning
// that for instance, even when setting discardResponseBodies to true in the k6 options, using
// s3.getObject still receives the underlying response body and returns data to the user.
//
// To achieve this, we set the responseType to 'text' in the baseRequestParams, as it
// will lead the http module to ignore the discardResponseBodies option.
//
// AWS Client classes can override this value if they want to receive the response body
// as a different type ('binary' for instance, e.g. S3Client.getObject).
//
// See #45: https://github.com/grafana/k6-jslib-aws/issues/45
readonly baseRequestParams: Params = {
responseType: 'text',
}

private _endpoint?: Endpoint

/**
Expand Down
1 change: 1 addition & 0 deletions src/internal/event-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class EventBridgeClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, EventBridgeOperation.PutEvents)
Expand Down
1 change: 1 addition & 0 deletions src/internal/kinesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export class KinesisClient extends AWSClient {
)

const res = await http.asyncRequest('POST', signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})

Expand Down
2 changes: 2 additions & 0 deletions src/internal/kms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class KMSClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, KMSOperation.ListKeys)
Expand Down Expand Up @@ -112,6 +113,7 @@ export class KMSClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, KMSOperation.GenerateDataKey)
Expand Down
1 change: 1 addition & 0 deletions src/internal/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class LambdaClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res)
Expand Down
10 changes: 10 additions & 0 deletions src/internal/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'ListBuckets')
Expand Down Expand Up @@ -120,6 +121,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'ListObjectsV2')
Expand Down Expand Up @@ -183,6 +185,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'GetObject')
Expand Down Expand Up @@ -241,6 +244,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'PutObject')
Expand Down Expand Up @@ -270,6 +274,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'DeleteObject')
Expand Down Expand Up @@ -309,6 +314,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})

Expand Down Expand Up @@ -343,6 +349,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'CreateMultipartUpload')
Expand Down Expand Up @@ -393,6 +400,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'UploadPart')
Expand Down Expand Up @@ -443,6 +451,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'CompleteMultipartUpload')
Expand Down Expand Up @@ -477,6 +486,7 @@ export class S3Client extends AWSClient {
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, 'AbortMultipartUpload')
Expand Down
5 changes: 5 additions & 0 deletions src/internal/secrets-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class SecretsManagerClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, SecretsManagerOperation.ListSecrets)
Expand Down Expand Up @@ -100,6 +101,7 @@ export class SecretsManagerClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})

Expand Down Expand Up @@ -160,6 +162,7 @@ export class SecretsManagerClient extends AWSClient {
// headers['X-Amz-Target'] = `${this.serviceName}.CreateSecret`

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, SecretsManagerOperation.CreateSecret)
Expand Down Expand Up @@ -200,6 +203,7 @@ export class SecretsManagerClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, SecretsManagerOperation.PutSecretValue)
Expand Down Expand Up @@ -249,6 +253,7 @@ export class SecretsManagerClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, SecretsManagerOperation.DeleteSecret)
Expand Down
1 change: 1 addition & 0 deletions src/internal/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export class SQSClient extends AWSClient {
)

const res = await http.asyncRequest('POST', signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})

Expand Down
1 change: 1 addition & 0 deletions src/internal/ssm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class SystemsManagerClient extends AWSClient {
)

const res = await http.asyncRequest(this.method, signedRequest.url, signedRequest.body, {
...this.baseRequestParams,
headers: signedRequest.headers,
})
this.handleError(res, SystemsManagerOperation.GetParameter)
Expand Down
Loading