Skip to content

Commit 77a2b2e

Browse files
kellerbr-ibmrtveitch
authored andcommitted
Add COS usage metrics monitoring feature
1 parent e2df969 commit 77a2b2e

File tree

1 file changed

+86
-4
lines changed

1 file changed

+86
-4
lines changed

cos_config/resource_configuration_v1.py

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def get_bucket_config(self, bucket, **kwargs):
112112
return response
113113

114114

115-
def update_bucket_config(self, bucket, firewall=None, activity_tracking=None, if_match=None, **kwargs):
115+
def update_bucket_config(self, bucket, firewall=None, activity_tracking=None, metrics_monitoring=None, if_match=None, **kwargs):
116116
"""
117117
Make changes to a bucket's configuration.
118118
@@ -134,6 +134,9 @@ def update_bucket_config(self, bucket, firewall=None, activity_tracking=None, if
134134
Tracker and LogDNA to provide visibility into object read and write events. All
135135
object events are sent to the activity tracker instance defined in the
136136
`activity_tracker_crn` field.
137+
:param MetricsMonitoring metrics_monitoring: Enables sending metrics to IBM Cloud
138+
Monitoring. All metrics are sent to the IBM Cloud Monitoring instance defined in
139+
the `monitoring_crn` field.
137140
:param str if_match: An Etag previously returned in a header when fetching or
138141
updating a bucket's metadata. If this value does not match the active Etag, the
139142
request will fail.
@@ -148,6 +151,8 @@ def update_bucket_config(self, bucket, firewall=None, activity_tracking=None, if
148151
firewall = self._convert_model(firewall, Firewall)
149152
if activity_tracking is not None:
150153
activity_tracking = self._convert_model(activity_tracking, ActivityTracking)
154+
if metrics_monitoring is not None:
155+
metrics_monitoring = self._convert_model(metrics_monitoring, MetricsMonitoring)
151156

152157
headers = {
153158
'if-match': if_match
@@ -159,7 +164,8 @@ def update_bucket_config(self, bucket, firewall=None, activity_tracking=None, if
159164

160165
data = {
161166
'firewall': firewall,
162-
'activity_tracking': activity_tracking
167+
'activity_tracking': activity_tracking,
168+
'metrics_monitoring': metrics_monitoring
163169
}
164170

165171
url = '/b/{0}'.format(*self._encode_path_vars(bucket))
@@ -277,9 +283,12 @@ class Bucket(object):
277283
Activity Tracker and LogDNA to provide visibility into object read and write events.
278284
All object events are sent to the activity tracker instance defined in the
279285
`activity_tracker_crn` field.
286+
:attr MetricsMonitoring metrics_monitoring: (optional) Enables sending metrics to IBM
287+
Cloud Monitoring. All metrics are sent to the IBM Cloud Monitoring instance defined in
288+
the `monitoring_crn` field.
280289
"""
281290

282-
def __init__(self, name=None, crn=None, service_instance_id=None, service_instance_crn=None, time_created=None, time_updated=None, object_count=None, bytes_used=None, firewall=None, activity_tracking=None):
291+
def __init__(self, name=None, crn=None, service_instance_id=None, service_instance_crn=None, time_created=None, time_updated=None, object_count=None, bytes_used=None, firewall=None, activity_tracking=None, metrics_monitoring=None):
283292
"""
284293
Initialize a Bucket object.
285294
@@ -308,6 +317,9 @@ def __init__(self, name=None, crn=None, service_instance_id=None, service_instan
308317
Activity Tracker and LogDNA to provide visibility into object read and write
309318
events. All object events are sent to the activity tracker instance defined in the
310319
`activity_tracker_crn` field.
320+
:param MetricsMonitoring metrics_monitoring: (optional) Enables sending metrics to
321+
IBM Cloud Monitoring. All metrics are sent to the IBM Cloud Monitoring instance
322+
defined in the `monitoring_crn` field.
311323
"""
312324
self.name = name
313325
self.crn = crn
@@ -319,12 +331,13 @@ def __init__(self, name=None, crn=None, service_instance_id=None, service_instan
319331
self.bytes_used = bytes_used
320332
self.firewall = firewall
321333
self.activity_tracking = activity_tracking
334+
self.metrics_monitoring = metrics_monitoring
322335

323336
@classmethod
324337
def _from_dict(cls, _dict):
325338
"""Initialize a Bucket object from a json dictionary."""
326339
args = {}
327-
validKeys = ['name', 'crn', 'service_instance_id', 'service_instance_crn', 'time_created', 'time_updated', 'object_count', 'bytes_used', 'firewall', 'activity_tracking']
340+
validKeys = ['name', 'crn', 'service_instance_id', 'service_instance_crn', 'time_created', 'time_updated', 'object_count', 'bytes_used', 'firewall', 'activity_tracking', 'metrics_monitoring']
328341
badKeys = set(_dict.keys()) - set(validKeys)
329342
if badKeys:
330343
raise ValueError('Unrecognized keys detected in dictionary for class Bucket: ' + ', '.join(badKeys))
@@ -348,6 +361,8 @@ def _from_dict(cls, _dict):
348361
args['firewall'] = Firewall._from_dict(_dict.get('firewall'))
349362
if 'activity_tracking' in _dict:
350363
args['activity_tracking'] = ActivityTracking._from_dict(_dict.get('activity_tracking'))
364+
if 'metrics_monitoring' in _dict:
365+
args['metrics_monitoring'] = MetricsMonitoring._from_dict(_dict.get('metrics_monitoring'))
351366
return cls(**args)
352367

353368
def _to_dict(self):
@@ -373,6 +388,8 @@ def _to_dict(self):
373388
_dict['firewall'] = self.firewall._to_dict()
374389
if hasattr(self, 'activity_tracking') and self.activity_tracking is not None:
375390
_dict['activity_tracking'] = self.activity_tracking._to_dict()
391+
if hasattr(self, 'metrics_monitoring') and self.metrics_monitoring is not None:
392+
_dict['metrics_monitoring'] = self.metrics_monitoring._to_dict()
376393
return _dict
377394

378395
def __str__(self):
@@ -449,3 +466,68 @@ def __ne__(self, other):
449466
return not self == other
450467

451468

469+
class MetricsMonitoring(object):
470+
"""
471+
Enables sending metrics to IBM Cloud Monitoring. All metrics are sent to the IBM Cloud
472+
Monitoring instance defined in the `monitoring_crn` field.
473+
474+
:attr bool usage_metrics_enabled: (optional) If set to `true`, all usage metrics (i.e.
475+
`bytes_used`) will be sent to the monitoring service.
476+
:attr str metrics_monitoring_crn: (optional) Required the first time
477+
`metrics_monitoring` is configured. The instance of IBM Cloud Monitoring that will
478+
receive the bucket metrics. The format is "crn:v1:bluemix:public:logdnaat:{bucket
479+
location}:a/{storage account}:{monitoring service instance}::".
480+
"""
481+
482+
def __init__(self, usage_metrics_enabled=None, metrics_monitoring_crn=None):
483+
"""
484+
Initialize a MetricsMonitoring object.
485+
486+
:param bool usage_metrics_enabled: (optional) If set to `true`, all usage metrics
487+
(i.e. `bytes_used`) will be sent to the monitoring service.
488+
:param str metrics_monitoring_crn: (optional) Required the first time
489+
`metrics_monitoring` is configured. The instance of IBM Cloud Monitoring that will
490+
receive the bucket metrics. The format is "crn:v1:bluemix:public:logdnaat:{bucket
491+
location}:a/{storage account}:{monitoring service instance}::".
492+
"""
493+
self.usage_metrics_enabled = usage_metrics_enabled
494+
self.metrics_monitoring_crn = metrics_monitoring_crn
495+
496+
@classmethod
497+
def _from_dict(cls, _dict):
498+
"""Initialize a MetricsMonitoring object from a json dictionary."""
499+
args = {}
500+
validKeys = ['usage_metrics_enabled', 'metrics_monitoring_crn']
501+
badKeys = set(_dict.keys()) - set(validKeys)
502+
if badKeys:
503+
raise ValueError('Unrecognized keys detected in dictionary for class MetricsMonitoring: ' + ', '.join(badKeys))
504+
if 'usage_metrics_enabled' in _dict:
505+
args['usage_metrics_enabled'] = _dict.get('usage_metrics_enabled')
506+
if 'metrics_monitoring_crn' in _dict:
507+
args['metrics_monitoring_crn'] = _dict.get('metrics_monitoring_crn')
508+
return cls(**args)
509+
510+
def _to_dict(self):
511+
"""Return a json dictionary representing this model."""
512+
_dict = {}
513+
if hasattr(self, 'usage_metrics_enabled') and self.usage_metrics_enabled is not None:
514+
_dict['usage_metrics_enabled'] = self.usage_metrics_enabled
515+
if hasattr(self, 'metrics_monitoring_crn') and self.metrics_monitoring_crn is not None:
516+
_dict['metrics_monitoring_crn'] = self.metrics_monitoring_crn
517+
return _dict
518+
519+
def __str__(self):
520+
"""Return a `str` version of this MetricsMonitoring object."""
521+
return json.dumps(self._to_dict(), indent=2)
522+
523+
def __eq__(self, other):
524+
"""Return `true` when self and other are equal, false otherwise."""
525+
if not isinstance(other, self.__class__):
526+
return False
527+
return self.__dict__ == other.__dict__
528+
529+
def __ne__(self, other):
530+
"""Return `true` when self and other are not equal, false otherwise."""
531+
return not self == other
532+
533+

0 commit comments

Comments
 (0)