๐Ÿ’ป
DevOps Cookbook
  • Home
    • Meiko DevOps Cookbook
  • Gitlab
    • Tips
      • ์‚ฌ์ „ ์ •์˜๋œ CI/CD ๋ณ€์ˆ˜์˜ ๊ธฐ๋ณธ ์„ธํŠธ
    • ๋”ฅ๋‹ค์ด๋ธŒ Gitlab CI/CD
      • GitLab CI/CD ์‹œ์ž‘ํ•˜๊ธฐ
        • .gitlab-ci.yml ํŒŒ์ผ
        • Runner
        • ํŒŒ์ดํ”„๋ผ์ธ
        • CI/CD ๋ณ€์ˆ˜
        • CI/CD ์ปดํฌ๋„ŒํŠธ
      • CI/CD YAML ๊ตฌ๋ฌธ ์ฐธ์กฐ
    • CI/CD Notifications
      • CI/CD slack notifiaction ๊ตฌ์ถ•์ž‘์—… ๊ฒฐ๊ณผ
  • Kubernetes
    • Persistence Volume
      • play-cluster
    • Ingress
      • Ingress๋ž€
      • ์ˆ˜๋™์œผ๋กœ ingress ๋ฐฐํฌํ•˜๊ธฐ
    • Security
    • HPA
      • hpa troubleshooting history
        • 1. HELM_UPGRADE_VALUES_FILE๋กœ hpa๊ฐ€ ์ถ”๊ฐ€๋˜์ง€ ์•Š๋Š” ์›์ธ
        • 2. targetCPUUtilizationPercentage ๊ณ„์‚ฐ์€ ์–ด๋–ป๊ฒŒ ๋˜๋Š”๊ฐ€
        • 3. helm values์— cpu resource ๋‹จ์œ„๋ฅผ 1๋กœ ํ–ˆ์„ ๋•Œ ์‹ค์ œ ํŒŒ๋“œ์— 1m( 0.001 ) ์ฝ”์–ด๊ฐ€ ๋ถ€์—ฌ๋œ ๊ฒƒ
        • 4. pod cpu resources๊ฐ€ ํ• ๋‹น๋ฐ›์€ ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ์ธ ์ง€ ํ˜„์žฌ ์‚ฌ์šฉ๋Ÿ‰์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ์ธ์ง€ ๊ฒ€์ฆ
        • 5. ์„ค์ •ํ•œ hpa๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ pod auto scaling์ด ๋™์ž‘ํ•˜๋Š” ์ง€ ๊ฒ€์ฆ
      • HorizontalPodAutoscaler์˜ behavior ํ•„๋“œ ์ค‘ stabilizationWindowSeconds ๊ฐ’์ด Kubernetes ์ฝ”๋“œ์—์„œ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”์ง€ ๋ถ„์„
  • prometheus
    • prometheus ๋ฆฌ์†Œ์Šค alert ์„ธํŒ…
      • ์Šฌ๋ž™ ์ฑ„๋„ ๊ตฌ์„ฑ
      • alert ํ™˜๊ฒฝ ๊ตฌ์„ฑ ๊ฐ€์ด๋“œ
  • Loki
    • loki-grafana alert ์„ธํŒ…
      • 1์ฐจ ๊ฒ€์ฆ ๊ฒฐ๊ณผ
      • Alert ํ™˜๊ฒฝ ๊ตฌ์„ฑ ๊ฐ€์ด๋“œ
  • load test
    • nGrinder
      • nGrinder Test Configuration ๊ฐ’๋“ค
      • ์งˆ๋ฌธ๋ฆฌ์ŠคํŠธ
        • groovy๋Š” JUnit ์Šคํƒ€์ผ์— ํฌํ•จ๋˜์ง€ ์•Š๋Š”๊ฑด๊ฐ€ ? + GTest๊ฐ€ ๋ญ”์ง€ ์ข€ ํ—ท๊ฐˆ๋ฆฐ๋‹ค
      • Script
        • Groovy Script Structure
          • reference
          • Groovy script deep dive
          • Groovy Script ์‹คํ–‰ ๊ตฌ์กฐ ๋ถ„์„
      • Test
        • [nGrinder] single endpoint load test ํ•˜๊ธฐ
          • [nGrinder] single endpoint load test script ๊ธฐ๋ฐ˜ cpu ์‚ฌ์šฉ๋Ÿ‰ ํ…Œ์ŠคํŠธ
          • [nGrinder] single endpoint load test script ๊ธฐ๋ฐ˜ pod autoscaling ํ…Œ์ŠคํŠธ
        • [nGrinder] multi endpoint load test ํ•˜๊ธฐ
          • [nGrinder] multi endpoint load test script์— ์ •์˜ํ•œ test๋“ค์ด ์‹คํ–‰ ์ˆœ์„œ๋ฅผ ๋ณด์žฅ ๋ฐ›๋Š”๊ฐ€?
  • AWS
    • aws-cli
      • eks cluster vpc ์ŠคํŽ™๋ณด๊ธฐ
    • aws-vpc
  • EKS
    • youtube links
    • EKS best practice
    • ์งˆ๋ฌธ ์ •๋ฆฌ
  • Istio
    • Istio Basic
      • Istio ์ปดํฌ๋„ŒํŠธ ๋ณ„ ์—ญํ• 
      • Kubernetes Ingress์™€ Istio VirtualService์˜ ๊ด€๊ณ„
    • Gateway
      • Gateway ์ฃผ์š” ํŠน์ง•
      • Istio Gateway์™€ Kubernetes Ingress์˜ ์ฃผ์š” ์ฐจ์ด์ 
  • IAC
    • Terraform
      • ํ…Œ๋ผํผ ์„ค์น˜
      • ํ…Œ๋ผํผ ๋ฌธ์„œ
      • ํ…Œ๋ผํผ ๊ฐœ๋…
        • ์–ธ์–ด ๊ตฌ์กฐ
        • ์‚ฌ์šฉ ์ˆœ์„œ
        • ์ƒํƒœํŒŒ์ผ (tfstate)
        • ๋ณ€์ˆ˜ ์ •์˜ ๋ฐฉ๋ฒ•
      • Terraform - AWS VPC
    • Ansible
      • Ansible ์ดˆ๊ธฐ ํ•™์Šต ๋‚ด์šฉ
      • Ansible Playbook
      • Ansible Study
        • Inventory
        • Playbook
          • Module
        • Variable
  • etc
    • Toss SLASH24
    • Elastic Load Balancing
    • ๋‚™์„œ์žฅ
      • IRSA
    • deep dive
      • Istio ๊ณต์‹๋ฌธ์„œ ๋ฒˆ์—ญ
        • Overview
          • What is Istio?
          • Why choose Istio?
          • Sidecar or ambient?
        • Concepts
          • Traffic Management
        • Page
      • eks ์—์„œ control plane < - > data plane ํ†ต์‹  ์›๋ฆฌ
Powered by GitBook
On this page
Edit on GitHub
  1. load test
  2. nGrinder
  3. Script

Groovy Script Structure

nGrinder์—์„œ ๊ธฐ๋ณธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ƒ์„ฑํ–ˆ์„ ๋•Œ ๋‚˜์˜ค๋Š” ๊ธฐ๋ณธ ์Šคํฌ๋ฆฝํŠธ๋Š” Java๋กœ ์ž‘์„ฑ๋˜์—ˆ์ง€๋งŒ, Groovy ์Šคํƒ€์ผ๋กœ ๋ณด์ผ ์ˆ˜ ์žˆ๋‹ค. ์‹ค์ œ๋กœ nGrinder๋Š” JUnit์„ ๊ธฐ๋ฐ˜์œผ๋กœ Java ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ, Groovy ์Šคํƒ€์ผ๋กœ ์ž‘์„ฑ๋œ GrinderRunner์™€ ๊ฐ™์€ ์ฃผ์„ ๋ฐ ์–ด๋…ธํ…Œ์ด์…˜์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋‹ค.

nGrinder Groovy ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด์„œ๋Š” ํด๋ž˜์Šค ์œ„์— @RunWith(GrinderRunner) ์• ๋„ˆํ…Œ์ด์…˜์„ ๊ผญ ๋ถ™์—ฌ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์ด ๋ถ€๋ถ„์€ GroovyRunner๊ฐ€ JUnit์˜ ํ–‰๋™์„ ์ œ์–ดํ•˜๋ฉฐ JUnit์— grinder context๋ฅผ ๋งˆ์šดํŠธ ํ•œ๋‹ค.

nGrinder๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ Groovy ๊ธฐ๋ฐ˜์˜ JUnit ํ…Œ์ŠคํŠธ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ๊ธฐ๋ณธ ์Šคํฌ๋ฆฝํŠธ๋Š” Groovy์™€ Java์˜ ์กฐํ•ฉ์œผ๋กœ ์ž‘์„ฑ๋˜๋ฉฐ, Groovy ์–ธ์–ด์˜ ๊ฐ„๊ฒฐํ•จ๊ณผ Java์˜ ๊ฐ•๋ ฅํ•จ์„ ๋™์‹œ์— ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ธฐ๋ณธ ์Šคํฌ๋ฆฝํŠธ ๋ถ„์„

์Šคํฌ๋ฆฝํŠธ ๊ตฌ์กฐ ๋ฐ ๋ถ„์„:

import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.script.GTest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
// import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith

import org.ngrinder.http.HTTPRequest
import org.ngrinder.http.HTTPRequestControl
import org.ngrinder.http.HTTPResponse
import org.ngrinder.http.cookie.Cookie
import org.ngrinder.http.cookie.CookieManager

/**
 * A simple example using the HTTP plugin that shows the retrieval of a single page via HTTP.
 *
 * This script is automatically generated by ngrinder.
 *
 * @author admin
 */
@RunWith(GrinderRunner)
class TestRunner {

    public static GTest test
    public static HTTPRequest request
    public static Map<String, String> headers = [:]
    public static Map<String, Object> params = [:]
    public static List<Cookie> cookies = []

    @BeforeProcess
    public static void beforeProcess() {
        HTTPRequestControl.setConnectionTimeout(300000)
        test = new GTest(1, "airdrop-api.dev.memecore.org")
        request = new HTTPRequest()
        grinder.logger.info("before process.")
    }

    @BeforeThread
    public void beforeThread() {
        test.record(this, "test")
        grinder.statistics.delayReports = true
        grinder.logger.info("before thread.")
    }

    @Before
    public void before() {
        request.setHeaders(headers)
        CookieManager.addCookies(cookies)
        grinder.logger.info("before. init headers and cookies")
    }

    @Test
    public void test() {
        HTTPResponse response = request.GET("https://airdrop-api.dev.memecore.org", params)

        if (response.statusCode == 301 || response.statusCode == 302) {
            grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
        } else {
            assertThat(response.statusCode, is(200))
        }
    }
}

์ฃผ์š” ๋ถ€๋ถ„ ์„ค๋ช…

  1. ์–ด๋…ธํ…Œ์ด์…˜ ๋ฐ ํด๋ž˜์Šค ์ฃผ์„

    • @RunWith(GrinderRunner): GrinderRunner๋ฅผ ์‚ฌ์šฉํ•ด ํ…Œ์ŠคํŠธ ์‹คํ–‰.

    • @BeforeProcess, @BeforeThread, @Before, @Test ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ํ…Œ์ŠคํŠธ ๋ผ์ดํ”„์‚ฌ์ดํด์„ ์ •์˜.

  2. ํ…Œ์ŠคํŠธ ๋ผ์ดํ”„์‚ฌ์ดํด ํ•จ์ˆ˜

    • @BeforeProcess: ์ „์ฒด ํ”„๋กœ์„ธ์Šค ์‹œ์ž‘ ์ „ ํ•œ ๋ฒˆ ์‹คํ–‰.

    • @BeforeThread: ๊ฐ ์Šค๋ ˆ๋“œ ์‹œ์ž‘ ์ „ ํ•œ ๋ฒˆ ์‹คํ–‰.

    • @Before: ๊ฐ ํ…Œ์ŠคํŠธ ์ „๋งˆ๋‹ค ์‹คํ–‰.

    • @Test: ํ…Œ์ŠคํŠธ ํ•จ์ˆ˜๋กœ, ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ํ•ต์‹ฌ ์ฝ”๋“œ ์ž‘์„ฑ.

  3. ์ฃผ์š” ๊ฐ์ฒด ๋ฐ ํ”Œ๋Ÿฌ๊ทธ์ธ ์‚ฌ์šฉ

    • GTest: ํ…Œ์ŠคํŠธ ๊ฐ์ฒด ์ƒ์„ฑ.

    • HTTPRequest, HTTPResponse: HTTP ์š”์ฒญ ๋ฐ ์‘๋‹ต์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฐ์ฒด.

    • Cookie, CookieManager: ์ฟ ํ‚ค ๊ด€๋ฆฌ ๊ฐ์ฒด.

์š”์•ฝ:

  • ๊ธฐ๋ณธ์ ์œผ๋กœ nGrinder์—์„œ ์ƒ์„ฑ๋˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋Š” Java์™€ Groovy ์Šคํƒ€์ผ์˜ ์กฐํ•ฉ์œผ๋กœ, Groovy๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ JUnit ํ…Œ์ŠคํŠธ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉ.

  • GrinderRunner์™€ ์–ด๋…ธํ…Œ์ด์…˜์„ ํ†ตํ•ด ํ…Œ์ŠคํŠธ ๋ผ์ดํ”„์‚ฌ์ดํด์„ ๊ด€๋ฆฌํ•˜๋ฉฐ, ์ฃผ์š” ํ”Œ๋Ÿฌ๊ทธ์ธ๊ณผ ๊ฐ์ฒด๋ฅผ ํ™œ์šฉํ•ด ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑ.

Q1: ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์–ด๋–ป๊ฒŒ ํ™•์žฅํ•  ์ˆ˜ ์žˆ์„๊นŒ?

Q2: Groovy ์Šคํƒ€์ผ์˜ ์Šคํฌ๋ฆฝํŠธ ์ž‘์„ฑ ์‹œ ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜?

Q3: ๊ฐ ์–ด๋…ธํ…Œ์ด์…˜์˜ ์—ญํ• ์„ ๊ตฌ์ฒด์ ์œผ๋กœ ์„ค๋ช…ํ•  ์ˆ˜ ์žˆ๋‚˜?

PreviousScriptNextGroovy script deep dive

Last updated 1 year ago