{- |
 Module      :  OpenTelemetry.Resource.Kubernetes
 Copyright   :  (c) Ian Duncan, 2021
 License     :  BSD-3
 Description :  Information about how and where a process is running in a k8s cluster
 Maintainer  :  Ian Duncan
 Stability   :  experimental
 Portability :  non-portable (GHC extensions)
-}
module OpenTelemetry.Resource.Kubernetes where

import Data.Text (Text)
import OpenTelemetry.Attributes.Key (unkey)
import OpenTelemetry.Resource
import qualified OpenTelemetry.SemanticConventions as SC


{- | A Kubernetes Cluster.

@since 0.0.1.0
-}
data Cluster = Cluster
  { Cluster -> Maybe Text
clusterName :: Maybe Text
  -- ^ The name of the cluster.
  , Cluster -> Maybe Text
clusterUid :: Maybe Text
  -- ^ The UID of the cluster.
  }
  deriving (Int -> Cluster -> ShowS
[Cluster] -> ShowS
Cluster -> String
(Int -> Cluster -> ShowS)
-> (Cluster -> String) -> ([Cluster] -> ShowS) -> Show Cluster
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Cluster -> ShowS
showsPrec :: Int -> Cluster -> ShowS
$cshow :: Cluster -> String
show :: Cluster -> String
$cshowList :: [Cluster] -> ShowS
showList :: [Cluster] -> ShowS
Show)


instance ToResource Cluster where
  toResource :: Cluster -> Resource
toResource Cluster {Maybe Text
clusterName :: Cluster -> Maybe Text
clusterUid :: Cluster -> Maybe Text
clusterName :: Maybe Text
clusterUid :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_cluster_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
clusterName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_cluster_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
clusterUid
      ]


{- | A Kubernetes Node.

@since 0.0.1.0
-}
data Node = Node
  { Node -> Maybe Text
nodeName :: Maybe Text
  , Node -> Maybe Text
nodeUid :: Maybe Text
  }
  deriving (Int -> Node -> ShowS
[Node] -> ShowS
Node -> String
(Int -> Node -> ShowS)
-> (Node -> String) -> ([Node] -> ShowS) -> Show Node
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Node -> ShowS
showsPrec :: Int -> Node -> ShowS
$cshow :: Node -> String
show :: Node -> String
$cshowList :: [Node] -> ShowS
showList :: [Node] -> ShowS
Show)


instance ToResource Node where
  toResource :: Node -> Resource
toResource Node {Maybe Text
nodeName :: Node -> Maybe Text
nodeUid :: Node -> Maybe Text
nodeName :: Maybe Text
nodeUid :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_node_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
nodeName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_node_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
nodeUid
      ]


{- | Namespaces provide a scope for names. Names of objects need to be unique within a namespace, but not across namespaces.

@since 0.0.1.0
-}
newtype Namespace = Namespace
  { Namespace -> Maybe Text
namespaceName :: Maybe Text
  -- ^ The name of the namespace that the pod is running in.
  }
  deriving (Int -> Namespace -> ShowS
[Namespace] -> ShowS
Namespace -> String
(Int -> Namespace -> ShowS)
-> (Namespace -> String)
-> ([Namespace] -> ShowS)
-> Show Namespace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Namespace -> ShowS
showsPrec :: Int -> Namespace -> ShowS
$cshow :: Namespace -> String
show :: Namespace -> String
$cshowList :: [Namespace] -> ShowS
showList :: [Namespace] -> ShowS
Show)


instance ToResource Namespace where
  toResource :: Namespace -> Resource
toResource Namespace {Maybe Text
namespaceName :: Namespace -> Maybe Text
namespaceName :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_namespace_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
namespaceName
      ]


{- | The smallest and simplest Kubernetes object. A Pod represents a set of running containers on your cluster.

@since 0.0.1.0
-}
data Pod = Pod
  { Pod -> Maybe Text
podName :: Maybe Text
  -- ^ The name of the Pod.
  , Pod -> Maybe Text
podUid :: Maybe Text
  -- ^ The UID of the Pod.
  }
  deriving (Int -> Pod -> ShowS
[Pod] -> ShowS
Pod -> String
(Int -> Pod -> ShowS)
-> (Pod -> String) -> ([Pod] -> ShowS) -> Show Pod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Pod -> ShowS
showsPrec :: Int -> Pod -> ShowS
$cshow :: Pod -> String
show :: Pod -> String
$cshowList :: [Pod] -> ShowS
showList :: [Pod] -> ShowS
Show)


instance ToResource Pod where
  toResource :: Pod -> Resource
toResource Pod {Maybe Text
podName :: Pod -> Maybe Text
podUid :: Pod -> Maybe Text
podName :: Maybe Text
podUid :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_pod_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
podName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_pod_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
podUid
      ]


{- | A container in a PodTemplate.

@since 0.0.1.0
-}
data Container = Container
  { Container -> Maybe Text
containerName :: Maybe Text
  -- ^ The name of the Container from Pod specification, must be unique within a Pod. Container runtime usually uses different globally unique name (container.name).
  , Container -> Maybe Int
containerRestartCount :: Maybe Int
  -- ^ Number of times the container was restarted. This attribute can be used to identify a particular container (running or stopped) within a container spec.
  }


instance ToResource Container where
  toResource :: Container -> Resource
toResource Container {Maybe Int
Maybe Text
containerName :: Container -> Maybe Text
containerRestartCount :: Container -> Maybe Int
containerName :: Maybe Text
containerRestartCount :: Maybe Int
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_container_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
containerName
      , AttributeKey Int64 -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Int64
SC.k8s_container_restartCount Text -> Maybe Int -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Int
containerRestartCount
      ]


{- | A ReplicaSet’s purpose is to maintain a stable set of replica Pods running at any given time.

@since 0.0.1.0
-}
data ReplicaSet = ReplicaSet
  { ReplicaSet -> Maybe Text
replicaSetUid :: Maybe Text
  , ReplicaSet -> Maybe Text
replicaSetName :: Maybe Text
  }


instance ToResource ReplicaSet where
  toResource :: ReplicaSet -> Resource
toResource ReplicaSet {Maybe Text
replicaSetUid :: ReplicaSet -> Maybe Text
replicaSetName :: ReplicaSet -> Maybe Text
replicaSetUid :: Maybe Text
replicaSetName :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_replicaset_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
replicaSetName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_replicaset_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
replicaSetUid
      ]


{- | An API object that manages a replicated application, typically by running Pods with no local state. Each replica is represented by a Pod, and the Pods are distributed among the nodes of a cluster.

@since 0.0.1.0
-}
data Deployment = Deployment
  { Deployment -> Maybe Text
deploymentUid :: Maybe Text
  -- ^ The UID of the Deployment.
  , Deployment -> Maybe Text
deploymentName :: Maybe Text
  -- ^ The name of the Deployment.
  }


instance ToResource Deployment where
  toResource :: Deployment -> Resource
toResource Deployment {Maybe Text
deploymentUid :: Deployment -> Maybe Text
deploymentName :: Deployment -> Maybe Text
deploymentUid :: Maybe Text
deploymentName :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_deployment_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
deploymentName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_deployment_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
deploymentUid
      ]


{- | Manages the deployment and scaling of a set of Pods, and provides guarantees about the ordering and uniqueness of these Pods.

@since 0.0.1.0
-}
data StatefulSet = StatefulSet
  { StatefulSet -> Maybe Text
statefulSetUid :: Maybe Text
  -- ^ The UID of the StatefulSet.
  , StatefulSet -> Maybe Text
statefulSetName :: Maybe Text
  -- ^ The name of the StatefulSet.
  }


instance ToResource StatefulSet where
  toResource :: StatefulSet -> Resource
toResource StatefulSet {Maybe Text
statefulSetUid :: StatefulSet -> Maybe Text
statefulSetName :: StatefulSet -> Maybe Text
statefulSetUid :: Maybe Text
statefulSetName :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_statefulset_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
statefulSetName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_statefulset_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
statefulSetUid
      ]


{- | A DaemonSet ensures that all (or some) Nodes run a copy of a Pod.

@since 0.0.1.0
-}
data DaemonSet = DaemonSet
  { DaemonSet -> Maybe Text
daemonSetUid :: Maybe Text
  -- ^ The UID of the DaemonSet.
  , DaemonSet -> Maybe Text
daemonSetName :: Maybe Text
  -- ^ The name of the DaemonSet.
  }


instance ToResource DaemonSet where
  toResource :: DaemonSet -> Resource
toResource DaemonSet {Maybe Text
daemonSetUid :: DaemonSet -> Maybe Text
daemonSetName :: DaemonSet -> Maybe Text
daemonSetUid :: Maybe Text
daemonSetName :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_daemonset_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
daemonSetName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_daemonset_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
daemonSetUid
      ]


{- | A Job creates one or more Pods and ensures that a specified number of them successfully terminate.

@since 0.0.1.0
-}
data Job = Job
  { Job -> Maybe Text
jobUid :: Maybe Text
  -- ^ The UID of the Job.
  , Job -> Maybe Text
jobName :: Maybe Text
  -- ^ The name of the Job.
  }


instance ToResource Job where
  toResource :: Job -> Resource
toResource Job {Maybe Text
jobUid :: Job -> Maybe Text
jobName :: Job -> Maybe Text
jobUid :: Maybe Text
jobName :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_job_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
jobName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_job_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
jobUid
      ]


{- | A CronJob creates Jobs on a repeating schedule.

@since 0.0.1.0
-}
data CronJob = CronJob
  { CronJob -> Maybe Text
cronJobUid :: Maybe Text
  -- ^ The UID of the CronJob.
  , CronJob -> Maybe Text
cronJobName :: Maybe Text
  -- ^ The name of the CronJob.
  }


instance ToResource CronJob where
  toResource :: CronJob -> Resource
toResource CronJob {Maybe Text
cronJobUid :: CronJob -> Maybe Text
cronJobName :: CronJob -> Maybe Text
cronJobUid :: Maybe Text
cronJobName :: Maybe Text
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_cronjob_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
cronJobName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.k8s_cronjob_uid Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
cronJobUid
      ]