packages feed

ngx-export-tools-extra 1.2.9 → 1.2.9.1

raw patch · 3 files changed

+62/−49 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Changelog.md view
@@ -1,15 +1,30 @@+### 1.2.9.1++- Module *NgxExport.Tools.Resolve*.+  + By mistake, servers with less weights had higher priorities in *A* queries.+  + If the number of upstreams in the priority list is less than the number of+    variations of priorities collected in *SRV* queries or weights set in+    *QueryA* data, then remaining servers with the lowest priorities or weights+    won't be used in the upstreams.+  + With the *PriorityList* policy, weights of servers in the collected data are+    deliberately not specified in *A* queries. In *SRV* queries, conversely,+    weights are not specified with the *SinglePriority* policy as it is not+    clear how to choose them correctly from the two parameters *priority* and+    *weight* of the *SRV* record.+ ### 1.2.9  - Module *NgxExport.Tools.Resolve*.   + Correctly print IP addresses in the server data collected in *A* queries.   + Allow setting weights to names in *QueryA* data.   + Allow priority policies in *QueryA* data.-  + Now, if the number of upstreams in the priority list is greater than the-    number of variations of weights collected in *SRV* queries or set in-    *QueryA* data, the remainder of upstreams get servers with the lowest-    weight rather than not being specified at all in the collected data.-  + Now, with the *PriorityList* policy, weights of servers in the collected-    data are deliberately not specified.+  + If the number of upstreams in the priority list is greater than the number+    of variations of priorities collected in *SRV* queries or weights set in+    *QueryA* data, then remaining upstreams will contain the same servers with+    the lowest priority or weight rather than not being specified at all in the+    collected data.+  + With the *PriorityList* policy, weights of servers in the collected data are+    deliberately not specified.   + Names in the *QueryA* name list may contain suffix *:port* where *port* is     a port number, this suffix is ignored at resolving step in *collectA* and     only appended to values of the collected server addresses.
NgxExport/Tools/Resolve.hs view
@@ -59,6 +59,7 @@ import           Data.Function import           Data.List import           Data.Bits+import           Data.Ord import           Control.Concurrent.Async import           Control.Exception import           Control.Exception.Safe (handleAny)@@ -220,18 +221,14 @@ -- @ -- -- With this configuration, servers with the highest priority will inhabit--- upstream /utest/, while servers with lesser priorities will inhabit upstream--- /utest1/. Upstream /utest1/ must also be managed by the /upconf/ module. The--- priority list may contain more than two upstreams, in which case upstreams--- at the beginning of the list will take higher priorities found in the--- collected servers, while the last upstream will take the remainder of the--- priorities. Generally, given the number of upstreams in the priority list is--- /N/ and the number of all variations of server priorities collected in the--- response is /M/, and /N/ is less than /M/, then the remainder of servers with--- the lowest priorities will inhabit the last upstream in the priority list,--- and vice versa, if /N/ is greater than /M/, then more than one upstreams at--- the end of the priority list will contain the same servers of the lowest--- priority.+-- upstream /utest/, while servers with the less priority will inhabit upstream+-- /utest1/. Upstream /utest1/ must also be managed by the /upconf/ module.+-- Generally, given the number of upstreams in the priority list is \(N\) and+-- the number of all variations of server priorities collected in the response+-- is \(M\), and \(N\) is less than \(M\), then remaining \(M - N\) servers with+-- the lowest priorities won't be used in the upstreams at all, otherwise, if+-- \(N\) is greater than \(M\), then remaining \(N - M\) upstreams at the end of+-- the priority list will contain the same servers of the lowest priority. -- -- Upstreams in the priority list can be put inside of an /upstrand/ to form the -- main and the backup layers of servers.@@ -278,13 +275,25 @@ -- - the same as the previous, but distribute collected servers among a list of --   upstreams according to the collected priorities. ----- Note that+-- Particularly, in /SRV/ queries priorities are taken from values of+-- 'srvPriority', the less this value the higher the priority. In /A/ queries+-- priorities are taken from v'WeightedList', the higher the weight the higher+-- the priority. ----- - names in /QueryA/ name list may contain suffix /:port/ (a port number)---   which is ignored in 'collectA' and only appended to values of 'sAddr'---   collected by 'collectServerData',--- - when priority policy is 'PriorityList', vaues of 'sWeight' collected by---   'collectServerData' are deliberately /Nothing/.+-- Weights of individual servers depend on both priority policy and type of the+-- query:+--+-- - /single priority, A query/: weights are taken from v'WeightedList',+-- - /priority list, A query/: no weights are specified as the values from+--   v'WeightedList' are used for the priority list parameterization,+-- - /single priority, SRV query/: no weights are specified as it is not clear+--   how to choose them correctly from the two parameters 'srvPriority' and+--   'srvWeight',+-- - /priority list, SRV query/: weights are taken from 'srvWeight'.+--+-- Names in the /QueryA/ name list may contain suffix /:port/ (a port number)+-- which is ignored in 'collectA' and only appended to values of 'sAddr'+-- collected by 'collectServerData'. data UQuery = QueryA NameList UNamePriorityPolicy  -- ^ Query /A/ records             | QuerySRV Name UNamePriorityPolicy    -- ^ Query an /SRV/ record             deriving Read@@ -316,10 +325,8 @@ -- -- Includes DNS query model and parameters for Nginx /server/ description. -- Values of /uMaxFails/ and /uFailTimeout/ get assigned to each collected--- server as /max_fails/ and /fail_timeout/ respectively. For /SRV/ queries,--- weights of individual servers will be picked from the values of 'srvWeight'--- collected in the query. Note that setting of parameters /max_conns/,--- /backup/ and /down/ is not supported.+-- server as /max_fails/ and /fail_timeout/ respectively. Note that setting of+-- parameters /max_conns/, /backup/ and /down/ is not supported. data UData = UData { uQuery       :: UQuery  -- ^ DNS query model                    , uMaxFails    :: Int     -- ^ /max_fails/                    , uFailTimeout :: Int     -- ^ /fail_timeout/@@ -424,18 +431,9 @@ partitionByPriority :: (Eq b, Ord b) => (a -> b) -> [a] -> [[a]] partitionByPriority f = groupBy ((==) `on` f) . sortOn f -zipWithPriorityList :: UNamePriorityPolicy -> [a] -> [(UName, a)]-zipWithPriorityList (PriorityList []) _ = []-zipWithPriorityList (PriorityList _) [] = []-zipWithPriorityList (PriorityList pl) vs =-    let (lpl, lastp) = lengthAndLast pl-        (lvs, lastv) = lengthAndLast vs-    in uncurry zip $ if lpl > lvs-                         then (pl, vs ++ repeat lastv)-                         else (pl ++ repeat lastp, vs)-    where lengthAndLast =-              foldl' (\(l, _) v -> (succ l, v)) (0 :: Int, undefined)-zipWithPriorityList _ _ = undefined+zipWithOtherRepeatLast :: [a] -> [b] -> [(a, b)]+zipWithOtherRepeatLast _ [] = []+zipWithOtherRepeatLast xs other = zip xs $ other ++ repeat (last other)  ipv4ToServerData :: UData -> UNamePriorityPolicy -> Name -> Maybe Word ->     IPv4 -> ServerData@@ -455,8 +453,8 @@         showAddr i p = showIPv4 i ++ ':' : show p     in ServerData (T.pack $ showAddr a srvPort) (T.decodeUtf8 n)           (case policy of-               SinglePriority _ -> Just $ fromIntegral srvWeight-               PriorityList _ -> Nothing+               SinglePriority _ -> Nothing+               PriorityList _ -> Just $ fromIntegral srvWeight           ) (Just uMaxFails) (Just uFailTimeout)  -- | Collects server data for the given upstream configuration.@@ -473,14 +471,14 @@     | null ns = return (lTTL, M.empty)     | PriorityList [] <- p = return (lTTL, M.empty) collectServerData lTTL ud@(UData (QueryA-                                     (WeightedList ns) p@(PriorityList _)+                                     (WeightedList ns) p@(PriorityList pl)                                  ) _ _                           ) = do     a <- mapConcurrently (\nw@(n, _) -> (nw, ) <$> collectA lTTL n) ns     return $         minimum ***-            M.fromList . zipWithPriorityList p-            . map (map snd) . partitionByPriority fst . concat $+            M.fromList . zipWithOtherRepeatLast pl+            . map (map snd) . partitionByPriority (Down . fst) . concat $                 foldr (\((n, w), (t, s)) (ts, ss) ->                           (t : ts                            -- sort is required because resolver may rotate@@ -488,7 +486,7 @@                            -- after every single check; this note regards to                            -- other clauses of this function as well                           ,sort (map ((w ,) .-                                         ipv4ToServerData ud p n (Just w)+                                         ipv4ToServerData ud p n Nothing                                      ) s                                 ) : ss                           )@@ -512,9 +510,9 @@     return (wt, M.singleton u $ sort $ map (srvToServerData ud p) srv) collectServerData lTTL (UData (QuerySRV _ (PriorityList [])) _ _) =     return (lTTL, M.empty)-collectServerData lTTL ud@(UData (QuerySRV n p@(PriorityList _)) _ _ ) = do+collectServerData lTTL ud@(UData (QuerySRV n p@(PriorityList pl)) _ _ ) = do     (wt, srv) <- collectSRV lTTL n-    let srv' = zipWithPriorityList p $ partitionByPriority srvPriority srv+    let srv' = zipWithOtherRepeatLast pl $ partitionByPriority srvPriority srv     return (wt            ,M.fromList $ map (second $ sort . map (srvToServerData ud p)) srv'            )
ngx-export-tools-extra.cabal view
@@ -1,5 +1,5 @@ name:                       ngx-export-tools-extra-version:                    1.2.9+version:                    1.2.9.1 synopsis:                   More extra tools for Nginx Haskell module description:                More extra tools for         <https://github.com/lyokha/nginx-haskell-module Nginx Haskell module>.