in projects/alloydb-autoscaler/src/alloydb-autoscaler/poller/alloydb-metadata-reader.ts [38:90]
async getMetadata(): Promise<MetadataValueMap> {
this.logger.info({
message: `----- ${this.instance.info.resourcePath}: Metadata -----`,
});
const response = await this.alloyDbClient.getInstance({
name: this.instance.info.resourcePath,
});
if (!response || !Array.isArray(response)) {
throw new Error(
'Unable to read metadata from AlloyDB instance ' +
this.instance.info.resourcePath
);
}
const [instance] = response;
if (!instance) {
throw new Error(
'Unable to read metadata from AlloyDB instance ' +
this.instance.info.resourcePath
);
}
const instanceType = instance?.instanceType;
const nodeCount = instance?.readPoolConfig?.nodeCount;
const cpuCount = instance?.machineConfig?.cpuCount;
this.logger.debug({message: `instanceType: ${instanceType}`});
this.logger.debug({message: `nodeCount: ${nodeCount}`});
this.logger.debug({message: `cpuCount: ${cpuCount}`});
if (instanceType !== 'READ_POOL') {
throw new Error(
'Only AlloyDB read pool instances are currently supported. ' +
`Instance ${this.instance.info.resourcePath} is of type ` +
instanceType
);
}
if (!nodeCount) {
throw new Error(
'Unable to read current node count for AlloyDB instance ' +
this.instance.info.resourcePath
);
}
return {
currentSize: nodeCount,
nodeCount: nodeCount,
cpuCount: cpuCount ?? 0,
instanceType: instance.instanceType ?? '',
};
}