influxdb 1.6.0.9 → 1.6.1
raw patch · 11 files changed
+153/−42 lines, 11 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Database.InfluxDB.Format: instance (a ~ r) => Data.String.IsString (Database.InfluxDB.Format.Format a r)
- Database.InfluxDB.Types: instance GHC.Exception.Exception Database.InfluxDB.Types.InfluxException
+ Database.InfluxDB: secureServer :: Server
+ Database.InfluxDB.Format: instance (a Data.Type.Equality.~ r) => Data.String.IsString (Database.InfluxDB.Format.Format a r)
+ Database.InfluxDB.Types: instance GHC.Classes.Eq (Database.InfluxDB.Types.Precision a)
+ Database.InfluxDB.Types: instance GHC.Exception.Type.Exception Database.InfluxDB.Types.InfluxException
+ Database.InfluxDB.Types: secureServer :: Server
- Database.InfluxDB: Decoder :: Parser a -> Parser b -> Parser (Vector b) -> Parser (Vector a) -> Decoder a
+ Database.InfluxDB: Decoder :: (Parser a -> Parser b) -> (Parser (Vector b) -> Parser (Vector a)) -> Decoder a
- Database.InfluxDB: Line :: !Measurement -> !(Map Key Key) -> !(Map Key LineField) -> !(Maybe time) -> Line time
+ Database.InfluxDB: Line :: !Measurement -> !Map Key Key -> !Map Key LineField -> !Maybe time -> Line time
- Database.InfluxDB: newtype Tagged (s :: k) b :: forall k. () => k -> * -> *
+ Database.InfluxDB: newtype Tagged (s :: k) b :: forall k. () => k -> Type -> Type
- Database.InfluxDB.JSON: Decoder :: Parser a -> Parser b -> Parser (Vector b) -> Parser (Vector a) -> Decoder a
+ Database.InfluxDB.JSON: Decoder :: (Parser a -> Parser b) -> (Parser (Vector b) -> Parser (Vector a)) -> Decoder a
- Database.InfluxDB.Line: Line :: !Measurement -> !(Map Key Key) -> !(Map Key LineField) -> !(Maybe time) -> Line time
+ Database.InfluxDB.Line: Line :: !Measurement -> !Map Key Key -> !Map Key LineField -> !Maybe time -> Line time
- Database.InfluxDB.Query: newtype Tagged (s :: k) b :: forall k. () => k -> * -> *
+ Database.InfluxDB.Query: newtype Tagged (s :: k) b :: forall k. () => k -> Type -> Type
Files
- CHANGELOG.md +6/−0
- README.md +1/−1
- examples/write-udp.hs +2/−3
- influxdb.cabal +3/−2
- src/Database/InfluxDB.hs +3/−6
- src/Database/InfluxDB/Line.hs +1/−1
- src/Database/InfluxDB/Ping.hs +9/−3
- src/Database/InfluxDB/Query.hs +12/−4
- src/Database/InfluxDB/Types.hs +77/−16
- src/Database/InfluxDB/Write.hs +14/−4
- src/Database/InfluxDB/Write/UDP.hs +25/−2
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for influxdb +## v1.6.1 - 2018-11-20++* Add secureServer smart constructor for Server+* Test with InfluxDB 1.7.1 and newer GHCs including 8.6.2+* Enhace Haddock comments+ ## v1.6.0.9 - 2018-09-11 * Relax upper version bound for network
README.md view
@@ -4,7 +4,7 @@ [](http://packdeps.haskellers.com/feed?needle=influxdb) [](https://gitter.im/maoe/influxdb-haskell?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) -Currently this library is tested against InfluxDB 1.5.+Currently this library is tested against InfluxDB 1.7. ## Getting started
examples/write-udp.hs view
@@ -8,13 +8,12 @@ import Data.Time.Clock import Network.Socket -import Database.InfluxDB.Types-import Database.InfluxDB.Line+import Database.InfluxDB import qualified Database.InfluxDB.Write.UDP as UDP main :: IO () main = bracket (socket AF_INET Datagram defaultProtocol) close $ \sock -> do- localhost <- inet_addr "127.0.0.1"+ let localhost = tupleToHostAddress (127, 0, 0, 1) let params = UDP.writeParams sock $ SockAddrInet 8089 localhost tags1 = [ ("tag1", "A")
influxdb.cabal view
@@ -1,5 +1,5 @@ name: influxdb-version: 1.6.0.9+version: 1.6.1 synopsis: Haskell client library for InfluxDB description: @influxdb@ is a Haskell client library for InfluxDB.@@ -18,7 +18,8 @@ GHC == 7.10.3 GHC == 8.0.2 GHC == 8.2.2- GHC == 8.4.3+ GHC == 8.4.4+ GHC == 8.6.2 extra-source-files: README.md
src/Database/InfluxDB.hs view
@@ -79,6 +79,7 @@ , Server , defaultServer+ , secureServer , host , port , ssl@@ -214,12 +215,8 @@ {- $write InfluxDB has two ways to write data into it, via HTTP and UDP. This module-only exports functions for the HTTP API. For UDP, you can use a qualified-import:--@-import qualified "Database.InfluxDB.Write.UDP" as UDP-@+only exports functions for the HTTP API. For UDP, see+"Database.InfluxDB.Write.UDP". -} {- $query
src/Database/InfluxDB/Line.hs view
@@ -65,7 +65,7 @@ -- | Placeholder for the Line Protocol ----- See https://docs.influxdata.com/influxdb/v1.5/write_protocols/line_protocol_tutorial/ for the+-- See https://docs.influxdata.com/influxdb/v1.7/write_protocols/line_protocol_tutorial/ for the -- concrete syntax. data Line time = Line { _measurement :: !Measurement
src/Database/InfluxDB/Ping.hs view
@@ -36,6 +36,12 @@ -- Ping requests do not require authentication -- | The full set of parameters for the ping API+--+-- Following lenses are available to access its fields:+--+-- * 'server'+-- * 'manager'+-- * 'timeout' data PingParams = PingParams { pingServer :: !Server , pingManager :: !(Either HC.ManagerSettings HC.Manager)@@ -48,9 +54,9 @@ -- -- Default parameters: ----- ['L.server'] 'defaultServer'--- ['L.manager'] @'Left' 'HC.defaultManagerSettings'@--- ['L.timeout'] 'Nothing'+-- ['server'] 'defaultServer'+-- ['manager'] @'Left' 'HC.defaultManagerSettings'@+-- ['timeout'] 'Nothing' pingParams :: PingParams pingParams = PingParams { pingServer = defaultServer
src/Database/InfluxDB/Query.hs view
@@ -276,6 +276,14 @@ return (v1, v2, v3, v4, v5, v6, v7, v8) -- | The full set of parameters for the query API+--+-- Following lenses are available to access its fields:+--+-- * 'server'+-- * 'database'+-- * 'precision'+-- * 'authentication'+-- * 'manager' data QueryParams = QueryParams { queryServer :: !Server , queryDatabase :: !Database@@ -293,10 +301,10 @@ -- -- Default parameters: ----- ['L.server'] 'defaultServer'--- ['L.precision'] 'RFC3339'--- ['L.authentication'] 'Nothing'--- ['L.manager'] @'Left' 'HC.defaultManagerSettings'@+-- ['server'] 'defaultServer'+-- ['precision'] 'RFC3339'+-- ['authentication'] 'Nothing'+-- ['manager'] @'Left' 'HC.defaultManagerSettings'@ queryParams :: Database -> QueryParams queryParams queryDatabase = QueryParams { queryServer = defaultServer
src/Database/InfluxDB/Types.hs view
@@ -36,7 +36,7 @@ -- | An InfluxDB query. -- -- A spec of the format is available at--- <https://docs.influxdata.com/influxdb/v1.5/query_language/spec/>.+-- <https://docs.influxdata.com/influxdb/v1.7/query_language/spec/>. -- -- A 'Query' can be constructed using either --@@ -56,26 +56,19 @@ instance Show Query where show (Query q) = show q +-- | InfluxDB server to connect to.+--+-- Following lenses are available to access its fields:+--+-- * 'host': FQDN or IP address of the InfluxDB server+-- * 'port': Port number of the InfluxDB server+-- * 'ssl': Whether or not to use SSL data Server = Server { _host :: !Text , _port :: !Int , _ssl :: !Bool } deriving (Show, Generic, Eq, Ord) --- | Default server settings.------ Default parameters:------ * 'host': @"localhost"@--- * 'port': @8086@--- * 'ssl': 'False'-defaultServer :: Server-defaultServer = Server- { _host = "localhost"- , _port = 8086- , _ssl = False- }- makeLensesWith (lensRules & generateSignatures .~ False) ''Server -- | Host name of the server@@ -85,14 +78,46 @@ port :: Lens' Server Int -- | If SSL is enabled+--+-- For secure connections (HTTPS), consider using one of the following packages:+--+-- * [http-client-tls](https://hackage.haskell.org/package/http-client-tls)+-- * [http-client-openssl](https://hackage.haskell.org/package/http-client-openssl) ssl :: Lens' Server Bool --- | User credentials+-- | Default InfluxDB server settings+--+-- Default parameters:+--+-- >>> defaultServer ^. host+-- "localhost"+-- >>> defaultServer ^. port+-- 8086+-- >>> defaultServer ^. ssl+-- False+defaultServer :: Server+defaultServer = Server+ { _host = "localhost"+ , _port = 8086+ , _ssl = False+ }++-- | HTTPS-enabled InfluxDB server settings+secureServer :: Server+secureServer = defaultServer & ssl .~ True++-- | User credentials.+--+-- Following lenses are available to access its fields:+--+-- * 'user'+-- * 'password' data Credentials = Credentials { _user :: !Text , _password :: !Text } deriving Show +-- | Smart constructor for 'Credentials' credentials :: Text -- ^ User name -> Text -- ^ Password@@ -109,6 +134,10 @@ user :: Lens' Credentials Text -- | Password to access InfluxDB+--+-- >>> let creds = credentials "john" "passw0rd"+-- >>> creds ^. password+-- "passw0rd" password :: Lens' Credentials Text -- | Database name.@@ -152,6 +181,9 @@ | elem '\n' xs = error $ ty ++ " should not contain a new line" | otherwise = fromString xs +-- | Nullability of fields.+--+-- Queries can contain nulls but the line protocol cannot. data Nullability = Nullable | NonNullable deriving Typeable -- | Field type for queries. Queries can contain null values.@@ -162,10 +194,21 @@ type LineField = Field 'NonNullable data Field (n :: Nullability) where+ -- | Signed 64-bit integers (@-9,223,372,036,854,775,808@ to+ -- @9,223,372,036,854,775,807@). FieldInt :: !Int64 -> Field n+ -- | IEEE-754 64-bit floating-point numbers. This is the default numerical+ -- type. FieldFloat :: !Double -> Field n+ -- | String field. Its length is limited to 64KB, which is not enforced by+ -- this library. FieldString :: !Text -> Field n+ -- | Boolean field. FieldBool :: !Bool -> Field n+ -- | Null field.+ --+ -- Note that a field can be null only in queries. The line protocol doesn't+ -- allow null values. FieldNull :: Field 'Nullable deriving Typeable @@ -204,11 +247,24 @@ RFC3339 :: Precision 'QueryRequest deriving instance Show (Precision a)+deriving instance Eq (Precision a) -- | Name of the time precision. -- -- >>> precisionName Nanosecond -- "n"+-- >>> precisionName Microsecond+-- "u"+-- >>> precisionName Millisecond+-- "ms"+-- >>> precisionName Second+-- "s"+-- >>> precisionName Minute+-- "m"+-- >>> precisionName Hour+-- "h"+-- >>> precisionName RFC3339+-- "rfc3339" precisionName :: Precision ty -> Text precisionName = \case Nanosecond -> "n"@@ -378,18 +434,22 @@ instance Exception InfluxException +-- | Class of data types that have a server field class HasServer a where -- | InfluxDB server address and port that to interact with. server :: Lens' a Server +-- | Class of data types that have a database field class HasDatabase a where -- | Database name to work on. database :: Lens' a Database +-- | Class of data types that have a precision field class HasPrecision (ty :: RequestType) a | a -> ty where -- | Time precision parameter. precision :: Lens' a (Precision ty) +-- | Class of data types that have a manager field class HasManager a where -- | HTTP manager settings or a manager itself. --@@ -397,6 +457,7 @@ -- the settings for you. manager :: Lens' a (Either ManagerSettings Manager) +-- | Class of data types that has an authentication field class HasCredentials a where -- | User name and password to be used when sending requests to InfluxDB. authentication :: Lens' a (Maybe Credentials)
src/Database/InfluxDB/Write.hs view
@@ -46,7 +46,7 @@ import Database.InfluxDB.JSON -- $setup--- >>> :set -XOverloadedStrings+-- >>> :set -XOverloadedStrings -XNoOverloadedLists -- >>> import qualified Data.Map as Map -- >>> import Data.Time -- >>> import Database.InfluxDB@@ -62,6 +62,15 @@ -} -- | The full set of parameters for the HTTP writer.+--+-- Following lenses are available to access its fields:+--+-- * 'server'+-- * 'database'+-- * 'retentionPolicy'+-- * 'precision'+-- * 'authentication'+-- * 'manager' data WriteParams = WriteParams { writeServer :: !Server , writeDatabase :: !Database@@ -82,10 +91,11 @@ -- -- Default parameters: ----- ['L.server'] 'defaultServer'--- ['L.precision'] 'Nanosecond'+-- ['server'] 'defaultServer' -- ['retentionPolicy'] 'Nothing'--- ['L.manager'] @'Left' 'HC.defaultManagerSettings'@+-- ['precision'] 'Nanosecond'+-- ['authentication'] 'Nothing'+-- ['manager'] @'Left' 'HC.defaultManagerSettings'@ writeParams :: Database -> WriteParams writeParams writeDatabase = WriteParams { writeServer = defaultServer
src/Database/InfluxDB/Write/UDP.hs view
@@ -4,7 +4,9 @@ {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TemplateHaskell #-} module Database.InfluxDB.Write.UDP- ( -- * Writers+ ( -- $intro++ -- * Writers write , writeBatch , writeByteString@@ -25,6 +27,27 @@ import Database.InfluxDB.Line import Database.InfluxDB.Types as Types +{- $intro+This module is desined to be used with the [network]+(https://hackage.haskell.org/package/network) package and be imported qualified.++>>> :set -XOverloadedStrings -XOverloadedLists+>>> import Data.Time+>>> import Network.Socket+>>> import Database.InfluxDB+>>> import qualified Database.InfluxDB.Write.UDP as UDP+>>> sock <- Network.Socket.socket AF_INET Datagram defaultProtocol+>>> let localhost = tupleToHostAddress (127, 0, 0, 1)+>>> let params = UDP.writeParams sock $ SockAddrInet 8089 localhost+>>> UDP.write params $ Line "measurement1" [] [("value", FieldInt 42)] (Nothing :: Maybe UTCTime)+>>> close sock++Make sure that the UDP service is enabled in the InfluxDB config. This API+doesn't tell you if any error occurs. See [the official doc]+(https://docs.influxdata.com/influxdb/v1.6/supported_protocols/udp/) for+details.+-}+ -- | The full set of parameters for the UDP writer. data WriteParams = WriteParams { _socket :: !Socket@@ -63,7 +86,7 @@ writeBatch p@WriteParams {_precision} = writeByteString p . encodeLines (roundTo _precision) --- | Write a raw 'L.ByteString'+-- | Write a lazy 'L.ByteString' writeByteString :: WriteParams -> BL.ByteString -> IO () writeByteString WriteParams {..} payload = sendManyTo _socket (BL.toChunks payload) _sockAddr