-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat: Managed Autoscaler #1965
Closed
Closed
feat: Managed Autoscaler #1965
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
119ae60
feat: add code changes for managed autoscaler
alkatrivedi 6f85a41
Merge branch 'main' into managed-autoscaler
harshachinta ac79780
Merge branch 'main' into managed-autoscaler
surbhigarg92 6f0bd47
Merge branch 'googleapis:main' into managed-autoscaler
alkatrivedi ba35662
Merge branch 'googleapis:main' into managed-autoscaler
alkatrivedi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright 2023 Google LLC | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// [START spanner_create_instance_with_autoscaling_config] | ||
|
||
'use strict'; | ||
|
||
async function createInstanceWithAutoscalingConfig(instanceId, projectId) { | ||
// Imports the Google Cloud client library | ||
const {Spanner, protos} = require('@google-cloud/spanner'); | ||
|
||
// Creates a client | ||
const spanner = new Spanner({ | ||
projectId: projectId, | ||
}); | ||
|
||
const instance = spanner.instance(instanceId); | ||
const autoscalingConfig = | ||
protos.google.spanner.admin.instance.v1.AutoscalingConfig.create({ | ||
// Only one of minNodes/maxNodes or minProcessingUnits/maxProcessingUnits | ||
// can be set. Both min and max need to be set and | ||
// maxNodes/maxProcessingUnits can be at most 10X of | ||
// minNodes/minProcessingUnits. | ||
autoscalingLimits: | ||
protos.google.spanner.admin.instance.v1.AutoscalingConfig.AutoscalingLimits.create( | ||
{ | ||
minNodes: 1, | ||
maxNodes: 2, | ||
} | ||
), | ||
// highPriorityCpuUtilizationPercent and storageUtilizationPercent are both | ||
// percentages and must lie between 0 and 100. | ||
autoscalingTargets: | ||
protos.google.spanner.admin.instance.v1.AutoscalingConfig.AutoscalingTargets.create( | ||
{ | ||
highPriorityCpuUtilizationPercent: 65, | ||
storageUtilizationPercent: 95, | ||
} | ||
), | ||
}); | ||
// Creates a new instance with autoscalingConfig | ||
try { | ||
console.log(`Creating instance ${instance.formattedName_}.`); | ||
const [, operation] = await instance.create({ | ||
config: 'regional-us-west1', | ||
autoscalingConfig: autoscalingConfig, | ||
displayName: 'This is a display name.', | ||
labels: { | ||
['cloud_spanner_samples']: 'true', | ||
}, | ||
}); | ||
|
||
console.log(`Waiting for operation on ${instance.id} to complete...`); | ||
await operation.promise(); | ||
|
||
console.log(`Created instance ${instanceId}.`); | ||
|
||
const [metadata] = await instance.getMetadata({ | ||
fieldNames: ['autoscalingConfig'], | ||
}); | ||
console.log( | ||
`Autoscaling configurations of ${instanceId} are: ` + | ||
'\n' + | ||
`Min nodes: ${metadata.autoscalingConfig.autoscalingLimits.minNodes} ` + | ||
'nodes.' + | ||
'\n' + | ||
`Max nodes: ${metadata.autoscalingConfig.autoscalingLimits.maxNodes}` + | ||
' nodes.' + | ||
'\n' + | ||
`High priority cpu utilization percent: ${metadata.autoscalingConfig.autoscalingTargets.highPriorityCpuUtilizationPercent}.` + | ||
'\n' + | ||
`Storage utilization percent: ${metadata.autoscalingConfig.autoscalingTargets.storageUtilizationPercent}.` | ||
); | ||
} catch (err) { | ||
console.error('ERROR:', err); | ||
} | ||
} | ||
|
||
// [END spanner_create_instance_with_autoscaling_config] | ||
module.exports.createInstanceWithAutoscalingConfig = | ||
createInstanceWithAutoscalingConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,7 @@ export interface CreateInstanceRequest { | |
config?: string; | ||
nodes?: number; | ||
processingUnits?: number; | ||
autoscalingConfig?: google.spanner.admin.instance.v1.IAutoscalingConfig; | ||
displayName?: string; | ||
labels?: {[k: string]: string} | null; | ||
gaxOptions?: CallOptions; | ||
|
@@ -481,17 +482,21 @@ class Spanner extends GrpcService { | |
displayName, | ||
nodeCount: config.nodes, | ||
processingUnits: config.processingUnits, | ||
autoscalingConfig: config.autoscalingConfig, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to do changes for Update Instance to handle below use case |
||
}, | ||
config | ||
), | ||
}; | ||
|
||
if (reqOpts.instance.nodeCount && reqOpts.instance.processingUnits) { | ||
throw new GoogleError( | ||
['Only one of nodeCount or processingUnits can be specified.'].join('') | ||
); | ||
} | ||
if (!reqOpts.instance.nodeCount && !reqOpts.instance.processingUnits) { | ||
if ( | ||
!reqOpts.instance.nodeCount && | ||
!reqOpts.instance.processingUnits && | ||
!reqOpts.instance.autoscalingConfig | ||
) { | ||
// If neither nodes nor processingUnits are specified, default to a | ||
// nodeCount of 1. | ||
reqOpts.instance.nodeCount = 1; | ||
|
@@ -503,6 +508,7 @@ class Spanner extends GrpcService { | |
if (config.config!.indexOf('/') === -1) { | ||
reqOpts.instance.config = `projects/${this.projectId}/instanceConfigs/${config.config}`; | ||
} | ||
|
||
this.request( | ||
{ | ||
client: 'InstanceAdminClient', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.