ぴよ丸水産

週末ファゴッティストによる技術ブログ

【Jenkins】JenkinsからJMeterで負荷試験をやってみる

はじめに

JenkinsからJMeterを使用した負荷試験をやってみました。
JMeter全然使いこなせてないウーマンですが、
そのあたりは目をつむって。。
Jenkinsでこう設定すると、こんな感じで実行できて、こんな風に結果が見えます、
をざっくりまとめてみました。

pythonもろもろのバージョンなど、環境特有のものかもですが、
いろいろトラブったのでおまけでトラブルシュートの軌跡をメモしておきました。
トラブルシュートは相変わらずパワープレーですが、悪しからず。。

目次

環境情報

項目
OS RHEL7
Python 2.7.5
Jenkins 2.138.2
Jenkins Performance Plugin 3.1.17
Apache JMeter 5.1.1

要件

  • GitLabのPerformansTest.gitにjmxファイルを格納しておく
  • Jenkinsジョブを実行すると、最新masterのjmxファイルがテストシナリオとして試験が実行される

JenkinsにPerformance Plugin追加

plugins.jenkins.io

JenkinsからJMeterによる負荷試験実行するために、
Performance Pluginをインストールします。

Performance PluginはTaurusという自動テストフレームワークから
Jmeterなどのテストツールを実行する仕組みのようです。

gettaurus.org

プラグインのインストールは、下記の方法で行いました。

  1. Performance Pluginにアクセスし、Archivesをクリック
  2. 3.17をクリックしてダウンロード
  3. ダウンロードしたperformance.hpiをJenkinsにアップロード
    • Jenkinsの管理->プラグインの管理->高度な設定タブ->プラグインのアップロード

f:id:blue-38:20200519173032p:plain

ジョブの作成

新規ジョブの作成を押下し、フリースタイル・プロジェクトのビルドを選択し、
新規ジョブを作成します。

ソースコードの管理

ディレクトリに固定で置いても良いと思いますが、
今回Gitで試験シナリオを定義したJmxファイルを管理する構成にしてみたので、
下記のように設定しました。

f:id:blue-38:20200519173059p:plain

ビルド

ビルド手順の追加からRun Performance Testを選択します。

f:id:blue-38:20200519173127p:plain

Taurus tool parameters:に実行するJmxファイル名を指定します。

f:id:blue-38:20200519173147p:plain

そのほかの項目はデフォルトから変えていないですが、
Automatically generate performance reportは結果出力に必要なパラメータのようです。

ビルド後の処理

ビルド後の処理の追加からPublish Performance test results reportを選択します。

f:id:blue-38:20200519173226p:plain

Source data files (autodetects format):**/*.jtlを指定します。
それ以外はデフォルトのままです。

f:id:blue-38:20200519173210p:plain

ジョブの実行結果

#(ジョブの実行No)をクリックして、Performance Reportをクリックすると表示されます。

Jmxファイルの内容によるので、参考程度ですが、
こんな感じに出力されました。
今回の実行結果+過去結果からの推移が可視化されるようです。

f:id:blue-38:20200519173239p:plain

おわりに

JMeterを使い込んでないので、
JMeter単体で使う場合とのギャップを語ることはできませんが、
下記3点がポイントだと思います。

  • GitLabでテストシナリオをバージョン管理
  • スケジュール実行可
  • Jenkinsで試験結果推移の可視化

おまけ:トラブルシュート

私の検証環境特有の問題だと思うので、別出しでまとめました。
あとコンソールログが消えちゃったりしたので、ふわっと書いてます。

bztvirtualenvpip installしろやと言われ、ジョブエラー

すみません、ジョブのコンソールログ消えちゃいました。
手動でbztインストールを試行しました。
virtualenvはすんなりはいりましたが、
ジョブ動かしたら結局venvした先でbztがインストールできず詰んだ
(プロキシの関係かな、、あきらめたので未調査)ので、
bztインストールしました。

pip install bzt
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting bzt
  Downloading bzt-1.13.9-py2.py3-none-any.whl (311 kB)
     |????????????????????????????????| 311 kB 2.3 MB/s

~(略)~

Collecting Appium-Python-Client
  Downloading Appium-Python-Client-1.0.0.tar.gz (51 kB)
     |????????????????????????????????| 51 kB 285 kB/s
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-b0nYvk/Appium-Python-Client/setup.py'"'"'; __file__='"'"'/tmp/pip-install-b0nYvk/Appium-Python-Client/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-b0nYvk/Appium-Python-Client/pip-egg-info
         cwd: /tmp/pip-install-b0nYvk/Appium-Python-Client/
    Complete output (8 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-b0nYvk/Appium-Python-Client/setup.py", line 19, in <module>
        from appium.common.helper import library_version
      File "appium/common/helper.py", line 20
        def extract_const_attributes(cls: type) -> Dict[str, Any]:
                                        ^
    SyntaxError: invalid syntax
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 20.0.2; however, version 20.1 is available.
You should consider upgrading via the '/usr/bin/python -m pip install --upgrade pip' command.

Appium-Python-Clientのインストールでこけているようです。

https://pypi.org/project/Appium-Python-Client/

Notice
Since v1.0.0, only Python 3 is supported

とのことなので、Python2も対応してるバージョンをインストールしました。

# pip install Appium-Python-Client==0.51

さっきとは違うエラーが出てきました。

Collecting Appium-Python-Client==0.51
  Downloading Appium-Python-Client-0.51.tar.gz (56 kB)
     |????????????????????????????????| 56 kB 445 kB/s
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-Docu3L/Appium-Python-Client/setup.py'"'"'; __file__='"'"'/tmp/pip-install-Docu3L/Appium-Python-Client/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-C2pD_b
         cwd: /tmp/pip-install-Docu3L/Appium-Python-Client/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-Docu3L/Appium-Python-Client/setup.py", line 37, in <module>
        packages=find_packages(include=['appium*']),
    TypeError: find_packages() got an unexpected keyword argument 'include'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

https://github.com/appium/python-client/issues/397

同じことて困ってる人いました。
私もsetuptoolsのバージョンが低いのかな。。。と思い。

# pip show setuptools
Name: setuptools
Version: 0.9.8
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://pypi.python.org/pypi/setuptools
Author: Python Packaging Authority
Author-email: distutils-sig@python.org
License: PSF or ZPL
Location: /usr/lib/python2.7/site-packages
Requires:
Required-by:

上げてみました。怖いくらい上がってしまった。

# pip install -U setuptools
pip install -U setuptools
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting setuptools
  Downloading setuptools-44.1.0-py2.py3-none-any.whl (583 kB)
     |????????????????????????????????| 583 kB 409 kB/s
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 0.9.8
    Uninstalling setuptools-0.9.8:
      Successfully uninstalled setuptools-0.9.8
Successfully installed setuptools-44.1.0

もう一度bztインストール試行!
先に進めてエラーが変わりました。

ERROR: Cannot uninstall 'chardet'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

https://stackoverflow.com/questions/49915951/cannot-uninstall-chardet

こちらを参考にchardetを一回消しました。
もう一度bztインストール試行!
ようやくbztインストールできました。

# pip show bzt
Name: bzt
Version: 1.13.9
Summary: Taurus Tool for Continuous Testing
Home-page: http://gettaurus.org/
Author: Andrey Pokhilko
Author-email: andrey@blazemeter.com
License: Apache 2.0
Location: /usr/lib/python2.7/site-packages
Requires: nose, requests, pytest, terminaltables, psutil, fuzzyset, progressbar33, astunparse, pyvirtualdisplay, gevent, colorlog, cssselect, selenium, pyyaml, apiritif, lxml, hdrpy, ipaddress, colorama, urwid, Appium-Python-Client
Required-by:

JMeterのインストール失敗

もう一度ジョブ流してみました。

11:36:23 INFO: Taurus CLI Tool v1.13.9
11:36:23 INFO: Starting with configs: ['/var/lib/jenkins/workspace/Execute_Performance_Test/jenkins-report.yml', '/tmp/jmx_HIaZOv.json']
11:36:23 INFO: No personal config found, creating one at /var/lib/jenkins/.bzt-rc
11:36:23 INFO: Configuring...
11:36:23 INFO: Artifacts dir: /var/lib/jenkins/workspace/Execute_Performance_Test/2020-05-19_11-36-23.694021
11:36:23 INFO: Preparing...
11:36:24 INFO: Will install JMeter into /var/lib/jenkins/.bzt/jmeter-taurus/5.1.1
11:36:33 WARNING: Failed to check for updates
11:36:34 ERROR: Can't fetch https://jmeter.apache.org/download_jmeter.cgi
11:36:34 INFO: Downloading: https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.1.1.zip
11:36:39 ERROR: Error while downloading https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.1.1.zip: Unsuccessful download from https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.1.1.zip
11:36:39 ERROR: Internal Error: JMeter download failed: No more links to try
11:36:39 INFO: Post-processing...
11:36:39 INFO: Artifacts dir: /var/lib/jenkins/workspace/Execute_Performance_Test/2020-05-19_11-36-23.694021
11:36:39 WARNING: Done performing with code: 1
Build step 'Run Performance Test' changed build result to FAILURE
Creating parser with percentiles:'0,50,90,100,' filterRegex:
Performance: Recording JMeter reports '**/*.jtl'
Performance: No threshold configured for making the test unstable
Performance: No threshold configured for making the test failure
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE

JMeterのインストールで止まりました。
プロキシ配下の環境のため、Jenkinsを通してインストールできていないのかもしれません。
(このへん、切り分けてないです)
パワープレーですが、
/var/lib/jenkins/.bzt/jmeter-taurus/5.1.1(ディレクトリは自分で掘りました)に、

# wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.1.1.zip

で取得したzipファイルを解凍してソースを配置すれば、動きます。
所有者や権限は気を付けてください。