{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

{- |
 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.Resource


-- | A Kubernetes Cluster.
newtype Cluster = Cluster
  { Cluster -> Maybe Text
clusterName :: Maybe Text
  -- ^ The name of the cluster.
  }


instance ToResource Cluster where
  type ResourceSchema Cluster = 'Nothing
  toResource :: Cluster -> Resource (ResourceSchema Cluster)
toResource Cluster {Maybe Text
clusterName :: Cluster -> Maybe Text
clusterName :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [Text
"k8s.cluster.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
clusterName]


-- | A Kubernetes Node.
data Node = Node
  { Node -> Maybe Text
nodeName :: Maybe Text
  , Node -> Maybe Text
nodeUid :: Maybe Text
  }


instance ToResource Node where
  type ResourceSchema Node = 'Nothing
  toResource :: Node -> Resource (ResourceSchema Node)
toResource Node {Maybe Text
nodeName :: Node -> Maybe Text
nodeUid :: Node -> Maybe Text
nodeName :: Maybe Text
nodeUid :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.node.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
nodeName
      , Text
"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.
newtype Namespace = Namespace
  { Namespace -> Maybe Text
namespaceName :: Maybe Text
  -- ^ The name of the namespace that the pod is running in.
  }


instance ToResource Namespace where
  type ResourceSchema Namespace = 'Nothing
  toResource :: Namespace -> Resource (ResourceSchema Namespace)
toResource Namespace {Maybe Text
namespaceName :: Namespace -> Maybe Text
namespaceName :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"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.
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.
  }


instance ToResource Pod where
  type ResourceSchema Pod = 'Nothing
  toResource :: Pod -> Resource (ResourceSchema Pod)
toResource Pod {Maybe Text
podName :: Pod -> Maybe Text
podUid :: Pod -> Maybe Text
podName :: Maybe Text
podUid :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.pod.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
podName
      , Text
"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.
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
  type ResourceSchema Container = 'Nothing
  toResource :: Container -> Resource (ResourceSchema Container)
toResource Container {Maybe Int
Maybe Text
containerName :: Container -> Maybe Text
containerRestartCount :: Container -> Maybe Int
containerName :: Maybe Text
containerRestartCount :: Maybe Int
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.container.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
containerName
      , Text
"k8s.container.restart_count" 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.
data ReplicaSet = ReplicaSet
  { ReplicaSet -> Maybe Text
replicaSetUid :: Maybe Text
  , ReplicaSet -> Maybe Text
replicaSetName :: Maybe Text
  }


instance ToResource ReplicaSet where
  type ResourceSchema ReplicaSet = 'Nothing
  toResource :: ReplicaSet -> Resource (ResourceSchema ReplicaSet)
toResource ReplicaSet {Maybe Text
replicaSetUid :: ReplicaSet -> Maybe Text
replicaSetName :: ReplicaSet -> Maybe Text
replicaSetUid :: Maybe Text
replicaSetName :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.replicaset.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
replicaSetName
      , Text
"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.
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
  type ResourceSchema Deployment = 'Nothing
  toResource :: Deployment -> Resource (ResourceSchema Deployment)
toResource Deployment {Maybe Text
deploymentUid :: Deployment -> Maybe Text
deploymentName :: Deployment -> Maybe Text
deploymentUid :: Maybe Text
deploymentName :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.deployment.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
deploymentName
      , Text
"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.
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
  type ResourceSchema StatefulSet = 'Nothing
  toResource :: StatefulSet -> Resource (ResourceSchema StatefulSet)
toResource StatefulSet {Maybe Text
statefulSetUid :: StatefulSet -> Maybe Text
statefulSetName :: StatefulSet -> Maybe Text
statefulSetUid :: Maybe Text
statefulSetName :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.statefulset.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
statefulSetName
      , Text
"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.
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
  type ResourceSchema DaemonSet = 'Nothing
  toResource :: DaemonSet -> Resource (ResourceSchema DaemonSet)
toResource DaemonSet {Maybe Text
daemonSetUid :: DaemonSet -> Maybe Text
daemonSetName :: DaemonSet -> Maybe Text
daemonSetUid :: Maybe Text
daemonSetName :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.daemonset.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
daemonSetName
      , Text
"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.
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
  type ResourceSchema Job = 'Nothing
  toResource :: Job -> Resource (ResourceSchema Job)
toResource Job {Maybe Text
jobUid :: Job -> Maybe Text
jobName :: Job -> Maybe Text
jobUid :: Maybe Text
jobName :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.job.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
jobName
      , Text
"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.
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
  type ResourceSchema CronJob = 'Nothing
  toResource :: CronJob -> Resource (ResourceSchema CronJob)
toResource CronJob {Maybe Text
cronJobUid :: CronJob -> Maybe Text
cronJobName :: CronJob -> Maybe Text
cronJobUid :: Maybe Text
cronJobName :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"k8s.cronjob.name" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
cronJobName
      , Text
"k8s.cronjob.uid" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
cronJobUid
      ]