feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Logging metrics group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
class Metrics(base.Group):
"""Manages logs-based metrics."""
category = base.MANAGEMENT_TOOLS_CATEGORY

View File

@@ -0,0 +1,114 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 Google LLC. All Rights Reserved.
#
# 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.
"""'logging metrics create' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
DETAILED_HELP = {
'DESCRIPTION':
"""\
Create a logs-based metric to count the number of log entries that
match a filter expression. Logs-based metrics can also be used to
extract values from logs and create a distribution of the values.
""",
'EXAMPLES':
"""\
To create a metric that counts the number of log entries with a
severity level higher than WARNING, run:
$ {command} high_severity_count --description="Number of high severity log entries" --log-filter="severity > WARNING"
Detailed information about filters can be found at:
[](https://cloud.google.com/logging/docs/view/logging-query-language)
To create a metric that uses advanced features like distribution or
user-defined labels, run:
$ {command} my_metric --config-from-file=$PATH_TO_FILE
The config file can be in YAML or JSON format. Detailed information
about how to configure metrics can be found at: [](https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics#LogMetric).
To create a bucket log-based metric, run:
$ {command} my_bucket_metric --description="DESCRIPTION" --log-filter="LOG_FILTER" --bucket-name="BUCKET_NAME"
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Create(base.CreateCommand):
"""Create a logs-based metric."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument('metric_name', help='The name of the new metric.')
config_group = parser.add_argument_group(help='Data about the new metric.',
mutex=True,
required=True
)
legacy_mode_group = config_group.add_argument_group(
help=('A group of arguments to specify simple counter logs-based '
'metrics. '))
legacy_mode_group.add_argument(
'--description', required=True,
help='The metric\'s description.')
legacy_mode_group.add_argument(
'--log-filter', required=True,
help='The metric\'s filter expression.')
legacy_mode_group.add_argument(
'--bucket-name',
help='The Log Bucket name which owns the log-based metric.')
config_group.add_argument('--config-from-file',
help=('A path to a YAML or JSON file specifying '
'the logs-based metric to create.'),
type=arg_parsers.FileContents())
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
The created metric.
"""
messages = util.GetMessages()
new_metric = util.CreateLogMetric(
metric_name=args.metric_name,
description=args.description,
log_filter=args.log_filter,
bucket_name=args.bucket_name,
data=args.config_from_file)
request = messages.LoggingProjectsMetricsCreateRequest(
parent=util.GetCurrentProjectParent(), logMetric=new_metric)
result = util.GetClient().projects_metrics.Create(request)
log.CreatedResource(args.metric_name)
return result
Create.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 Google LLC. All Rights Reserved.
#
# 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.
"""'logging metrics delete' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Delete a logs-based metric."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument(
'metric_name', help='The name of the metric to delete.')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
"""
console_io.PromptContinue(
'Really delete metric [%s]?' % args.metric_name, cancel_on_no=True)
util.GetClient().projects_metrics.Delete(
util.GetMessages().LoggingProjectsMetricsDeleteRequest(
metricName=util.CreateResourceName(
util.GetCurrentProjectParent(), 'metrics', args.metric_name)))
log.DeletedResource(args.metric_name)
Delete.detailed_help = {
'DESCRIPTION': """\
Delete a logs-based metric called high_severity_count.
""",
'EXAMPLES': """\
To delete a metric called high_severity_count, run:
$ {command} high_severity_count
""",
}

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 Google LLC. All Rights Reserved.
#
# 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.
"""'logging metrics describe' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import base
class Describe(base.DescribeCommand):
"""Display the definition of a logs-based metric."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument(
'metric_name', help='The name of the metric.')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
The specified metric with its description and configured filter.
"""
return util.GetClient().projects_metrics.Get(
util.GetMessages().LoggingProjectsMetricsGetRequest(
metricName=util.CreateResourceName(
util.GetCurrentProjectParent(), 'metrics', args.metric_name)))
Describe.detailed_help = {
'DESCRIPTION': """\
Show the definition of a logs-based metric.
""",
'EXAMPLES': """\
To show the definition of a metric called high_severity_count, run:
$ {command} high_severity_count
""",
}

View File

@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 Google LLC. All Rights Reserved.
#
# 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.
"""'logging metrics list' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA)
class ListGA(base.ListCommand):
"""Display all logs-based metrics."""
detailed_help = {
'DESCRIPTION': """\
List all logs-based metrics.
""",
'EXAMPLES': """\
To list the top 10 logs-based metrics, run:
$ {command} --limit=10
""",
}
@staticmethod
def Args(parser):
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
parser.display_info.AddFormat('table(name, description, filter)')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
The list of metrics.
"""
request = util.GetMessages().LoggingProjectsMetricsListRequest(
parent=util.GetCurrentProjectParent())
return list_pager.YieldFromList(
util.GetClient().projects_metrics, request, field='metrics',
limit=args.limit, batch_size=None, batch_size_attribute='pageSize')
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class ListBeta(ListGA):
"""Display all logs-based metrics."""
detailed_help = {
'DESCRIPTION': """\
Lists all logs-based metrics.
""",
'EXAMPLES': """\
To list up to 10 logs-based metrics, run:
$ {command} --limit=10
To view as a simple table with just the name, description, and filter
fields, run:
$ {command} --format="table(name, description, filter)"
""",
}
@staticmethod
def Args(parser):
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
parser.display_info.AddFormat('yaml')

View File

@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 Google LLC. All Rights Reserved.
#
# 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.
"""'logging metrics update' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
DETAILED_HELP = {
'DESCRIPTION':
"""\
Update the description or the filter expression of an existing
logs-based metric.
""",
'EXAMPLES':
"""\
To update the description of a metric called high_severity_count, run:
$ {command} high_severity_count --description="Count of high-severity log entries."
To update the filter expression of the metric, run:
$ {command} high_severity_count --log-filter="severity >= WARNING"
Detailed information about filters can be found at:
[](https://cloud.google.com/logging/docs/view/logging-query-language)
For advanced features such as user-defined labels and distribution
metrics, update using a config file:
$ {command} high_severity_count --config-from-file=$PATH_TO_FILE
The config file should be in YAML format. Detailed information about
how to configure metrics can be found at: [](https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics#LogMetric).
Any top-level fields in the LogMetric definition that aren't specified
in the config file will not be updated in the metric.
To update the bucket associated with a bucket log-based metric, run:
$ {command} my-bucket-metric --bucket-name="NEW_BUCKET_NAME"
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Update(base.UpdateCommand):
"""Update the definition of a logs-based metric."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.add_argument(
'metric_name', help='The name of the log-based metric to update.')
config_group = parser.add_argument_group(
help='Data about the metric to update.', mutex=True, required=True)
legacy_mode_group = config_group.add_argument_group(
help=('Arguments to specify information about simple counter logs-'
'based metrics.'))
legacy_mode_group.add_argument(
'--description',
required=False,
help=('A new description for the metric. '
'If omitted, the description is not changed.'))
legacy_mode_group.add_argument(
'--log-filter',
required=False,
help=('A new filter string for the metric. '
'If omitted, the filter is not changed.'))
config_group.add_argument(
'--config-from-file',
help=('A path to a YAML file specifying the '
'updates to be made to the logs-based '
'metric.'),
type=arg_parsers.FileContents())
legacy_mode_group.add_argument(
'--bucket-name',
help='The Log Bucket name which owns the log-based metric.')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
The updated metric.
"""
# Calling the API's Update method on a non-existing metric creates it.
# Make sure the metric exists so we don't accidentally create it.
metric = util.GetClient().projects_metrics.Get(
util.GetMessages().LoggingProjectsMetricsGetRequest(
metricName=util.CreateResourceName(util.GetCurrentProjectParent(),
'metrics', args.metric_name)))
updated_metric = util.UpdateLogMetric(
metric,
description=args.description,
log_filter=args.log_filter,
bucket_name=args.bucket_name,
data=args.config_from_file)
result = util.GetClient().projects_metrics.Update(
util.GetMessages().LoggingProjectsMetricsUpdateRequest(
metricName=util.CreateResourceName(util.GetCurrentProjectParent(),
'metrics', args.metric_name),
logMetric=updated_metric))
log.UpdatedResource(args.metric_name)
return result
Update.detailed_help = DETAILED_HELP