[PATCH master] hinfo: Gather and print group statistics

1 view
Skip to first unread message

René Nussbaumer

unread,
Feb 29, 2012, 10:32:00 AM2/29/12
to ganeti...@googlegroups.com
---
I'm not sure about the line breaks, please let me know if there's a better line wrap
htools/Ganeti/HTools/Program/Hinfo.hs | 41 +++++++++++++++++++++++++++++++++
1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/htools/Ganeti/HTools/Program/Hinfo.hs b/htools/Ganeti/HTools/Program/Hinfo.hs
index ba26746..600440c 100644
--- a/htools/Ganeti/HTools/Program/Hinfo.hs
+++ b/htools/Ganeti/HTools/Program/Hinfo.hs
@@ -58,6 +58,45 @@ options =
, oShowHelp
]

+-- | Node group statistics
+calcGroupInfo :: Group.Group -> Node.List -> Instance.List -> ( String
+ , (Int, Int)
+ , (Int, Int)
+ , Bool )
+calcGroupInfo g nl il =
+ let nl_size = (Container.size nl)
+ il_size = (Container.size il)
+ (bad_nodes, bad_instances) = Cluster.computeBadItems nl il
+ bn_size = length bad_nodes
+ bi_size = length bad_instances
+ n1h = bn_size == 0
+ in (Group.name g, (nl_size, il_size), (bn_size, bi_size), n1h)
+
+-- | Helper to format one group row result
+groupRowFormatHelper :: Group.Group -> Node.List -> Instance.List -> [String]
+groupRowFormatHelper g nl il =
+ let (gname, (nl_size, il_size), (bn_size, bi_size), n1h) = (calcGroupInfo g
+ nl
+ il)
+ in [ gname
+ , printf "%d" nl_size
+ , printf "%d" il_size
+ , printf "%d" bn_size
+ , printf "%d" bi_size
+ , show n1h ]
+
+-- | Print node group information
+groupInfo :: Group.List -> Node.List -> Instance.List -> IO ()
+groupInfo gl nl il = do
+ let grs = map (\(gdx, (gnl, gil)) ->
+ groupRowFormatHelper (Container.find gdx gl) gnl gil) $
+ Cluster.splitCluster nl il
+ header = ["Group", "Nodes", "Instances", "Bad_Nodes", "Bad_Instances",
+ "N+1"]
+
+ printf "Node group information:\n%s"
+ (printTable " " header grs [False, True, True, True, True, False])
+
-- | Gather and print split instances
splitInstancesInfo :: Int -> Node.List -> Instance.List -> IO ()
splitInstancesInfo verbose nl il = do
@@ -112,6 +151,8 @@ main opts args = do

splitInstancesInfo verbose nlf ilf

+ groupInfo gl nlf ilf
+
maybePrintInsts showinsts "Instances" (Cluster.printInsts nlf ilf)

maybePrintNodes shownodes "Cluster" (Cluster.printNodes nlf)
--
1.7.7.3

Iustin Pop

unread,
Feb 29, 2012, 11:15:57 AM2/29/12
to René Nussbaumer, ganeti...@googlegroups.com
On Wed, Feb 29, 2012 at 04:32:00PM +0100, René Nussbaumer wrote:
> ---
> I'm not sure about the line breaks, please let me know if there's a better line wrap

Will do, see below.

> htools/Ganeti/HTools/Program/Hinfo.hs | 41 +++++++++++++++++++++++++++++++++
> 1 files changed, 41 insertions(+), 0 deletions(-)
>
> diff --git a/htools/Ganeti/HTools/Program/Hinfo.hs b/htools/Ganeti/HTools/Program/Hinfo.hs
> index ba26746..600440c 100644
> --- a/htools/Ganeti/HTools/Program/Hinfo.hs
> +++ b/htools/Ganeti/HTools/Program/Hinfo.hs
> @@ -58,6 +58,45 @@ options =
> , oShowHelp
> ]
>
> +-- | Node group statistics

missing '.' at the end.

> +calcGroupInfo :: Group.Group -> Node.List -> Instance.List -> ( String
> + , (Int, Int)
> + , (Int, Int)
> + , Bool )

Usually you put each arg/result on its own line, like:

calcGroupInfo :: Group.Group
-> Node.List
-> Instance.List

-> …

> +calcGroupInfo g nl il =
> + let nl_size = (Container.size nl)
> + il_size = (Container.size il)

no need for parantheses on the previous two lines.

> + (bad_nodes, bad_instances) = Cluster.computeBadItems nl il
> + bn_size = length bad_nodes
> + bi_size = length bad_instances
> + n1h = bn_size == 0
> + in (Group.name g, (nl_size, il_size), (bn_size, bi_size), n1h)
> +
> +-- | Helper to format one group row result

. missing

> +groupRowFormatHelper :: Group.Group -> Node.List -> Instance.List -> [String]
> +groupRowFormatHelper g nl il =
> + let (gname, (nl_size, il_size), (bn_size, bi_size), n1h) = (calcGroupInfo g
> + nl
> + il)

you can put the calcGroupInfo call on a 2nd line, and again you don't
need parentheses.

> + in [ gname
> + , printf "%d" nl_size
> + , printf "%d" il_size
> + , printf "%d" bn_size
> + , printf "%d" bi_size
> + , show n1h ]
> +
> +-- | Print node group information
> +groupInfo :: Group.List -> Node.List -> Instance.List -> IO ()
> +groupInfo gl nl il = do

groupInfo → showGroupInfo ?

thanks,
iustin

René Nussbaumer

unread,
Mar 1, 2012, 4:58:18 AM3/1/12
to Iustin Pop, ganeti...@googlegroups.com
On Wed, Feb 29, 2012 at 17:15, Iustin Pop <ius...@google.com> wrote:
> On Wed, Feb 29, 2012 at 04:32:00PM +0100, René Nussbaumer wrote:
>> ---
>> I'm not sure about the line breaks, please let me know if there's a better line wrap
>
> Will do, see below.

Thanks for the heads up!

>>  htools/Ganeti/HTools/Program/Hinfo.hs |   41 +++++++++++++++++++++++++++++++++
>>  1 files changed, 41 insertions(+), 0 deletions(-)
>>
>> diff --git a/htools/Ganeti/HTools/Program/Hinfo.hs b/htools/Ganeti/HTools/Program/Hinfo.hs
>> index ba26746..600440c 100644
>> --- a/htools/Ganeti/HTools/Program/Hinfo.hs
>> +++ b/htools/Ganeti/HTools/Program/Hinfo.hs
>> @@ -58,6 +58,45 @@ options =
>>    , oShowHelp
>>    ]
>>
>> +-- | Node group statistics
>
> missing '.' at the end.
>
>> +calcGroupInfo :: Group.Group -> Node.List -> Instance.List -> ( String
>> +                                                              , (Int, Int)
>> +                                                              , (Int, Int)
>> +                                                              , Bool )
>
> Usually you put each arg/result on its own line, like:
>
> calcGroupInfo :: Group.Group
>              -> Node.List
>              -> Instance.List
>              -> …

Indeed, done!

>> +calcGroupInfo g nl il =
>> +  let nl_size                    = (Container.size nl)
>> +      il_size                    = (Container.size il)
>
> no need for parantheses on the previous two lines.

Indeed, done.

>
>> +      (bad_nodes, bad_instances) = Cluster.computeBadItems nl il
>> +      bn_size                    = length bad_nodes
>> +      bi_size                    = length bad_instances
>> +      n1h                        = bn_size == 0
>> +  in (Group.name g, (nl_size, il_size), (bn_size, bi_size), n1h)
>> +
>> +-- | Helper to format one group row result
>
> . missing

Done.

>
>> +groupRowFormatHelper :: Group.Group -> Node.List -> Instance.List -> [String]
>> +groupRowFormatHelper g nl il =
>> +  let (gname, (nl_size, il_size), (bn_size, bi_size), n1h) = (calcGroupInfo g
>> +                                                                            nl
>> +                                                                            il)
>
> you can put the calcGroupInfo call on a 2nd line, and again you don't
> need parentheses.

I tried but now I know what I missed back then. I did the indent
wrong. Anyway, this line is obsolete in the upcoming new patch as I
reorganized some of those functions to be better suited.

>> +  in [ gname
>> +     , printf "%d" nl_size
>> +     , printf "%d" il_size
>> +     , printf "%d" bn_size
>> +     , printf "%d" bi_size
>> +     , show n1h ]
>> +
>> +-- | Print node group information
>> +groupInfo :: Group.List -> Node.List -> Instance.List -> IO ()
>> +groupInfo gl nl il = do
>
> groupInfo → showGroupInfo ?

Done :)

René

René Nussbaumer

unread,
Mar 1, 2012, 5:00:57 AM3/1/12
to ganeti...@googlegroups.com
---
I didn't like the logic of groupRowFormatHelper, as it was also fetching the
data. However, in my opinion this should have been clearly just the format
task. So I fixed that part by refactoring. This had the nice side effect that I
now can easily calculate the overall cluster N+1 happiness :). I try to
incomporate all the comments of the previous patch in this one.
htools/Ganeti/HTools/Program/Hinfo.hs | 47 +++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/htools/Ganeti/HTools/Program/Hinfo.hs b/htools/Ganeti/HTools/Program/Hinfo.hs
index ba26746..ad160ae 100644
--- a/htools/Ganeti/HTools/Program/Hinfo.hs
+++ b/htools/Ganeti/HTools/Program/Hinfo.hs
@@ -58,7 +58,48 @@ options =
, oShowHelp
]

--- | Gather and print split instances
+-- | Node group statistics.
+calcGroupInfo :: Group.Group
+ -> Node.List
+ -> Instance.List
+ -> (String, (Int, Int), (Int, Int), Bool)


+calcGroupInfo g nl il =

+ let nl_size = Container.size nl
+ il_size = Container.size il


+ (bad_nodes, bad_instances) = Cluster.computeBadItems nl il
+ bn_size = length bad_nodes
+ bi_size = length bad_instances
+ n1h = bn_size == 0
+ in (Group.name g, (nl_size, il_size), (bn_size, bi_size), n1h)
+
+-- | Helper to format one group row result.

+groupRowFormatHelper :: (String, (Int, Int), (Int, Int), Bool) -> [String]
+groupRowFormatHelper (gname, (nl_size, il_size), (bn_size, bi_size), n1h) =
+ [ gname


+ , printf "%d" nl_size
+ , printf "%d" il_size
+ , printf "%d" bn_size
+ , printf "%d" bi_size
+ , show n1h ]
+

+-- | Print node group information.
+showGroupInfo :: Int -> Group.List -> Node.List -> Instance.List -> IO ()
+showGroupInfo verbose gl nl il = do
+ let cgrs = map (\(gdx, (gnl, gil)) ->
+ calcGroupInfo (Container.find gdx gl) gnl gil) $
+ Cluster.splitCluster nl il
+ cn1h = all (\(_, _, _, n1h) -> n1h) cgrs
+ grs = map groupRowFormatHelper cgrs


+ header = ["Group", "Nodes", "Instances", "Bad_Nodes", "Bad_Instances",
+ "N+1"]
+

+ when (verbose > 1) $


+ printf "Node group information:\n%s"
+ (printTable " " header grs [False, True, True, True, True, False])
+

+ printf "Cluster is N+1 %s\n" $ if cn1h then "happy" else "unhappy"
+
+-- | Gather and print split instances.


splitInstancesInfo :: Int -> Node.List -> Instance.List -> IO ()
splitInstancesInfo verbose nl il = do

let split_insts = Cluster.findSplitInstances nl il
@@ -70,7 +111,7 @@ splitInstancesInfo verbose nl il = do
putStrLn "Found instances belonging to multiple node groups:"
mapM_ (\i -> hPutStrLn stderr $ " " ++ Instance.name i) split_insts

--- | Print common (interesting) information
+-- | Print common (interesting) information.
commonInfo :: Int -> Group.List -> Node.List -> Instance.List -> IO ()
commonInfo verbose gl nl il = do
when (Container.null il && verbose > 1) $ do
@@ -112,6 +153,8 @@ main opts args = do

splitInstancesInfo verbose nlf ilf

+ showGroupInfo verbose gl nlf ilf

Iustin Pop

unread,
Mar 1, 2012, 8:19:35 AM3/1/12
to René Nussbaumer, ganeti...@googlegroups.com
On Thu, Mar 01, 2012 at 11:00:57AM +0100, René Nussbaumer wrote:
> ---
> I didn't like the logic of groupRowFormatHelper, as it was also fetching the
> data. However, in my opinion this should have been clearly just the format
> task. So I fixed that part by refactoring. This had the nice side effect that I
> now can easily calculate the overall cluster N+1 happiness :). I try to
> incomporate all the comments of the previous patch in this one.
> htools/Ganeti/HTools/Program/Hinfo.hs | 47 +++++++++++++++++++++++++++++++-
> 1 files changed, 45 insertions(+), 2 deletions(-)

LGTM, thanks.

iustin

Reply all
Reply to author
Forward
0 new messages