summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitsutoshiAoe <>2018-11-20 03:21:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-11-20 03:21:00 (GMT)
commit5f5d3a7d37983710a1454700a2f9b43a6388d8a7 (patch)
tree3a13b0e4c896d4180045e3fa72e132c045b0f93a
parentaff1829a144344ec8bd34531b6ae9908a9cdc822 (diff)
version 1.6.11.6.1
-rwxr-xr-xCHANGELOG.md6
-rwxr-xr-xREADME.md2
-rw-r--r--examples/write-udp.hs5
-rw-r--r--influxdb.cabal5
-rw-r--r--src/Database/InfluxDB.hs9
-rw-r--r--src/Database/InfluxDB/Line.hs2
-rw-r--r--src/Database/InfluxDB/Ping.hs12
-rw-r--r--src/Database/InfluxDB/Query.hs16
-rw-r--r--src/Database/InfluxDB/Types.hs93
-rw-r--r--src/Database/InfluxDB/Write.hs18
-rw-r--r--src/Database/InfluxDB/Write/UDP.hs27
11 files changed, 153 insertions, 42 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 57b8869..11ca2f6 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/README.md b/README.md
index 00a660d..69db7c6 100755
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
[![Hackage-Deps](https://img.shields.io/hackage-deps/v/influxdb.svg)](http://packdeps.haskellers.com/feed?needle=influxdb)
[![Gitter](https://badges.gitter.im/maoe/influxdb-haskell.svg)](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
diff --git a/examples/write-udp.hs b/examples/write-udp.hs
index 490c50a..afc37d5 100644
--- a/examples/write-udp.hs
+++ b/examples/write-udp.hs
@@ -8,13 +8,12 @@ import Control.Lens
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")
diff --git a/influxdb.cabal b/influxdb.cabal
index ce6b3bc..5c5e244 100644
--- a/influxdb.cabal
+++ b/influxdb.cabal
@@ -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 @@ tested-with:
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
diff --git a/src/Database/InfluxDB.hs b/src/Database/InfluxDB.hs
index bbdb6bf..58455ae 100644
--- a/src/Database/InfluxDB.hs
+++ b/src/Database/InfluxDB.hs
@@ -79,6 +79,7 @@ module Database.InfluxDB
, Server
, defaultServer
+ , secureServer
, host
, port
, ssl
@@ -214,12 +215,8 @@ instance QueryResults CPUUsage where
{- $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
diff --git a/src/Database/InfluxDB/Line.hs b/src/Database/InfluxDB/Line.hs
index fec76d8..af88ec1 100644
--- a/src/Database/InfluxDB/Line.hs
+++ b/src/Database/InfluxDB/Line.hs
@@ -65,7 +65,7 @@ let l1 = Line "cpu_usage"
-- | 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
diff --git a/src/Database/InfluxDB/Ping.hs b/src/Database/InfluxDB/Ping.hs
index 08567c1..83b379e 100644
--- a/src/Database/InfluxDB/Ping.hs
+++ b/src/Database/InfluxDB/Ping.hs
@@ -36,6 +36,12 @@ import Database.InfluxDB.Types as Types
-- 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 @@ data PingParams = PingParams
--
-- 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
diff --git a/src/Database/InfluxDB/Query.hs b/src/Database/InfluxDB/Query.hs
index 5c8cba0..988012b 100644
--- a/src/Database/InfluxDB/Query.hs
+++ b/src/Database/InfluxDB/Query.hs
@@ -276,6 +276,14 @@ instance
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 @@ data QueryParams = QueryParams
--
-- 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
diff --git a/src/Database/InfluxDB/Types.hs b/src/Database/InfluxDB/Types.hs
index 96bab6d..52b3330 100644
--- a/src/Database/InfluxDB/Types.hs
+++ b/src/Database/InfluxDB/Types.hs
@@ -36,7 +36,7 @@ import qualified Network.HTTP.Client as HC
-- | 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 @@ newtype Query = Query T.Text deriving IsString
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 @@ host :: Lens' Server Text
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 @@ makeLensesWith (lensRules & generateSignatures .~ False) ''Credentials
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 @@ identifier ty xs
| 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 QueryField = Field 'Nullable
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 @@ data Precision (ty :: RequestType) where
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 @@ data InfluxException
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 @@ class HasManager a where
-- 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)
diff --git a/src/Database/InfluxDB/Write.hs b/src/Database/InfluxDB/Write.hs
index 56761ce..04a1f25 100644
--- a/src/Database/InfluxDB/Write.hs
+++ b/src/Database/InfluxDB/Write.hs
@@ -46,7 +46,7 @@ import Database.InfluxDB.Types as Types
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 @@ import Data.Time
-}
-- | 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 @@ data WriteParams = WriteParams
--
-- 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
diff --git a/src/Database/InfluxDB/Write/UDP.hs b/src/Database/InfluxDB/Write/UDP.hs
index 450bfc8..def9752 100644
--- a/src/Database/InfluxDB/Write/UDP.hs
+++ b/src/Database/InfluxDB/Write/UDP.hs
@@ -4,7 +4,9 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
module Database.InfluxDB.Write.UDP
- ( -- * Writers
+ ( -- $intro
+
+ -- * Writers
write
, writeBatch
, writeByteString
@@ -25,6 +27,27 @@ import qualified Data.ByteString.Lazy as BL
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
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