Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 7bc77ca

Browse files
authored
test: Add a metric service client test and ensure universe domain gets used when writing the metrics (#1671)
## Description Adds a test to make sure the universe domain is used when writing metrics. ## Impact Adds a test to ensure metrics are always written to the right place when universe domain is provided. ## Testing Assuming the MetricServiceClient is working properly, this test ensures that universe domain is passed to the metric service client so that metrics will be written to the universe domain endpoint. An even better test would be to set up a project at a different universe domain and check it for metrics after a write to ensure the metrics are actually getting written there, but that setup is a pretty heavy lift. I think the current test gives us enough confidence that the test is working correctly.
1 parent 98c1064 commit 7bc77ca

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

test/metric-service-client-credentials.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ import * as assert from 'assert';
1818
import {MetricServiceClient} from '@google-cloud/monitoring';
1919

2020
describe('Bigtable/MetricServiceClientCredentials', () => {
21-
it('should pass the credentials to the exporter', done => {
21+
it('should pass the credentials and universe domain to the exporter', done => {
2222
const clientOptions = {
2323
metricsEnabled: true,
2424
sslCreds: grpc.credentials.createInsecure(),
25+
universeDomain: 'some-universe-domain.com',
2526
};
2627
class FakeExporter {
2728
constructor(options: ClientOptions) {
@@ -81,4 +82,40 @@ describe('Bigtable/MetricServiceClientCredentials', () => {
8182
const projectIdUsed = await client.getProjectId();
8283
assert.strictEqual(projectIdUsed, SECOND_PROJECT_ID);
8384
});
85+
it('should pass the credentials and universe domain to the metric service client', done => {
86+
const clientOptions = {
87+
metricsEnabled: true,
88+
sslCreds: grpc.credentials.createInsecure(),
89+
universeDomain: 'some-universe-domain.com',
90+
};
91+
class FakeMetricServiceClient {
92+
constructor(options: ClientOptions) {
93+
try {
94+
assert.strictEqual(options, clientOptions);
95+
done();
96+
} catch (e) {
97+
done(e);
98+
}
99+
}
100+
}
101+
const FakeExporter = proxyquire('../src/client-side-metrics/exporter.js', {
102+
'@google-cloud/monitoring': {
103+
MetricServiceClient: FakeMetricServiceClient,
104+
},
105+
}).CloudMonitoringExporter;
106+
const FakeCGPMetricsHandler = proxyquire(
107+
'../src/client-side-metrics/gcp-metrics-handler.js',
108+
{
109+
'./exporter': {
110+
CloudMonitoringExporter: FakeExporter,
111+
},
112+
},
113+
).GCPMetricsHandler;
114+
const FakeBigtable = proxyquire('../src/index.js', {
115+
'./client-side-metrics/gcp-metrics-handler': {
116+
GCPMetricsHandler: FakeCGPMetricsHandler,
117+
},
118+
}).Bigtable;
119+
new FakeBigtable(clientOptions);
120+
});
84121
});

0 commit comments

Comments
 (0)