packages feed

tmp-proc-zipkin (empty) → 0.5.0.0

raw patch · 8 files changed

+270/−0 lines, 8 filesdep +basedep +bytestringdep +hspecsetup-changed

Dependencies added: base, bytestring, hspec, hspec-tmp-proc, http-client, text, tmp-proc, tmp-proc-zipkin, tracing

Files

+ ChangeLog.md view
@@ -0,0 +1,6 @@+# Revision history for tmp-proc-zipkin++## 0.5.0.0 -- 2021-09-28++* First version+* Initial upload to hackage
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2021, Tim Emiola++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Tim Emiola nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,11 @@+# tmp-proc-zipkin++`tmp-proc-zipkin` provides an example of using `tmp-proc` to launch dockerized+Zipkin in integration tests.++It provides an instance of [Proc][1] for launching the Zipkin image, and also+provides an instance of [Conn][2] that simplifies opening connections to the+launched Zipkin service from tests that use `tmp-proc`.++[1]: https://hackage.haskell.org/package/tmp-proc-0.5.0.0/docs/System-TmpProc-Docker.html#t:Proc+[2]: https://hackage.haskell.org/package/tmp-proc-0.5.0.0/docs/System-TmpProc-Docker.html#t:Conn
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/System/TmpProc/Docker/Zipkin.hs view
@@ -0,0 +1,119 @@+{-# LANGUAGE DataKinds             #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE NamedFieldPuns        #-}+{-# LANGUAGE OverloadedStrings     #-}+{-# LANGUAGE ScopedTypeVariables   #-}+{-# LANGUAGE TypeApplications      #-}+{-# LANGUAGE TypeFamilies          #-}+{-# OPTIONS_HADDOCK prune not-home #-}+{-|+Copyright   : (c) 2020-2021 Tim Emiola+SPDX-License-Identifier: BSD3+Maintainer  : Tim Emiola <adetokunbo@users.noreply.github.com >++Provides an instance of 'Proc' that launches @ZipKin@ as a @tmp proc@.++The instance this module provides can be used in integration tests as is.++It's also possible to write other instances that launch @ZipKin@ in different+ways; for those, this instance can be used as a reference example.++-}+module System.TmpProc.Docker.Zipkin+  ( -- * 'Proc' instance+    TmpZipkin(..)++    -- * Useful definitions+  , aProc+  , aHandle++    -- * Re-exports+  , module System.TmpProc+  )+where++import           Control.Monad.IO.Class    (MonadIO, liftIO)+import           Control.Monad.Trace.Class (MonadTrace, alwaysSampled, rootSpan)+import qualified Data.ByteString.Char8     as C8+import           Data.Proxy                (Proxy (..))+import           Data.String               (fromString)+import qualified Data.Text                 as Text+import           Network.HTTP.Client       (HttpException)+import           System.IO                 (Handle, IOMode (..), hPutStrLn,+                                            openBinaryFile)++import qualified Monitor.Tracing.Zipkin    as ZPK++import           System.TmpProc            (Connectable (..), HList (..),+                                            HandlesOf, HostIpAddress,+                                            Pinged (..), Proc (..),+                                            ProcHandle (..), SvcURI, startupAll,+                                            toPinged, withTmpConn)+++{-| A singleton 'HList' containing a 'TmpZipkin'. -}+aProc :: HList '[TmpZipkin]+aProc = TmpZipkin `HCons` HNil+++{-| An 'HList' that just contains the handle created by 'aProc'. -}+aHandle :: IO (HandlesOf '[TmpZipkin])+aHandle = startupAll aProc+++{-| Provides the capability to launch a Zipkin instance as a @tmp proc@. -}+data TmpZipkin = TmpZipkin+++{-| Specifies how to run @ZipKin@ as a @tmp proc@. -}+instance Proc TmpZipkin where+  type Image TmpZipkin = "openzipkin/zipkin-slim"+  type Name TmpZipkin = "a-zipkin-server"++  uriOf = mkUri'+  runArgs = []++  ping h = toPinged @HttpException Proxy $ do+    z <- openConn' h+    ZPK.run tracedPing z+    ZPK.publish z++  reset _ = pure ()+++{-| Specifies how to connect to a tmp @ZipKin@ service.++In this case, there is not really a connection type, but 'ZPK.Zipkin' provides+a close analogue.++-}+instance Connectable TmpZipkin where+  type Conn TmpZipkin = ZPK.Zipkin++  openConn = openConn'+  closeConn _ = pure ()+++openConn' :: ProcHandle TmpZipkin -> IO ZPK.Zipkin+openConn' = ZPK.new . toSettings+++{-| Make a simple HTTP uri to the zipkin server. -}+mkUri' :: HostIpAddress -> SvcURI+mkUri' ip = "http://" <> C8.pack (Text.unpack ip) <> "/"+++toSettings :: ProcHandle TmpZipkin -> ZPK.Settings+toSettings = fromString . Text.unpack . hAddr+++pingAction :: IO ()+pingAction = devNull >>= flip hPutStrLn "the trace of this will be sent as a ping"+++tracedPing :: (MonadIO m, MonadTrace m) => m ()+tracedPing = rootSpan alwaysSampled "ping" $ liftIO pingAction+++devNull :: IO Handle+devNull = openBinaryFile "/dev/null"  WriteMode
+ test/Spec.hs view
@@ -0,0 +1,12 @@+module Main (main) where++import           Test.Hspec++import           System.IO+import qualified Test.TmpProc.Docker.ZipkinSpec as ZK++main :: IO ()+main = do+  hSetBuffering stdin NoBuffering+  hSetBuffering stdout NoBuffering+  hspec ZK.spec
+ test/Test/TmpProc/Docker/ZipkinSpec.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE DataKinds         #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeApplications  #-}+module Test.TmpProc.Docker.ZipkinSpec where++import           Test.Hspec+import           Test.Hspec.TmpProc++import           Data.Proxy                     (Proxy (..))+import qualified Data.Text                      as Text++import           System.TmpProc.Docker.Zipkin++spec :: Spec+spec = tdescribe desc $ do+  beforeAll setupHandles $ afterAll terminateAll $ do+    context "when using the Proc from the HList by its 'Name'" $ do++      context "ixPing" $ do++        it "should succeed" $ \hs+          -> ixPing @"a-zipkin-server" Proxy hs `shouldReturn` OK+++setupHandles :: IO (HList '[ProcHandle TmpZipkin])+setupHandles = startupAll $ testProc `HCons` HNil+++testProc :: TmpZipkin+testProc = TmpZipkin+++desc :: String+desc = "Tmp.Proc:Zipkin:" ++ Text.unpack (nameOf testProc)
+ tmp-proc-zipkin.cabal view
@@ -0,0 +1,56 @@+cabal-version:      3.0+name:               tmp-proc-zipkin+version:            0.5.0.0+synopsis:           Shows how to run redis as a tmp proc+description:+  An example of using tmp-proc to launch dockerized ZipKin in integration tests.++license:            BSD-3-Clause+license-file:       LICENSE+copyright:          2021 Tim Emiola+author:             Tim Emiola+maintainer:         adetokunbo@users.noreply.github.com+category:           testing+bug-reports:        https://github.com/adetokunbo/tmp-proc/issues+build-type:         Simple+extra-source-files:+  ChangeLog.md+  README.md+tested-with:+  GHC == 8.10.5++source-repository head+  type:     git+  location: https://github.com/adetokunbo/tmp-proc.git++library+  exposed-modules:  System.TmpProc.Docker.Zipkin+  hs-source-dirs:   src+  build-depends:+    , base         >=4.11     && <4.16+    , bytestring   >=0.10.8.2 && <0.12+    , http-client+    , text         ^>=1.2.3+    , tmp-proc     >=0.5.0.0  && <0.6.0.0+    , tracing      >=0.0.7.2  && <0.1.0++  default-language: Haskell2010+  ghc-options:      -fno-ignore-asserts -Wall++test-suite integration-test+  type:             exitcode-stdio-1.0+  main-is:          Spec.hs+  other-modules:    Test.TmpProc.Docker.ZipkinSpec+  hs-source-dirs:   test+  build-depends:+    , base+    , bytestring+    , hspec+    , hspec-tmp-proc+    , text+    , tmp-proc+    , tmp-proc-zipkin++  default-language: Haskell2010+  ghc-options:+    -threaded -rtsopts -with-rtsopts=-N -fno-ignore-asserts -Wall