这是indexloc提供的服务,不要输入任何密码
Skip to content

Delegate createReadStream #1611

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

Draft
wants to merge 440 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
440 commits
Select commit Hold shift + click to select a range
c3f2963
Change tests and json structure to work
danieljbruce Feb 14, 2025
67b6478
Update all the fixtures
danieljbruce Feb 14, 2025
8544410
Fix the view creation code
danieljbruce Feb 19, 2025
96dbc1c
Starting test for gcp-metrics-handler
danieljbruce Feb 19, 2025
416e18c
Put tests in the proper places
danieljbruce Feb 19, 2025
991f5c8
Replace start and end time with more recent values
danieljbruce Feb 19, 2025
09389ee
Utilize the new metrics handler interface
danieljbruce Feb 20, 2025
87d5592
Solve compiler errors resulting from metrics handl
danieljbruce Feb 20, 2025
9ad2ef8
Update the fixture
danieljbruce Feb 20, 2025
c59fcab
rewrite the metric to request method
danieljbruce Feb 20, 2025
5848588
Add interfaces to work with type guards
danieljbruce Feb 21, 2025
9c35dfb
Correct the compile error problems
danieljbruce Feb 21, 2025
07ec90d
Fix expected OTEL output test
danieljbruce Feb 21, 2025
bf54c8c
Remove TODOs
danieljbruce Feb 21, 2025
f226b5f
Fix test to compare pointwise
danieljbruce Feb 21, 2025
b42b4f4
connectivity error count corrections
danieljbruce Feb 21, 2025
54ac764
Correct the fixtures
danieljbruce Feb 21, 2025
eb8f14b
Eliminate tests using the old export input fixture
danieljbruce Feb 21, 2025
6ecb1a6
Add headers
danieljbruce Feb 21, 2025
fa0a56e
run linter
danieljbruce Feb 21, 2025
fcef83d
Modify the gcp-metrics-handler and test the proces
danieljbruce Feb 21, 2025
cd2efac
Remove only
danieljbruce Feb 21, 2025
eba027c
Use a fake projectId
danieljbruce Feb 21, 2025
5929a9d
Only call export once
danieljbruce Feb 21, 2025
3b48c8e
Ensure test suite completes
danieljbruce Feb 21, 2025
8edc4ab
Remove shutdown
danieljbruce Feb 21, 2025
8c9d23f
remove async
danieljbruce Feb 21, 2025
7b49f01
Don’t export the data twice
danieljbruce Feb 21, 2025
2ec12b6
Merge branch 'main' of https://github.com/googleapis/nodejs-bigtable …
danieljbruce Feb 24, 2025
b4f7705
Increase the timeout
danieljbruce Feb 24, 2025
2a32459
Use the PushMetricExporter interface
danieljbruce Feb 24, 2025
e5caa9e
Removed some interfaces that are not used anymore
danieljbruce Feb 24, 2025
fc114ff
Update JSdoc
danieljbruce Feb 24, 2025
6fb5944
Move fake start time and fake end time
danieljbruce Feb 24, 2025
ca6f05e
Remove the TODO
danieljbruce Feb 24, 2025
4bec216
Update documentation
danieljbruce Feb 24, 2025
bd4b0ac
Add additional information to the error reported
danieljbruce Feb 25, 2025
c191614
Move start time and end time
danieljbruce Feb 25, 2025
86be1ea
Try to use timestamps in order
danieljbruce Feb 25, 2025
3b0f081
Reduce timestamp delay
danieljbruce Feb 25, 2025
3ebb9ff
Remove only
danieljbruce Feb 25, 2025
cf32131
Inline addFakeRecentTimestamps
danieljbruce Feb 25, 2025
78a20d4
Move replace timestamps into the only file it
danieljbruce Feb 25, 2025
105b58b
Fix comment
danieljbruce Feb 25, 2025
d4022fd
Rename the metric types
danieljbruce Feb 26, 2025
7ea28d2
Generate documentation for the new classes
danieljbruce Feb 26, 2025
7848643
Add documentation for monitored resource
danieljbruce Feb 26, 2025
7229174
Generate documentation for the other metrics
danieljbruce Feb 26, 2025
7f4e167
Generate documentation for the constructor
danieljbruce Feb 26, 2025
c86196a
Get documentation for replaceTimestamps, fixtures
danieljbruce Feb 26, 2025
41c9b2d
Merge branch 'main' of https://github.com/googleapis/nodejs-bigtable …
danieljbruce Feb 26, 2025
d76fa14
Reduce the interval time
danieljbruce Feb 27, 2025
2f3b4e5
Make view list based on latencies
danieljbruce Feb 27, 2025
7a4b33e
Add a guard for count
danieljbruce Feb 28, 2025
eaf8879
Add a CSM test for Bigtable
danieljbruce Mar 3, 2025
22d25fa
Add handlers to the middleware layer
danieljbruce Mar 3, 2025
a3068bf
Add the metrics to the tabular api surface
danieljbruce Mar 3, 2025
61187ea
Move the tests
danieljbruce Mar 3, 2025
a1276b4
Use the GCPMetricsHandler in the tabular api surface
danieljbruce Mar 3, 2025
d16d3ec
Add a guard in the metrics collector
danieljbruce Mar 5, 2025
874af79
Fix the proxyquire issue
danieljbruce Mar 5, 2025
c000a1c
Export every 60 seconds instead
danieljbruce Mar 5, 2025
9f28d3e
Add a guard to the metadata collector
danieljbruce Mar 5, 2025
8cc0757
Add a guard to the export function
danieljbruce Mar 5, 2025
88e0527
Make sure to await to avoid a race condition
danieljbruce Mar 5, 2025
d6d409e
Adjust headers
danieljbruce Mar 5, 2025
6b99e09
Add the right assertions for the TestMetricsHandle
danieljbruce Mar 6, 2025
f4cb545
Send the project id to the mock
danieljbruce Mar 6, 2025
5a09c33
Invert the for and if
danieljbruce Mar 6, 2025
aa18c1e
Pull all attributes out
danieljbruce Mar 6, 2025
791e70d
Eliminate the need for the type guard
danieljbruce Mar 6, 2025
2e21503
Eliminate the data points interface
danieljbruce Mar 6, 2025
e936aaa
only
danieljbruce Mar 6, 2025
ab07a58
Revert "Eliminate the need for the type guard"
danieljbruce Mar 6, 2025
7fe9a46
Pull timeseries into one variable
danieljbruce Mar 6, 2025
26b9ca7
Eliminate an unused import
danieljbruce Mar 6, 2025
29ef6b0
Add a comment that explains the usefulness
danieljbruce Mar 6, 2025
8fd59f4
Remove the gce instance setting
danieljbruce Mar 6, 2025
183bdb7
Eliminate the gcp cloud provider setting
danieljbruce Mar 6, 2025
92059aa
run all tests
danieljbruce Mar 6, 2025
af3aa73
Eliminate duplicate project id from monitored
danieljbruce Mar 6, 2025
422060e
Change the two metric names
danieljbruce Mar 6, 2025
f93a721
Extend the timeout so that the exporter has
danieljbruce Mar 7, 2025
ea230aa
Use spread syntax
danieljbruce Mar 7, 2025
5ecfb70
Changed metric to otel instruments
danieljbruce Mar 7, 2025
303c57c
Remove optional on Otel instruments
danieljbruce Mar 7, 2025
a822961
Rename initialize to getMetrics
danieljbruce Mar 7, 2025
31fe184
Pin promisify to version 4
danieljbruce Mar 7, 2025
30152d6
cast to string - compiler errors
danieljbruce Mar 7, 2025
ccaaa07
Cast to string when building buffer
danieljbruce Mar 13, 2025
236c42a
Remove a TODO - it is done
danieljbruce Mar 13, 2025
6c28f25
Delete the test that writes to metrics collected
danieljbruce Mar 13, 2025
59f9c51
eliminate unnecessary spacing
danieljbruce Mar 13, 2025
ef322d5
Remove console logs from the code
danieljbruce Mar 13, 2025
b17680c
Eliminate the TODO in index
danieljbruce Mar 13, 2025
c587722
Add comment to mention mocha
danieljbruce Mar 13, 2025
f00993c
Add another comment for code 0
danieljbruce Mar 13, 2025
8f61f4b
Add a comment clarifying what the test does
danieljbruce Mar 13, 2025
4fb25eb
Pin promisify to solve the linting issues
danieljbruce Mar 13, 2025
5fafe96
Rename test to ClientSideMetricsToMetricsHandler
danieljbruce Mar 13, 2025
68c2a1a
Rename another test suite
danieljbruce Mar 13, 2025
1a2ace7
Remove these console logs
danieljbruce Mar 13, 2025
886f999
Add guards to the after hooks on this test
danieljbruce Mar 13, 2025
bb3b177
Remove only
danieljbruce Mar 13, 2025
c3d918c
Increase the GCPMetricsHandler time
danieljbruce Mar 13, 2025
99c6271
Fix samples test issue
danieljbruce Mar 13, 2025
3843e7b
Add a comment to test that works with the mock ser
danieljbruce Mar 13, 2025
05787e5
Revert "Fix samples test issue"
danieljbruce Mar 13, 2025
78550a8
Increase the timeout
danieljbruce Mar 13, 2025
ee022ce
Catch failures to load ResponseParams
danieljbruce Mar 13, 2025
9584c69
Change the latency buckets
danieljbruce Mar 13, 2025
082c049
Updated the resultCallback comment
danieljbruce Mar 13, 2025
f2e46a4
Change the test description
danieljbruce Mar 14, 2025
dfcf56e
Add a comment explaining what the test is about
danieljbruce Mar 14, 2025
35da5c6
Completed the test for two metrics handlers
danieljbruce Mar 14, 2025
b5ae964
remove only
danieljbruce Mar 14, 2025
b575010
Cast as histogram to make compile error go away
danieljbruce Mar 14, 2025
822c14e
Move the duplicate copies of replaceTimestamps
danieljbruce Mar 14, 2025
561889c
Take steps to eliminate the ExportInput interface
danieljbruce Mar 14, 2025
f423c57
Add a header
danieljbruce Mar 14, 2025
9076be1
Remove only
danieljbruce Mar 14, 2025
ead3f5e
Eliminate ExportInput and dependencies
danieljbruce Mar 14, 2025
fa6c3fd
Eliminate constant
danieljbruce Mar 14, 2025
a587d0c
Push conversion to status back to metrics collect
danieljbruce Mar 14, 2025
311d555
Change property names to match MetricServiceClient
danieljbruce Mar 14, 2025
117473b
Solve the app_profile_id issue
danieljbruce Mar 14, 2025
e4154af
It is actually app_profile not app_profile_id
danieljbruce Mar 14, 2025
0ccec5b
Add guards that stop the export call
danieljbruce Mar 17, 2025
9f94b9e
Remove only
danieljbruce Mar 17, 2025
7e76c39
Add a new test for ten metrics handlers
danieljbruce Mar 17, 2025
bb64fbe
Remove only
danieljbruce Mar 17, 2025
27f5bcd
Do not pass data through the Resource object
danieljbruce Mar 17, 2025
d1a292f
Add a test for writing duplicate points to MH
danieljbruce Mar 17, 2025
23a4d39
Eliminate interface
danieljbruce Mar 17, 2025
55dbd8f
Set connectivity error count to 1 (not increment)
danieljbruce Mar 17, 2025
69abb9a
Merge branch '359913994-exporter-PR' of https://github.com/googleapis…
danieljbruce Mar 17, 2025
71b2d48
Edit the fixtures
danieljbruce Mar 17, 2025
c581129
Remove the guard
danieljbruce Mar 20, 2025
ba04208
Change attempt status to string
danieljbruce Mar 20, 2025
9c3e5b1
Add a comment - undefined in conformance tests
danieljbruce Mar 20, 2025
ab4545e
Make metrics handlers per client
danieljbruce Mar 21, 2025
2d23a83
Add coment about latency
danieljbruce Mar 21, 2025
efa147d
Wrap in try
danieljbruce Mar 21, 2025
5761892
Adjust the proxyquire mocks to mock handler in
danieljbruce Mar 21, 2025
333c5b9
Eliminate TODO
danieljbruce Mar 21, 2025
3b71eff
Eliminate TODO
danieljbruce Mar 21, 2025
5f67eef
Merge branch 'main' of https://github.com/googleapis/nodejs-bigtable …
danieljbruce Mar 24, 2025
4ab9084
Add some code so that first response latencies gets recorded
danieljbruce Mar 27, 2025
7daeb0f
Run the linter
danieljbruce Mar 27, 2025
25ab7c4
Reduce latency when collect metrics is false
danieljbruce Mar 27, 2025
fb8251c
Add a comment for the collect metrics variable
danieljbruce Mar 28, 2025
e2a11be
Remove unnecessary deltas
danieljbruce Mar 28, 2025
3e1b9e0
Add space back
danieljbruce Mar 28, 2025
3053809
Remove numRequests made increment
danieljbruce Mar 28, 2025
5022a37
Check for existence of metrics
danieljbruce Mar 28, 2025
8c9fd29
Finalize updates to do the test with 2 tables
danieljbruce Mar 28, 2025
558b091
Refactor the test setup into one file
danieljbruce Mar 28, 2025
5b79114
Use the new setup table function
danieljbruce Mar 28, 2025
0a5c598
Remove only handlers
danieljbruce Mar 28, 2025
bd3f76c
Add header
danieljbruce Mar 28, 2025
af44069
Add guard in the metrics collector
danieljbruce Mar 28, 2025
85fcca4
Revert "Remove the guard"
danieljbruce Mar 28, 2025
f2d16bd
Add the optimizations back again
danieljbruce Mar 28, 2025
873507a
cache cluster and zone so a call with 2 tables
danieljbruce Mar 31, 2025
ccbf8b7
Properly set up the table
danieljbruce Mar 31, 2025
256d1e5
Revert "cache cluster and zone so a call with 2 tables"
danieljbruce Mar 31, 2025
19cb1c4
Update the test setup
danieljbruce Mar 31, 2025
90ec71c
Test for multiple instances
danieljbruce Mar 31, 2025
c94244d
Adapt the test to work with multiple clients
danieljbruce Mar 31, 2025
cb77f93
Remove only
danieljbruce Mar 31, 2025
c58ceb4
Modification to handle no status
danieljbruce Mar 31, 2025
b93e5ba
Increment number of exports
danieljbruce Mar 31, 2025
d05bbba
Add an error for the timeouts
danieljbruce Mar 31, 2025
01f0515
Add a test for multiple simultaneous exports
danieljbruce Mar 31, 2025
00385da
Just test for one bigtable client right now
danieljbruce Mar 31, 2025
aad9fc0
Name test differently so that we can distinguish
danieljbruce Mar 31, 2025
1356ac5
Clarify test responsibilities
danieljbruce Mar 31, 2025
df8249e
Eliminate variable assignment
danieljbruce Mar 31, 2025
92a3966
Add a waiting script to the instance creation
danieljbruce Mar 31, 2025
0b08b05
Add the header and combine the tests
danieljbruce Mar 31, 2025
debede7
Remove only
danieljbruce Mar 31, 2025
53febe9
Delete files that have been consolidated
danieljbruce Mar 31, 2025
53e5936
Run the linter and add guards
danieljbruce Mar 31, 2025
6d9551c
Remove response params
danieljbruce Apr 1, 2025
e243c11
Revert "Remove response params"
danieljbruce Apr 2, 2025
0164f55
Remove the samples test workaround
danieljbruce Apr 9, 2025
795cccf
Add a wrapper for the try/catch logic
danieljbruce Apr 9, 2025
75f5d60
Revert "Remove the samples test workaround"
danieljbruce Apr 9, 2025
ff63f4b
Spelling correction
danieljbruce Apr 9, 2025
5a07489
Add a helper method for checking the state
danieljbruce Apr 9, 2025
d21bef0
this.state
danieljbruce Apr 9, 2025
9163d7a
Optional statuses
danieljbruce Apr 9, 2025
da9eb8e
Eliminate old comments
danieljbruce Apr 9, 2025
ae10660
Add a generateClientUuid function
danieljbruce Apr 9, 2025
6318dcc
Changed the name to metrics enabled
danieljbruce Apr 9, 2025
fa8b502
End call on ignored status code
danieljbruce Apr 9, 2025
484e4b6
eliminate mention of gemini
danieljbruce Apr 9, 2025
716681a
Add onOperationSucceeded helper
danieljbruce Apr 9, 2025
9dbeb34
Change name to last attempt completed
danieljbruce Apr 9, 2025
2e342d0
Use onLastAttemptCompleted here
danieljbruce Apr 9, 2025
530c9bd
run linter
danieljbruce Apr 9, 2025
81509cd
Add handlers no matter what
danieljbruce Apr 9, 2025
f198a4d
Add warning if check fails
danieljbruce Apr 9, 2025
f204404
Add console warns for various checks
danieljbruce Apr 10, 2025
7d459a4
Remove the try block
danieljbruce Apr 11, 2025
914a081
Modified comment
danieljbruce Apr 11, 2025
16a2134
Modified export comment
danieljbruce Apr 11, 2025
b6b1c80
Merge branch 'main' of https://github.com/googleapis/nodejs-bigtable …
danieljbruce Apr 11, 2025
7a2d5d0
Make the metrics handler static on the MC
danieljbruce Apr 11, 2025
2ec1694
Throw an error for better testing
danieljbruce Apr 11, 2025
228edcb
Add a helper for adding handlers
danieljbruce Apr 11, 2025
1ddaa7d
Directionally correct proxyquire stuff
danieljbruce Apr 11, 2025
f33f69f
Remove traces and various comments
danieljbruce Apr 11, 2025
e5eb375
Set instance name
danieljbruce Apr 11, 2025
1f830a7
Factor out the fake bigtable creator
danieljbruce Apr 11, 2025
cc32a4c
Remove only
danieljbruce Apr 11, 2025
61750d6
Eliminate onLastAttemptCompleted
danieljbruce Apr 11, 2025
67f9050
eliminate environment variable setting
danieljbruce Apr 11, 2025
cc47f99
thread projectId through test framework
danieljbruce Apr 14, 2025
599eded
Add error handling
danieljbruce Apr 14, 2025
4e32c5d
Test with different project
danieljbruce Apr 14, 2025
cf1ec77
Localize the MetricServiceClient
danieljbruce Apr 16, 2025
cef3dad
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Apr 16, 2025
b2c8f51
remove callback on checkState
danieljbruce Apr 16, 2025
ce79cb1
Throw instead of console.warn
danieljbruce Apr 16, 2025
fe0efa5
Merge branch '359913994-third-PR-CSM' of https://github.com/googleapi…
danieljbruce Apr 16, 2025
6ac0dfb
Use the hrtime module instead of the Date module
danieljbruce Apr 10, 2025
d13b3df
Merge branch 'main' of https://github.com/googleapis/nodejs-bigtable …
danieljbruce Apr 17, 2025
e1063e6
run the linter
danieljbruce Apr 17, 2025
07cee60
Fix failing tests
danieljbruce Apr 17, 2025
2aff9a2
Add promise catching
danieljbruce Apr 17, 2025
6d97723
Remove unused imports
danieljbruce Apr 17, 2025
5ec6275
Remove unused import
danieljbruce Apr 17, 2025
1bb9634
Use the path module
danieljbruce Apr 17, 2025
8fb0c64
Merge branch 'main' of https://github.com/googleapis/nodejs-bigtable …
danieljbruce Apr 28, 2025
03b8d11
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Apr 28, 2025
55c068c
Delete application latencies from the check
danieljbruce Apr 29, 2025
05cfa20
Get rid of bigtable singleton
danieljbruce Apr 29, 2025
0088ab8
Merge branch 'main' into 359913994-third-PR-CSM
danieljbruce Apr 30, 2025
671011b
fix: Get rid of the global singletons thereby improving client side m…
danieljbruce May 27, 2025
a79dfb6
Add warnings
danieljbruce May 28, 2025
cd25919
private readonly variable
danieljbruce May 28, 2025
3b7099e
Add default zone and cluster ids
danieljbruce May 28, 2025
3add0be
Merge branch 'main' of https://github.com/googleapis/nodejs-bigtable …
danieljbruce May 28, 2025
81d55f5
Add a test for second project id
danieljbruce May 28, 2025
8757a65
Better naming conventions for project
danieljbruce May 29, 2025
266e65e
don’t retry MSC, warning
danieljbruce May 29, 2025
b394dcd
Change to unspecified
danieljbruce May 29, 2025
910ea86
Remove unused method
danieljbruce May 29, 2025
00b467f
Delegate createReadStream
danieljbruce May 30, 2025
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
21 changes: 0 additions & 21 deletions protos/protos.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 7 additions & 42 deletions protos/protos.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 18 additions & 42 deletions src/client-side-metrics/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
Histogram,
ResourceMetrics,
} from '@opentelemetry/sdk-metrics';
import {grpc, ServiceError} from 'google-gax';
import {grpc, ClientOptions, ServiceError} from 'google-gax';

Check warning on line 22 in src/client-side-metrics/exporter.ts

View workflow job for this annotation

GitHub Actions / lint

'grpc' is defined but never used
import {MetricServiceClient} from '@google-cloud/monitoring';
import {google} from '@google-cloud/monitoring/build/protos/protos';
import ICreateTimeSeriesRequest = google.monitoring.v3.ICreateTimeSeriesRequest;
import {RetryOptions} from 'google-gax';

Check warning on line 26 in src/client-side-metrics/exporter.ts

View workflow job for this annotation

GitHub Actions / lint

'RetryOptions' is defined but never used

export interface ExportResult {
code: number;
Expand Down Expand Up @@ -119,7 +119,7 @@
* getResource gets the resource object which is used for building the timeseries
* object that will be sent to Google Cloud Monitoring dashboard
*
* @param {string} metricName The backend name of the metric that we want to record
* @param {string} projectId The name of the project
* @param {DataPoint} dataPoint The datapoint containing the data we wish to
* send to the Google Cloud Monitoring dashboard
*/
Expand Down Expand Up @@ -184,6 +184,7 @@
* metric attributes, data points, and aggregation information, into an object
* that conforms to the expected request format of the Cloud Monitoring API.
*
* @param projectId
* @param {ResourceMetrics} exportArgs - The OpenTelemetry metrics data to be converted. This
* object contains resource attributes, scope information, and a list of
* metrics with their associated data points.
Expand Down Expand Up @@ -211,14 +212,10 @@
*
*
*/
export function metricsToRequest(exportArgs: ResourceMetrics) {
type WithSyncAttributes = {_syncAttributes: {[index: string]: string}};
const resourcesWithSyncAttributes =
exportArgs.resource as unknown as WithSyncAttributes;
const projectId =
resourcesWithSyncAttributes._syncAttributes[
'monitored_resource.project_id'
];
export function metricsToRequest(
projectId: string,
exportArgs: ResourceMetrics,
) {
const timeSeriesArray = [];
for (const scopeMetrics of exportArgs.scopeMetrics) {
for (const scopeMetric of scopeMetrics.metrics) {
Expand Down Expand Up @@ -297,43 +294,22 @@
* @beta
*/
export class CloudMonitoringExporter extends MetricExporter {
private monitoringClient = new MetricServiceClient();
private client: MetricServiceClient;

export(
constructor(options: ClientOptions) {
super();
this.client = new MetricServiceClient(options);
}

async export(
metrics: ResourceMetrics,
resultCallback: (result: ExportResult) => void,
): void {
): Promise<void> {
(async () => {
try {
const request = metricsToRequest(metrics);
// In order to manage the "One or more points were written more
// frequently than the maximum sampling period configured for the
// metric." error we should have the metric service client retry a few
// times to ensure the metrics do get written.
//
// We use all the usual retry codes plus INVALID_ARGUMENT (code 3)
// because INVALID ARGUMENT (code 3) corresponds to the maximum
// sampling error.
const retry = new RetryOptions(
[
grpc.status.INVALID_ARGUMENT,
grpc.status.DEADLINE_EXCEEDED,
grpc.status.RESOURCE_EXHAUSTED,
grpc.status.ABORTED,
grpc.status.UNAVAILABLE,
],
{
initialRetryDelayMillis: 5000,
retryDelayMultiplier: 2,
maxRetryDelayMillis: 50000,
},
);
await this.monitoringClient.createTimeSeries(
request as ICreateTimeSeriesRequest,
{
retry,
},
);
const projectId = await this.client.getProjectId();
const request = metricsToRequest(projectId, metrics);
await this.client.createTimeSeries(request as ICreateTimeSeriesRequest);
// The resultCallback typically accepts a value equal to {code: x}
// for some value x along with other info. When the code is equal to 0
// then the operation completed successfully. When the code is not equal
Expand Down
52 changes: 14 additions & 38 deletions src/client-side-metrics/gcp-metrics-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {CloudMonitoringExporter} from './exporter';
import {
IMetricsHandler,
OnAttemptCompleteData,
Expand All @@ -20,6 +21,8 @@ import {
import * as Resources from '@opentelemetry/resources';
import * as ResourceUtil from '@google-cloud/opentelemetry-resource-util';
import {PushMetricExporter, View} from '@opentelemetry/sdk-metrics';
import {ClientOptions} from 'google-gax';
import {generateClientUuid} from './generate-client-uuid';
const {
Aggregation,
ExplicitBucketHistogramAggregation,
Expand Down Expand Up @@ -47,10 +50,9 @@ interface MetricsInstruments {
* This method gets the open telemetry instruments that will store GCP metrics
* for a particular project.
*
* @param projectId The project for which the instruments will be stored.
* @param exporter The exporter the metrics will be sent to.
*/
function createInstruments(projectId: string, exporter: PushMetricExporter) {
function createInstruments(exporter: PushMetricExporter): MetricsInstruments {
const latencyBuckets = [
0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0,
40.0, 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0,
Expand Down Expand Up @@ -80,7 +82,6 @@ function createInstruments(projectId: string, exporter: PushMetricExporter) {
views: viewList,
resource: new Resources.Resource({
'service.name': 'Cloud Bigtable Table',
'monitored_resource.project_id': projectId,
}).merge(new ResourceUtil.GcpDetectorSync().detect()),
readers: [
// Register the exporter
Expand Down Expand Up @@ -183,11 +184,8 @@ function createInstruments(projectId: string, exporter: PushMetricExporter) {
* associating them with relevant attributes for detailed analysis in Cloud Monitoring.
*/
export class GCPMetricsHandler implements IMetricsHandler {
private exporter: PushMetricExporter;
// The variable below is the singleton map from projects to instrument stacks
// which exists so that we only create one instrument stack per project. This
// will eliminate errors due to the maximum sampling period.
static instrumentsForProject: {[projectId: string]: MetricsInstruments} = {};
private otelInstruments: MetricsInstruments;
private clientUid: string;

/**
* The `GCPMetricsHandler` is responsible for managing and recording
Expand All @@ -196,33 +194,11 @@ export class GCPMetricsHandler implements IMetricsHandler {
* (histograms and counters) and exports them to Google Cloud Monitoring
* through the provided `PushMetricExporter`.
*
* @param exporter - The `PushMetricExporter` instance to use for exporting
* metrics to Google Cloud Monitoring. This exporter is responsible for
* sending the collected metrics data to the monitoring backend. The provided exporter must be fully configured, for example the projectId must have been set.
*/
constructor(exporter: PushMetricExporter) {
this.exporter = exporter;
}

/**
* Initializes the OpenTelemetry metrics instruments if they haven't been already.
* Creates and registers metric instruments (histograms and counters) for various Bigtable client metrics.
* Sets up a MeterProvider and configures a PeriodicExportingMetricReader for exporting metrics to Cloud Monitoring.
*
* which will be provided to the exporter in every export call.
*
*/
private getInstruments(projectId: string): MetricsInstruments {
// The projectId is needed per metrics handler because when the exporter is
// used it provides the project id for the name of the time series exported.
// ie. name: `projects/${....['monitored_resource.project_id']}`,
if (!GCPMetricsHandler.instrumentsForProject[projectId]) {
GCPMetricsHandler.instrumentsForProject[projectId] = createInstruments(
projectId,
this.exporter,
);
}
return GCPMetricsHandler.instrumentsForProject[projectId];
constructor(options: ClientOptions) {
this.clientUid = generateClientUuid();
const exporter = new CloudMonitoringExporter(options);
this.otelInstruments = createInstruments(exporter);
}

/**
Expand All @@ -231,11 +207,11 @@ export class GCPMetricsHandler implements IMetricsHandler {
* @param {OnOperationCompleteData} data Data related to the completed operation.
*/
onOperationComplete(data: OnOperationCompleteData) {
const otelInstruments = this.getInstruments(data.projectId);
const otelInstruments = this.otelInstruments;
const commonAttributes = {
app_profile: data.metricsCollectorData.app_profile,
method: data.metricsCollectorData.method,
client_uid: data.metricsCollectorData.client_uid,
client_uid: this.clientUid,
client_name: data.client_name,
instanceId: data.metricsCollectorData.instanceId,
table: data.metricsCollectorData.table,
Expand Down Expand Up @@ -271,11 +247,11 @@ export class GCPMetricsHandler implements IMetricsHandler {
* @param {OnAttemptCompleteData} data Data related to the completed attempt.
*/
onAttemptComplete(data: OnAttemptCompleteData) {
const otelInstruments = this.getInstruments(data.projectId);
const otelInstruments = this.otelInstruments;
const commonAttributes = {
app_profile: data.metricsCollectorData.app_profile,
method: data.metricsCollectorData.method,
client_uid: data.metricsCollectorData.client_uid,
client_uid: this.clientUid,
status: data.status,
client_name: data.client_name,
instanceId: data.metricsCollectorData.instanceId,
Expand Down
Loading
Loading