-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | ElasticSearch scribe for the Katip logging framework.
--   
--   See README.md for more details.
@package katip-elasticsearch
@version 0.4.0.0

module Katip.Scribes.ElasticSearch.Annotations

-- | Represents a value that can be converted to and from JSON that will
--   type annotate object keys when serializing and strip them out when
--   deserializating
newtype TypeAnnotated a
TypeAnnotated :: a -> TypeAnnotated a
[typeAnnotatedValue] :: TypeAnnotated a -> a
deannotateValue :: Value -> Value
instance Data.Aeson.Types.ToJSON.ToJSON a => Data.Aeson.Types.ToJSON.ToJSON (Katip.Scribes.ElasticSearch.Annotations.TypeAnnotated a)
instance Katip.Core.ToObject a => Katip.Core.ToObject (Katip.Scribes.ElasticSearch.Annotations.TypeAnnotated a)
instance Data.Aeson.Types.FromJSON.FromJSON a => Data.Aeson.Types.FromJSON.FromJSON (Katip.Scribes.ElasticSearch.Annotations.TypeAnnotated a)
instance Katip.Core.LogItem a => Katip.Core.LogItem (Katip.Scribes.ElasticSearch.Annotations.TypeAnnotated a)


-- | This is an internal module. No guarantees are made in this module
--   about API stability.
module Katip.Scribes.ElasticSearch.Internal

-- | EsScribeCfg now carries a type variable for the version of
--   ElasticSearch it targets, either <a>ESV1</a> or <a>ESV5</a>. You can
--   use <a>defaultEsScribeCfgV1</a> and <tt>defaultESScribeCfgV5</tt> for
--   a good starting point depending on the ES version you have.
data EsScribeCfg v
EsScribeCfg :: RetryPolicy -> EsQueueSize -> EsPoolSize -> Bool -> IndexSettings v -> IndexShardingPolicy -> EsScribeCfg v

-- | Retry policy when there are errors sending logs to the server
[essRetryPolicy] :: EsScribeCfg v -> RetryPolicy

-- | Maximum size of the bounded log queue
[essQueueSize] :: EsScribeCfg v -> EsQueueSize

-- | Worker pool size limit for sending data to the
[essPoolSize] :: EsScribeCfg v -> EsPoolSize

-- | Different payload items coexist in the "data" attribute in ES. It is
--   possible for different payloads to have different types for the same
--   key, e.g. an "id" key that is sometimes a number and sometimes a
--   string. If you're having ES do dynamic mapping, the first log item
--   will set the type and any that don't conform will be *discarded*. If
--   you set this to True, keys will recursively be appended with their ES
--   core type. e.g. "id" would become "id::l" and "id::s" automatically,
--   so they won't conflict. When this library exposes a querying API, we
--   will try to make deserialization and querying transparently remove the
--   type annotations if this is enabled.
[essAnnotateTypes] :: EsScribeCfg v -> Bool

-- | This will be the IndexSettings type from the appropriate bloodhound
--   module, either <tt>Database.V1.Bloodhound</tt> or
--   <tt>Database.V5.Bloodhound</tt>
[essIndexSettings] :: EsScribeCfg v -> IndexSettings v
[essIndexSharding] :: EsScribeCfg v -> IndexShardingPolicy

-- | Reasonable defaults for a config:
--   
--   <ul>
--   <li>defaultManagerSettings</li>
--   <li>exponential backoff with 25ms base delay up to 5 retries</li>
--   <li>Queue size of 1000</li>
--   <li>Pool size of 2</li>
--   <li>Annotate types set to False</li>
--   <li>DailyIndexSharding</li>
--   </ul>
defaultEsScribeCfg' :: ESVersion v => proxy v -> EsScribeCfg v

-- | Alias of <a>defaultEsScribeCfgV1</a> to minimize API breakage.
--   Previous versions of katip-elasticsearch only supported ES version 1.
defaultEsScribeCfg :: EsScribeCfg ESV1

-- | EsScribeCfg that will use ElasticSearch V1
defaultEsScribeCfgV1 :: EsScribeCfg ESV1

-- | EsScribeCfg that will use ElasticSearch V5
defaultEsScribeCfgV5 :: EsScribeCfg ESV5

-- | How should katip store your log data?
--   
--   <ul>
--   <li>NoIndexSharding will store all logs in one index name. This is the
--   simplest option but is not advised in production. In practice, the
--   index will grow very large and will get slower to search. Deleting
--   records based on some sort of retention period is also extremely
--   slow.</li>
--   <li>MonthlyIndexSharding, DailyIndexSharding, HourlyIndexSharding,
--   EveryMinuteIndexSharding will generate indexes based on the time of
--   the log. Index name is treated as a prefix. So if your index name is
--   <tt>foo</tt> and DailySharding is used, logs will be stored in
--   <tt>foo-2016-2-25</tt>, <tt>foo-2016-2-26</tt> and so on. Index
--   templating will be used to set up mappings automatically. Deletes
--   based on date are very fast and queries can be restricted to date
--   ranges for better performance. Queries against all dates should use
--   <tt>foo-*</tt> as an index name. Note that index aliasing's glob
--   feature is not suitable for these date ranges as it matches index
--   names as they are declared, so new dates will be excluded.
--   DailyIndexSharding is a reasonable choice. Changing index sharding
--   strategies is not advisable.</li>
--   <li>CustomSharding: supply your own function that decomposes an item
--   into its index name hierarchy which will be appended to the index
--   name. So for instance if your function return ["arbitrary", "prefix"],
--   the index will be <tt>foo-arbitrary-prefix</tt> and the index template
--   will be set to match <tt>foo-*</tt>. In general, you want to use
--   segments of increasing granularity (like year, month, day for dates).
--   This makes it easier to address groups of indexes (e.g.
--   <tt>foo-2016-*</tt>).</li>
--   </ul>
data IndexShardingPolicy
NoIndexSharding :: IndexShardingPolicy
MonthlyIndexSharding :: IndexShardingPolicy

-- | A special case of daily which shards to sunday
WeeklyIndexSharding :: IndexShardingPolicy
DailyIndexSharding :: IndexShardingPolicy
HourlyIndexSharding :: IndexShardingPolicy
EveryMinuteIndexSharding :: IndexShardingPolicy
CustomIndexSharding :: (forall a. Item a -> [IndexNameSegment]) -> IndexShardingPolicy
newtype IndexNameSegment
IndexNameSegment :: Text -> IndexNameSegment
[indexNameSegment] :: IndexNameSegment -> Text
shardPolicySegs :: IndexShardingPolicy -> Item a -> [IndexNameSegment]

-- | If the given day is sunday, returns the input, otherwise returns the
--   previous sunday
roundToSunday :: Day -> Day
chooseIxn :: ESVersion v => proxy v -> IndexName v -> IndexShardingPolicy -> Item a -> IndexName v
sis :: Integral a => a -> IndexNameSegment
splitTime :: DiffTime -> (Int, Int)
data EsScribeSetupError
CouldNotCreateIndex :: !(Response ByteString) -> EsScribeSetupError
CouldNotCreateMapping :: !(Response ByteString) -> EsScribeSetupError

-- | The Any field tagged with a <tt>v</tt> corresponds to the type of the
--   same name in the corresponding <tt>bloodhound</tt> module. For
--   instance, if you are configuring for ElasticSearch version 1, import
--   <tt>Database.V1.Bloodhound</tt> and <tt>BHEnv v</tt> will refer to
--   <tt>BHEnv</tt> from that module, <tt>IndexName v</tt> will repsond to
--   <tt>IndexName</tt> from that module, etc.
mkEsScribe :: forall v. (ESVersion v, MonadIO (BH v IO)) => EsScribeCfg v -> BHEnv v -> IndexName v -> MappingName v -> Severity -> Verbosity -> IO Scribe
baseMapping :: ESVersion v => proxy v -> MappingName v -> Value

-- | Handle both old-style aeson and picosecond-level precision
esDateFormat :: Text
mkDocId :: ESVersion v => proxy v -> IO (DocId v)
newtype EsQueueSize
EsQueueSize :: Int -> EsQueueSize
[unEsQueueSize] :: EsQueueSize -> Int
mkEsQueueSize :: Int -> Maybe EsQueueSize
newtype EsPoolSize
EsPoolSize :: Int -> EsPoolSize
[unEsPoolSize] :: EsPoolSize -> Int
mkEsPoolSize :: Int -> Maybe EsPoolSize
mkNonZero :: (Int -> a) -> Int -> Maybe a
startWorker :: forall v. (ESVersion v) => EsScribeCfg v -> BHEnv v -> MappingName v -> TBMQueue (IndexName v, Value) -> IO ()
class ESVersion v where type BHEnv v type IndexSettings v type IndexName v type MappingName v type DocId v type BH v :: (* -> *) -> * -> * type TemplateName v type TemplatePattern v type IndexTemplate v type IndexDocumentSettings v where {
    type family BHEnv v;
    type family IndexSettings v;
    type family IndexName v;
    type family MappingName v;
    type family DocId v;
    type family BH v :: (* -> *) -> * -> *;
    type family TemplateName v;
    type family TemplatePattern v;
    type family IndexTemplate v;
    type family IndexDocumentSettings v;
}
defaultIndexSettings :: ESVersion v => proxy v -> IndexSettings v
toIndexName :: ESVersion v => proxy v -> Text -> IndexName v
fromIndexName :: ESVersion v => proxy v -> IndexName v -> Text
fromMappingName :: ESVersion v => proxy v -> MappingName v -> Text
toDocId :: ESVersion v => proxy v -> Text -> DocId v
runBH :: ESVersion v => proxy v -> BHEnv v -> BH v m a -> m a
toTemplateName :: ESVersion v => proxy v -> Text -> TemplateName v
toTemplatePattern :: ESVersion v => proxy v -> Text -> TemplatePattern v
toIndexTemplate :: ESVersion v => proxy v -> TemplatePattern v -> Maybe (IndexSettings v) -> [Value] -> IndexTemplate v
defaultIndexDocumentSettings :: ESVersion v => proxy v -> IndexDocumentSettings v
indexExists :: ESVersion v => proxy v -> IndexName v -> BH v IO Bool
indexDocument :: (ESVersion v, ToJSON doc) => proxy v -> IndexName v -> MappingName v -> IndexDocumentSettings v -> doc -> DocId v -> BH v IO (Response ByteString)
createIndex :: ESVersion v => proxy v -> IndexSettings v -> IndexName v -> BH v IO (Response ByteString)
putTemplate :: ESVersion v => proxy v -> IndexTemplate v -> TemplateName v -> BH v IO (Response ByteString)
putMapping :: (ESVersion v, ToJSON a) => proxy v -> IndexName v -> MappingName v -> a -> BH v IO (Response ByteString)
data ESV1
ESV1 :: ESV1
data ESV5
ESV5 :: ESV5
instance GHC.Classes.Ord Katip.Scribes.ElasticSearch.Internal.EsPoolSize
instance GHC.Classes.Eq Katip.Scribes.ElasticSearch.Internal.EsPoolSize
instance GHC.Show.Show Katip.Scribes.ElasticSearch.Internal.EsPoolSize
instance GHC.Classes.Ord Katip.Scribes.ElasticSearch.Internal.EsQueueSize
instance GHC.Classes.Eq Katip.Scribes.ElasticSearch.Internal.EsQueueSize
instance GHC.Show.Show Katip.Scribes.ElasticSearch.Internal.EsQueueSize
instance GHC.Show.Show Katip.Scribes.ElasticSearch.Internal.EsScribeSetupError
instance GHC.Classes.Ord Katip.Scribes.ElasticSearch.Internal.IndexNameSegment
instance GHC.Classes.Eq Katip.Scribes.ElasticSearch.Internal.IndexNameSegment
instance GHC.Show.Show Katip.Scribes.ElasticSearch.Internal.IndexNameSegment
instance GHC.Show.Show Katip.Scribes.ElasticSearch.Internal.IndexShardingPolicy
instance GHC.Exception.Exception Katip.Scribes.ElasticSearch.Internal.EsScribeSetupError
instance GHC.Enum.Bounded Katip.Scribes.ElasticSearch.Internal.EsQueueSize
instance GHC.Enum.Bounded Katip.Scribes.ElasticSearch.Internal.EsPoolSize
instance Katip.Scribes.ElasticSearch.Internal.ESVersion Katip.Scribes.ElasticSearch.Internal.ESV1
instance Katip.Scribes.ElasticSearch.Internal.ESVersion Katip.Scribes.ElasticSearch.Internal.ESV5


-- | Includes a scribe that can be used to log structured, JSON log
--   messages to ElasticSearch. These logs can be explored easily using
--   <a>kibana</a> or your tool of choice. Supports ElasticSearch servers
--   with version 1.x or 5.x by way of different configs.
--   
--   Example of configuring for ES5:
--   
--   <pre>
--   import           Control.Exception
--   import           Database.V5.Bloodhound
--   import           Network.HTTP.Client
--   import           Katip
--   import           Katip.Scribes.ElasticSearch
--   
--   
--   main :: IO ()
--   main = do
--     mgr &lt;- newManager defaultManagerSettings
--     let bhe = mkBHEnv (Server "localhost") mgr
--     esScribe &lt;- mkEsScribe
--       -- Reasonable for production
--       defaultEsScribeCfgV5
--       -- Reasonable for single-node in development
--       -- defaultEsScribeCfgV5 { essIndexSettings = IndexSettings (ShardCound 1) (ReplicaCount 0)}
--       bhe
--       (IndexName "all-indices-prefixed-with")
--       (MappingName "application-logs")
--       DebugS
--       V3
--     let mkLogEnv = registerScribe "es" esScribe defaultScribeSettings =&lt;&lt; initLogEnv <a>MyApp</a> "production"
--     bracket mkLogEnv closeScribes $ le -&gt; runKatipT le $ do
--       logMsg "ns" InfoS "This goes to elasticsearch"
--   </pre>
--   
--   <b>Important Note on Index Settings</b>
--   
--   <a>defaultEsScribeCfg</a> inherits a set of default index settings
--   from the <tt>bloodhound</tt> package. These settings at this time of
--   writing set the indices up to have 3 shards and 2 replicas. This is an
--   arguably reasonable default setting for production but may cause
--   problems for development. In development, your cluster may be
--   configured to seek a write quorum greater than 1. If you're running
--   ElasticSearch on a single node, this could cause your writes to wait
--   for a bit and then fail due to a lack of quorum. <b>For development,
--   we recommend setting your replica count to 0 or modifying your write
--   quorum settings</b>. For production, we recommend reading the
--   <a>ElasticSearch Scaling Guide</a> and choosing the appropriate
--   settings, keeping in mind that you can chage replica counts on a live
--   index but that changing shard counts requires recreating the index.
module Katip.Scribes.ElasticSearch

-- | The Any field tagged with a <tt>v</tt> corresponds to the type of the
--   same name in the corresponding <tt>bloodhound</tt> module. For
--   instance, if you are configuring for ElasticSearch version 1, import
--   <tt>Database.V1.Bloodhound</tt> and <tt>BHEnv v</tt> will refer to
--   <tt>BHEnv</tt> from that module, <tt>IndexName v</tt> will repsond to
--   <tt>IndexName</tt> from that module, etc.
mkEsScribe :: forall v. (ESVersion v, MonadIO (BH v IO)) => EsScribeCfg v -> BHEnv v -> IndexName v -> MappingName v -> Severity -> Verbosity -> IO Scribe
data EsScribeSetupError
CouldNotCreateIndex :: !(Response ByteString) -> EsScribeSetupError
CouldNotCreateMapping :: !(Response ByteString) -> EsScribeSetupError
data EsQueueSize
mkEsQueueSize :: Int -> Maybe EsQueueSize
data EsPoolSize
mkEsPoolSize :: Int -> Maybe EsPoolSize

-- | How should katip store your log data?
--   
--   <ul>
--   <li>NoIndexSharding will store all logs in one index name. This is the
--   simplest option but is not advised in production. In practice, the
--   index will grow very large and will get slower to search. Deleting
--   records based on some sort of retention period is also extremely
--   slow.</li>
--   <li>MonthlyIndexSharding, DailyIndexSharding, HourlyIndexSharding,
--   EveryMinuteIndexSharding will generate indexes based on the time of
--   the log. Index name is treated as a prefix. So if your index name is
--   <tt>foo</tt> and DailySharding is used, logs will be stored in
--   <tt>foo-2016-2-25</tt>, <tt>foo-2016-2-26</tt> and so on. Index
--   templating will be used to set up mappings automatically. Deletes
--   based on date are very fast and queries can be restricted to date
--   ranges for better performance. Queries against all dates should use
--   <tt>foo-*</tt> as an index name. Note that index aliasing's glob
--   feature is not suitable for these date ranges as it matches index
--   names as they are declared, so new dates will be excluded.
--   DailyIndexSharding is a reasonable choice. Changing index sharding
--   strategies is not advisable.</li>
--   <li>CustomSharding: supply your own function that decomposes an item
--   into its index name hierarchy which will be appended to the index
--   name. So for instance if your function return ["arbitrary", "prefix"],
--   the index will be <tt>foo-arbitrary-prefix</tt> and the index template
--   will be set to match <tt>foo-*</tt>. In general, you want to use
--   segments of increasing granularity (like year, month, day for dates).
--   This makes it easier to address groups of indexes (e.g.
--   <tt>foo-2016-*</tt>).</li>
--   </ul>
data IndexShardingPolicy
NoIndexSharding :: IndexShardingPolicy
MonthlyIndexSharding :: IndexShardingPolicy

-- | A special case of daily which shards to sunday
WeeklyIndexSharding :: IndexShardingPolicy
DailyIndexSharding :: IndexShardingPolicy
HourlyIndexSharding :: IndexShardingPolicy
EveryMinuteIndexSharding :: IndexShardingPolicy
CustomIndexSharding :: (forall a. Item a -> [IndexNameSegment]) -> IndexShardingPolicy
newtype IndexNameSegment
IndexNameSegment :: Text -> IndexNameSegment
[indexNameSegment] :: IndexNameSegment -> Text

-- | EsScribeCfg now carries a type variable for the version of
--   ElasticSearch it targets, either <a>ESV1</a> or <a>ESV5</a>. You can
--   use <a>defaultEsScribeCfgV1</a> and <tt>defaultESScribeCfgV5</tt> for
--   a good starting point depending on the ES version you have.
data EsScribeCfg v

-- | Retry policy when there are errors sending logs to the server
essRetryPolicy :: EsScribeCfg v -> RetryPolicy

-- | Maximum size of the bounded log queue
essQueueSize :: EsScribeCfg v -> EsQueueSize

-- | Worker pool size limit for sending data to the
essPoolSize :: EsScribeCfg v -> EsPoolSize

-- | Different payload items coexist in the "data" attribute in ES. It is
--   possible for different payloads to have different types for the same
--   key, e.g. an "id" key that is sometimes a number and sometimes a
--   string. If you're having ES do dynamic mapping, the first log item
--   will set the type and any that don't conform will be *discarded*. If
--   you set this to True, keys will recursively be appended with their ES
--   core type. e.g. "id" would become "id::l" and "id::s" automatically,
--   so they won't conflict. When this library exposes a querying API, we
--   will try to make deserialization and querying transparently remove the
--   type annotations if this is enabled.
essAnnotateTypes :: EsScribeCfg v -> Bool

-- | This will be the IndexSettings type from the appropriate bloodhound
--   module, either <tt>Database.V1.Bloodhound</tt> or
--   <tt>Database.V5.Bloodhound</tt>
essIndexSettings :: EsScribeCfg v -> IndexSettings v
essIndexSharding :: EsScribeCfg v -> IndexShardingPolicy

-- | Alias of <a>defaultEsScribeCfgV1</a> to minimize API breakage.
--   Previous versions of katip-elasticsearch only supported ES version 1.
defaultEsScribeCfg :: EsScribeCfg ESV1

-- | EsScribeCfg that will use ElasticSearch V1
defaultEsScribeCfgV1 :: EsScribeCfg ESV1

-- | EsScribeCfg that will use ElasticSearch V5
defaultEsScribeCfgV5 :: EsScribeCfg ESV5

-- | Reasonable defaults for a config:
--   
--   <ul>
--   <li>defaultManagerSettings</li>
--   <li>exponential backoff with 25ms base delay up to 5 retries</li>
--   <li>Queue size of 1000</li>
--   <li>Pool size of 2</li>
--   <li>Annotate types set to False</li>
--   <li>DailyIndexSharding</li>
--   </ul>
defaultEsScribeCfg' :: ESVersion v => proxy v -> EsScribeCfg v
data ESV1
data ESV5
mkDocId :: ESVersion v => proxy v -> IO (DocId v)
