Skip to content
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

Calculating and updtating cluster and volume alert_count in each cluster sync #599

Merged
merged 3 commits into from
Apr 9, 2018

Conversation

GowthamShanmugam
Copy link
Contributor

tendrl-bug-id: #598

Signed-off-by: GowthamShanmugasundaram gshanmug@redhat.com

@GowthamShanmugam GowthamShanmugam requested review from shtripat and a team as code owners March 28, 2018 17:18
@GowthamShanmugam
Copy link
Contributor Author

@shtripat @shirshendu @r0h4n please review

@GowthamShanmugam
Copy link
Contributor Author

@GowthamShanmugam
Copy link
Contributor Author

only provisioning node will do alert_count update

@codecov
Copy link

codecov bot commented Mar 28, 2018

Codecov Report

Merging #599 into master will decrease coverage by 0.02%.
The diff coverage is 7.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #599      +/-   ##
==========================================
- Coverage   39.66%   39.63%   -0.03%     
==========================================
  Files          70       70              
  Lines        2607     2614       +7     
  Branches      374      376       +2     
==========================================
+ Hits         1034     1036       +2     
- Misses       1542     1547       +5     
  Partials       31       31
Impacted Files Coverage Δ
tendrl/gluster_integration/sds_sync/__init__.py 29.12% <7.69%> (-0.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2abb431...4787a92. Read the comment docs.

def find_volume_id():
alert_counts = {}
volumes = etcd_utils.read(
"clusters/%s/Volumes" % NS.tendrl_context.integration_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Volume.load_all()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will change this


def find_volume_id():
alert_counts = {}
volumes = etcd_utils.read(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use NS.gluster.objects.Volume().load_all() here ? I feel all you need is volume names then form the dict.
Also call the function as get_volume_alert_counts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

severity = ["WARNING", "CRITICAL"]
try:
alert_counts = find_volume_id()
alerts_arr = NS.tendrl.objects.ClusterAlert(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to load all the cluster alerts using tags only? Don't you need integration_id here? Does it default to NS.tendrl_context.integration_id in object constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shtripat for the cluster_alert object is a subclass of alert object, so for an alert object integration_id is not a mandatory field. So for cluster alerts, integration_id is present in tags only. While forming patch cluster alert object will take integration_id from tags only. That is why i am passing only tags with integration_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if alert.resource in NS.gluster.objects.VolumeAlertCounters(
)._defs['relationship'][alert.alert_type.lower()]:
vol_name = alert.tags.get('volume_name', None)
if vol_name:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add both the conditions in one if condition as if vol_name and vol_name in alert_counts.keys()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will change this

alert_count=cluster_alert_count
).save()
# Update volume alert count
for volume in alert_counts:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand alert_counts is a dict. If so you should use something like

for vol_name, alert_det in alert_counts.iter_items():
    NS.gluster.objects.VolumeAlertCounters(
        integration_id=NS.tendrl_context.integration_id,
        alert_count=alert_det['alert_count'],
        volume_id=alert_det['vol_id']
    ).save()

Does this work. Even I feel the dict created in find_volume_id functions could be with keys as volume ids and value as counters. Why you need volume name as keys? Do you really use that anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alert object contains volume name only present in tags, to compare this alert with a particular volume i need volume name. that why i am creating dict with the volume name. During alert iteration, i am just comparing volume name from alert object with newly formed dict to increase the alert count.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@GowthamShanmugam
Copy link
Contributor Author

@shtripat changes done

continue
volumes = NS.gluster.objects.Volume().load_all()
for volume in volumes:
alert_counts[volume.name] = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do the whole thing in one line

alert_counts[volume.name] = {"vol_id": volume.vol_id, "alert_count": 0}

@GowthamShanmugam
Copy link
Contributor Author

@shtripat changes done

severity = ["WARNING", "CRITICAL"]
try:
alert_counts = get_volume_alert_counts()
alerts_arr = NS.tendrl.objects.ClusterAlert(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alerts is good enough name :)

@shtripat
Copy link
Member

shtripat commented Apr 3, 2018

Looks fine. One small suggestion.
Also have you verified these changes?

@GowthamShanmugam
Copy link
Contributor Author

@shtripat changes done, i verified

Copy link
Member

@shtripat shtripat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine

Copy link
Contributor

@r0h4n r0h4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please resolve conflicts

…ter sync

tendrl-bug-id: Tendrl#598

Signed-off-by: GowthamShanmugasundaram <gshanmug@redhat.com>
tendrl-bug-id: Tendrl#598

Signed-off-by: GowthamShanmugasundaram <gshanmug@redhat.com>
tendrl-bug-id: Tendrl#598

Signed-off-by: GowthamShanmugasundaram <gshanmug@redhat.com>
@GowthamShanmugam
Copy link
Contributor Author

GowthamShanmugam commented Apr 7, 2018

Tendrl/ui#867

@r0h4n r0h4n merged commit 209923a into Tendrl:master Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants