Skip to content

Overview issue: Things to improve in consul-haskell #32

@nh2

Description

@nh2

Here I'm making a short list of key things to improve in consul-haskell.

  • Document all functions.
  • Provide some examples for common distributed-systems tasks, such as running a service with a health check from Haskell, or running a master-elected task across multiple Haskell servers.
  • Sensibly group funciton docs into sections of tasks that you usually want to accomplish with consul.
  • Use of Bool on errors.
    For example registerService :: ... -> m Bool returns False on any non-HTTP-200 response, discarding any useful error message, thus making it unclear how the caller should handle that case. Invalid request, or temporary loss of cluster leadership? The caller cannot tell.
    Some functions don't seem to check the status code at all; we need to fix that.
  • Clean up comment this is here instead of the where to prevent typechecking nastiness
  • Move the datacenter into ConsulClient (like the Python bindings do).
    Currently most functions take Maybe Datacenter as an argument, but it is usually not used, and if used, usually the same.
  • Fix usage of plain async.
    That function isn't exception-safe (see first section of the main docs of the async package); use withAsync or other safe helper utilities that the docs instruct to use instead.
  • Extract common code for functions that make requests.
    Most functions have very similar implementation:
    someFunctionality :: MonadIO m => ConsulClient -> FunctionalitySpecificRequestType -> m (Maybe FunctionalitySpecificResponseType)
    someFunctionality client@ConsulClient{..} request dc = do
      let hostnameWithScheme = hostWithScheme client
      initReq <- createRequest hostnameWithScheme
                               ccPort
                               "/v1/functionalitySpecificPath"
                               Nothing
                               (Just $ BL.toStrict $ encode request)
                               False
                               dc
      liftIO $ withResponse initReq ccManager $ \ response -> do
        case responseStatus response of
          x | x == status200 -> do
            bodyParts <- brConsume $ responseBody response
            return $ decode $ BL.fromStrict $ B.concat bodyParts
          _ -> return Nothing
    We should extract this common pattern into a helper function to make them easier to read.
  • Implement ACL support.
  • Add Github Actions based CI (Travis will discontinue OSS CI)
  • Add tests for all functions, ideally also including coverage reports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions