Exemplo n.º 1
0
    def test_constructor(self):
        from gcloud.monitoring.label import LabelDescriptor

        TYPE = 'gce_instance'
        NAME = 'projects/my-project/monitoredResourceDescriptors/' + TYPE
        DISPLAY_NAME = 'GCE Instance'
        DESCRIPTION = 'A VM instance hosted in Google Compute Engine.'
        LABELS = [
            LabelDescriptor(key='project_id',
                            value_type='STRING',
                            description='The ID of the GCP project...'),
            LabelDescriptor(key='instance_id',
                            value_type='STRING',
                            description='The VM instance identifier...'),
            LabelDescriptor(key='zone',
                            value_type='STRING',
                            description='The GCE zone...'),
        ]

        descriptor = self._makeOne(
            name=NAME,
            type_=TYPE,
            display_name=DISPLAY_NAME,
            description=DESCRIPTION,
            labels=LABELS,
        )

        self.assertEqual(descriptor.name, NAME)
        self.assertEqual(descriptor.type, TYPE)
        self.assertEqual(descriptor.display_name, DISPLAY_NAME)
        self.assertEqual(descriptor.description, DESCRIPTION)
        self.assertEqual(descriptor.labels, LABELS)
Exemplo n.º 2
0
    def test_constructor(self):
        from gcloud.monitoring.label import LabelDescriptor

        TYPE = 'appengine.googleapis.com/http/server/response_count'
        NAME = 'projects/my-project/metricDescriptors/' + TYPE
        LABELS = [
            LabelDescriptor(key='loading',
                            value_type='BOOL',
                            description='Loaded a new instance?'),
            LabelDescriptor(key='response_code',
                            value_type='INT64',
                            description='HTTP status code for the request.'),
        ]

        METRIC_KIND = 'DELTA'
        VALUE_TYPE = 'INT64'

        UNIT = '{responses}/s'
        DESCRIPTION = 'Delta HTTP response count.'
        DISPLAY_NAME = 'Response count'

        client = object()
        descriptor = self._makeOne(
            client=client,
            name=NAME,
            type_=TYPE,
            labels=LABELS,
            metric_kind=METRIC_KIND,
            value_type=VALUE_TYPE,
            unit=UNIT,
            description=DESCRIPTION,
            display_name=DISPLAY_NAME,
        )

        self.assertIs(descriptor.client, client)

        self.assertEqual(descriptor.name, NAME)
        self.assertEqual(descriptor.type, TYPE)
        self.assertEqual(descriptor.labels, LABELS)

        self.assertEqual(descriptor.metric_kind, METRIC_KIND)
        self.assertEqual(descriptor.value_type, VALUE_TYPE)

        self.assertEqual(descriptor.unit, UNIT)
        self.assertEqual(descriptor.description, DESCRIPTION)
        self.assertEqual(descriptor.display_name, DISPLAY_NAME)
Exemplo n.º 3
0
    def _init_from_dict(self, info):
        """Initialize attributes from the parsed JSON representation.

        :type info: dict
        :param info:
            A ``dict`` parsed from the JSON wire-format representation.
        """
        self.name = info['name']
        self.type = info['type']
        self.labels = tuple(LabelDescriptor._from_dict(label)
                            for label in info.get('labels', []))
        self.metric_kind = info['metricKind']
        self.value_type = info['valueType']
        self.unit = info.get('unit', '')
        self.description = info.get('description', '')
        self.display_name = info.get('displayName', '')
Exemplo n.º 4
0
    def _from_dict(cls, info):
        """Construct a resource descriptor from the parsed JSON representation.

        :type info: dict
        :param info:
            A ``dict`` parsed from the JSON wire-format representation.

        :rtype: :class:`ResourceDescriptor`
        :returns: A resource descriptor.
        """
        return cls(
            name=info['name'],
            type_=info['type'],
            display_name=info.get('displayName', ''),
            description=info.get('description', ''),
            labels=tuple(LabelDescriptor._from_dict(label)
                         for label in info.get('labels', ())),
        )
Exemplo n.º 5
0
    def _from_dict(cls, info):
        """Construct a resource descriptor from the parsed JSON representation.

        :type info: dict
        :param info:
            A ``dict`` parsed from the JSON wire-format representation.

        :rtype: :class:`ResourceDescriptor`
        :returns: A resource descriptor.
        """
        return cls(
            name=info['name'],
            type_=info['type'],
            display_name=info.get('displayName', ''),
            description=info.get('description', ''),
            labels=tuple(LabelDescriptor._from_dict(label)
                         for label in info.get('labels', ())),
        )
Exemplo n.º 6
0
    def _from_dict(cls, info):
        """Construct a metric descriptor from the parsed JSON representation.

        :type info: dict
        :param info:
            A ``dict`` parsed from the JSON wire-format representation.

        :rtype: :class:`MetricDescriptor`
        :returns: A metric descriptor.
        """
        return cls(
            name=info['name'],
            type_=info['type'],
            labels=tuple(LabelDescriptor._from_dict(label)
                         for label in info.get('labels', ())),
            metric_kind=info['metricKind'],
            value_type=info['valueType'],
            unit=info.get('unit', ''),
            description=info.get('description', ''),
            display_name=info.get('displayName', ''),
        )
Exemplo n.º 7
0
    def _from_dict(cls, info):
        """Construct a metric descriptor from the parsed JSON representation.

        :type info: dict
        :param info:
            A ``dict`` parsed from the JSON wire-format representation.

        :rtype: :class:`MetricDescriptor`
        :returns: A metric descriptor.
        """
        return cls(
            name=info['name'],
            type_=info['type'],
            labels=tuple(LabelDescriptor._from_dict(label)
                         for label in info.get('labels', ())),
            metric_kind=info['metricKind'],
            value_type=info['valueType'],
            unit=info.get('unit', ''),
            description=info.get('description', ''),
            display_name=info.get('displayName', ''),
        )