name: load-config

# Config options for test type
{{$SERVICE_TEST := DefaultParam .CL2_SERVICE_TEST true}}
{{$CNP_TEST := DefaultParam .CL2_CNP_TEST false}}
{{$CCNP_TEST := DefaultParam .CL2_CCNP_TEST false}}

# Config options for test parameters
{{$nodesPerNamespace := DefaultParam .CL2_NODES_PER_NAMESPACE 100}}
{{$podsPerNode := DefaultParam .CL2_PODS_PER_NODE 50}}
{{$loadTestThroughput := DefaultParam .CL2_LOAD_TEST_THROUGHPUT 100}}
{{$deploymentSize := DefaultParam .CL2_DEPLOYMENT_SIZE 100}}
{{$repeats := DefaultParam .CL2_REPEATS 1}}
{{$groupName := DefaultParam .CL2_GROUP_NAME "service-discovery"}}

# TODO(jshr-w): This should eventually use >1 namespace.
{{$namespaces := 1}}
{{$nodes := DefaultParam .CL2_NODES 1000}}

{{$operationTimeout := DefaultParam .CL2_OPERATION_TIMEOUT "15m"}}
{{$totalPods := MultiplyInt $namespaces $nodes $podsPerNode}}
{{$podsPerNamespace := DivideInt $totalPods $namespaces}}
{{$deploymentsPerNamespace := DivideInt $podsPerNamespace $deploymentSize}}

{{$latencyPodCpu := DefaultParam .CL2_LATENCY_POD_CPU 10}}
{{$latencyPodMemory := DefaultParam .CL2_LATENCY_POD_MEMORY 50}}
{{$podStartupLatencyThreshold := DefaultParam .CL2_POD_STARTUP_LATENCY_THRESHOLD "15s"}}

{{$CILIUM_METRICS_ENABLED := DefaultParam .CL2_CILIUM_METRICS_ENABLED false}}
{{$SCRAPE_CONTAINERD := DefaultParam .CL2_SCRAPE_CONTAINERD false}}

# Service test
{{$BIG_GROUP_SIZE := DefaultParam .BIG_GROUP_SIZE 4000}}
{{$SMALL_GROUP_SIZE := DefaultParam .SMALL_GROUP_SIZE 20}}

# TODO(jshr-w): Add some flexibility to BIG_GROUP_SIZE (e.g. upstream uses 250)
{{$bigDeploymentsPerNamespace := DefaultParam .bigDeploymentsPerNamespace 0}}
{{if (gt $podsPerNamespace $BIG_GROUP_SIZE)}}
{{$bigDeploymentsPerNamespace := DefaultParam .bigDeploymentsPerNamespace 1}}
{{end}}

{{$smallDeploymentPods := SubtractInt $podsPerNamespace (MultiplyInt $bigDeploymentsPerNamespace $BIG_GROUP_SIZE)}}
{{$smallDeploymentsPerNamespace := DivideInt $smallDeploymentPods $SMALL_GROUP_SIZE}}

# CNP & CCNP Test
{{$CNPS_PER_NAMESPACE := DefaultParam .CL2_CNPS_PER_NAMESPACE 0}}
{{$CCNPS := DefaultParam .CL2_CCNPS 0}}
{{$DUALSTACK := DefaultParam .CL2_DUALSTACK false}}

# QPS
# We use RandomizedTimeLimitedLoad for load QPS.
# Specifically, we aim to create/delete LOAD_TEST_THROUGHPUT/DELETE_TEST_THROUGHPUT pods per second, on average.
# Operations make an independent choice about the time to start uniformly at random from the associated time period.
{{$LOAD_TEST_THROUGHPUT := DefaultParam .CL2_LOAD_TEST_THROUGHPUT 100}}
{{$DELETE_TEST_THROUGHPUT := DefaultParam .CL2_DELETE_TEST_THROUGHPUT $LOAD_TEST_THROUGHPUT}}
{{$saturationTime := DivideInt $totalPods $LOAD_TEST_THROUGHPUT}}
{{$deletionTime := DivideInt $totalPods $DELETE_TEST_THROUGHPUT}}

namespace:
  number: {{$namespaces}}
  prefix: slo
  deleteStaleNamespaces: true
  deleteAutomanagedNamespaces: true
  enableExistingNamespaces: false

tuningSets:
  - name: Sequence
    parallelismLimitedLoad:
      parallelismLimit: 1
  - name: RandomizedSaturationTimeLimited
    RandomizedTimeLimitedLoad:
      timeLimit: {{$saturationTime}}s
  - name: RandomizedDeletionTimeLimited
    RandomizedTimeLimitedLoad:
      timeLimit: {{$deletionTime}}s

steps:
  - name: Log - namespaces={{$namespaces}}, nodesPerNamespace={{$nodesPerNamespace}}, podsPerNode={{$podsPerNode}}, totalPods={{$totalPods}}, podsPerNamespace={{$podsPerNamespace}}, bigDeploymentsPerNamespace={{$bigDeploymentsPerNamespace}}, smallDeploymentsPerNamespace={{$smallDeploymentsPerNamespace}}, bigGroupSize={{$BIG_GROUP_SIZE}}, smallGroupSize={{$SMALL_GROUP_SIZE}}, repeats={{$repeats}}, $saturationTime={{$saturationTime}}, $deletionTime={{$deletionTime}}
    measurements:
    - Identifier: Dummy
      Method: Sleep
      Params:
        action: start
        duration: 1ms

  - module:
      path: /modules/measurements.yaml
      params:
        action: start
        group: {{$groupName}}

{{if $CILIUM_METRICS_ENABLED}}
  - module:
      path: /modules/cilium-measurements.yaml
      params:
        action: start
{{end}}

{{if $SCRAPE_CONTAINERD}}
  - module:
      path: /modules/containerd-measurements.yaml
      params:
        action: start
{{end}}

{{range $i := Loop $repeats}}
{{if $SERVICE_TEST}}
  - module:
      path: /modules/services.yaml
      params:
        actionName: "Creating"
        namespaces: {{$namespaces}}
        smallServicesPerNamespace: {{$smallDeploymentsPerNamespace}}
        bigServicesPerNamespace: {{$bigDeploymentsPerNamespace}}
{{end}}

{{if $CNP_TEST}}
  - module:
      path: /modules/ciliumnetworkpolicy.yaml
      params:
        actionName: "Creating"
        namespaces: {{$namespaces}}
        Group: {{$groupName}}
        cnpsPerNamespace: {{$CNPS_PER_NAMESPACE}}
{{end}}

{{if $CCNP_TEST}}
  - module:
      path: /modules/ciliumclusternetworkpolicy.yaml
      params:
        actionName: "Creating"
        Group: {{$groupName}}
        ccnps: {{$CCNPS}}
{{end}}

  - module:
      path: /modules/reconcile-objects.yaml
      params:
        actionName: "create"
        namespaces: {{$namespaces}}
        tuningSet: RandomizedSaturationTimeLimited
        operationTimeout: {{$operationTimeout}}
    {{if or $CCNP_TEST $CNP_TEST}}
        bigDeploymentSize: 0
        bigDeploymentsPerNamespace: 0
        cnp_test: {{$CNP_TEST}}
        ccnp_test: {{$CCNP_TEST}}
    {{else}}
        bigDeploymentSize: {{$BIG_GROUP_SIZE}}
        bigDeploymentsPerNamespace: {{$bigDeploymentsPerNamespace}}
    {{end}}
        smallDeploymentSize: {{$SMALL_GROUP_SIZE}}
        smallDeploymentsPerNamespace: {{$smallDeploymentsPerNamespace}}
        CpuRequest: {{$latencyPodCpu}}m
        MemoryRequest: {{$latencyPodMemory}}M
        Group: {{$groupName}}
        deploymentLabel: start

  - module:
      path: /modules/reconcile-objects.yaml
      params:
        actionName: "restart"
        namespaces: {{$namespaces}}
        tuningSet: Sequence
        operationTimeout: {{$operationTimeout}}
    {{if or $CCNP_TEST $CNP_TEST}}
        bigDeploymentSize: 0
        bigDeploymentsPerNamespace: 0
        cnp_test: {{$CNP_TEST}}
        ccnp_test: {{$CCNP_TEST}}
    {{else}}
        bigDeploymentSize: {{$BIG_GROUP_SIZE}}
        bigDeploymentsPerNamespace: {{$bigDeploymentsPerNamespace}}
    {{end}}
        smallDeploymentSize: {{$SMALL_GROUP_SIZE}}
        smallDeploymentsPerNamespace: {{$smallDeploymentsPerNamespace}}
        CpuRequest: {{$latencyPodCpu}}m
        MemoryRequest: {{$latencyPodMemory}}M
        Group: {{$groupName}}
        deploymentLabel: restart

  - module:
      path: /modules/reconcile-objects.yaml
      params:
        actionName: "delete"
        namespaces: {{$namespaces}}
        tuningSet: RandomizedDeletionTimeLimited
        operationTimeout: {{$operationTimeout}}
    {{if or $CCNP_TEST $CNP_TEST}}
        bigDeploymentSize: 0
        bigDeploymentsPerNamespace: 0
        cnp_test: {{$CNP_TEST}}
        ccnp_test: {{$CCNP_TEST}}
    {{else}}
        bigDeploymentSize: {{$BIG_GROUP_SIZE}}
        bigDeploymentsPerNamespace: 0
    {{end}}
        smallDeploymentSize: {{$SMALL_GROUP_SIZE}}
        smallDeploymentsPerNamespace: 0
        deploymentLabel: restart
        Group: {{$groupName}}
{{if $SERVICE_TEST}}
  - module:
      path: /modules/services.yaml
      params:
        actionName: "Deleting"
        namespaces: {{$namespaces}}
        smallServicesPerNamespace: 0
        bigServicesPerNamespace: 0
{{end}}
{{if $CNP_TEST}}
  - module:
      path: /modules/ciliumnetworkpolicy.yaml
      params:
        actionName: "Deleting"
        namespaces: {{$namespaces}}
        cnpsPerNamespace: 0
{{end}}
{{if $CCNP_TEST}}
  - module:
      path: /modules/ciliumclusternetworkpolicy.yaml
      params:
        actionName: "Deleting"
        namespaces: {{$namespaces}}
        ccnps: 0
{{end}}
{{end}}

{{if $CILIUM_METRICS_ENABLED}}
  - module:
      path: /modules/cilium-measurements.yaml
      params:
        action: gather
{{end}}

{{if $SCRAPE_CONTAINERD}}
  - name: Wait for last scrape
    measurements:
      - Identifier: Sleep
        Method: Sleep
        Params:
          duration: 10m

  - module:
      path: /modules/containerd-measurements.yaml
      params:
        action: gather
{{end}}

  - module:
      path: /modules/measurements.yaml
      params:
        action: gather
        group: {{$groupName}}
