legion-discovery 0.2.2.1 → 0.2.2.2
raw patch · 3 files changed
+99/−6 lines, 3 filesdep +ekgdep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: ekg
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- README.md +82/−0
- legion-discovery.cabal +13/−5
- src/Network/Legion/Discovery.hs +4/−1
+ README.md view
@@ -0,0 +1,82 @@+# legion-discovery++A simple service discovery service based on Legion, that natively supports+the idea of interface versions, and the idea that clients may only be+interested in finding certain (compatible) versions of the services they+are looking for.++The initial motivation for this project is to act as a test driver for the+[Legion](https://github.com/owensmurray/legion#readme) framework. Since the+status of that framework is still experimental, the status of this service is+also experimental.++- [API](#api)+ - [`POST /v1/ping/:serviceId/:version`](#post-v1pingserviceidversion)+ - [`GET /v1/services/:serviceId`](#get-v1servicesserviceid)+ - [`GET /v1/services/:serviceId/:versionRange`](#get-v1servicesserviceidversionrange)+ - [`GET /v1/graph`](#get-v1graph)+- [Content Types](#content-types)+ - [`application/vnd.legion-discovery.instance-list+json`](#applicationvndlegion-discoveryinstance-listjson)+ - [`application/vnd.legion-discovery.ping-request+json`](#applicationvndlegion-discoveryping-requestjson)++## API++### `POST /v1/ping/:serviceId/:version`++Register a service. Registration expires in 30 seconds.++- Request+ - Content-Type: [`application/vnd.legion-discovery.ping-request+json`](#applicationvndlegion-discoveryping-requestjson)+- Response `204 No Content`: indicates a successful registration.++### `GET /v1/services/:serviceId`++Returns all current instances of a service, regardless of version.++- Response `200 Ok`+ - Content-Type: [`application/vnd.legion-discovery.instance-list+json`](#applicationvndlegion-discoveryinstance-listjson)+++### `GET /v1/services/:serviceId/:versionRange`++Returns the service instances that match the requested version range. The+version range syntax is the same as what cabal understands+(e.g. `>= 0.1 && < 0.2`). You are really going to want to make sure and url+encode this segment of the url.++- Response `200 Ok`+ - Content-Type: [`application/vnd.legion-discovery.instance-list+json`](#applicationvndlegion-discoveryinstance-listjson)++### `GET /v1/graph`++Returns a visualization of the service interactions. This endpoint supports+multiple content types via the `Accept` header.++- Response `200 Ok`+ - Content-Type [`image/svg+xml`](https://www.w3.org/TR/SVG11/)+ - Content-Type [`text/vnd.graphviz`](http://www.graphviz.org/content/dot-language)+++## Content Types++### `application/vnd.legion-discovery.instance-list+json`++ {+ "https://host1:8080": {+ "version": "1.0.2.0"+ },+ "https://host2:8080": {+ "version": "1.0.2.0"+ },+ "https://host3:8080": {+ "version": "1.0.2.0"+ }+ }++### `application/vnd.legion-discovery.ping-request+json`++ {+ "serviceAddress": "https://host3:8080"+ }++
legion-discovery.cabal view
@@ -1,7 +1,13 @@ name: legion-discovery-version: 0.2.2.1-synopsis: Initial project template from stack-description: Please see README.md+version: 0.2.2.2+synopsis: A discovery service based on Legion.++description: A simple service discovery service based on Legion,+ that natively supports the idea of interface+ versions, and the idea that clients may only be+ interested in finding certain (compatible) versions+ of the services they are looking for.+ homepage: https://github.com/owensmurray/legion-discovery#readme license: Apache-2.0 license-file: LICENSE@@ -10,7 +16,8 @@ copyright: 2016 Rick Owens category: value build-type: Simple--- extra-source-files:+extra-source-files:+ README.md cabal-version: >=1.10 library@@ -31,7 +38,7 @@ SHA >= 1.6.4.1 && < 1.7, aeson >= 0.11.2.1 && < 0.12, attoparsec >= 0.13.1.0 && < 0.14,- base >= 4.8 && < 4.10,+ base >= 4.9 && < 4.10, binary >= 0.7.5.0 && < 0.9, bytestring >= 0.10.6.0 && < 0.11, canteven-http >= 0.1.1.1 && < 0.2,@@ -39,6 +46,7 @@ conduit >= 1.2.7 && < 1.3, containers >= 0.5.6.2 && < 0.6, data-default-class >= 0.0.1 && < 0.2,+ ekg >= 0.4.0.11 && < 0.5, graphviz >= 2999.18.1.2 && < 2999.19, http-types >= 0.9.1 && < 0.10, legion >= 0.8 && < 0.9,
src/Network/Legion/Discovery.hs view
@@ -9,6 +9,7 @@ import Canteven.HTTP (requestLogging, logExceptionsAndContinue, DecodeResult(Unsupported, BadEntity, Ok), FromEntity, decodeEntity) import Canteven.Log.MonadLog (getCantevenOutput)+import Control.Monad (void) import Control.Monad.IO.Class (MonadIO, liftIO) import Data.Aeson (encode, object, (.=), FromJSON, parseJSON, Value(Object), (.:), eitherDecode)@@ -38,7 +39,7 @@ ServiceId(ServiceId), toKey, Time(Time), unServiceAddr, version, ServiceAddr(ServiceAddr), InstanceInfo, Service, instances, name, unServiceId, State, Client(Client), cName, cVersion)-import Network.Legion.Discovery.Config (servicePort)+import Network.Legion.Discovery.Config (servicePort, ekgPort) import Network.Legion.Discovery.Graphviz (toDotGraph) import Network.Legion.Discovery.HttpError (HttpError) import Network.Legion.Discovery.LIO (runLIO, LIO)@@ -59,11 +60,13 @@ import qualified Data.Text.Lazy.Encoding as TLE import qualified Network.Legion.Discovery.Config as C import qualified Paths_legion_discovery as P+import qualified System.Remote.Monitoring as Ekg main :: IO () main = do (settings, startupMode, config) <- parseArgs logging <- getCantevenOutput (C.logging config)+ void $ Ekg.forkServer "localhost" (ekgPort config) persist <- newMemoryPersistence :: IO (Persistence Input Output State) runLIO logging $ do legion <- forkLegionary persist settings startupMode