이 페이지는 기술 파트너가 공식 Datadog Agent 통합을 만드는 과정을 안내합니다.
Agent 기반 통합은 Datadog Agent가 설치되어 있거나 네트워크를 통해 접근할 수 있는 고객 관리 인프라에서 실행되는 소프트웨어 또는 시스템의 텔레메트리 데이터를 수집하도록 설계되었습니다. 이 통합은 승인된 기술 파트너가 개발한 사용자 지정 Agent 검사를 통해 Datadog Agent가 데이터를 수집하고 제출할 수 있도록 합니다.
Agent 검사는 고객의 Datadog 계정에 메트릭, 이벤트, 로그를 전송할 수 있습니다. 각 Agent 기반 통합은 Datadog Agent를 기반으로 빌드된 Python 패키지로 고객이 Datadog Agent를 통해 쉽게 설치할 수 있습니다. 다만 트레이스는 Agent 검사 외부에서 Datadog의 SDK 중 하나를 사용해 수집됩니다. 자세한 내용은 애플리케이션 계측 설명서를 참고하세요.
Agent 통합 로그 수집에서는 send_log를 사용해 Agent 검사에서 로그를 수집하는 방법을 설명합니다. 단일 소스 로그 전송에 가장 적합합니다.
HTTP 크롤러 튜토리얼은 여러 로그 소스에서 로그를 수집하는 방법을 설명합니다. 예를 들어 여러 엔드포인트나 외부 HTTP API를 폴링할 때 사용됩니다.
파일 awesome/datadog_checks/awesome/check.py은 다음과 같을 수 있습니다.
check.py
importrequestsimporttimefromdatadog_checks.baseimportAgentCheck,ConfigurationErrorclassAwesomeCheck(AgentCheck):"""AwesomeCheck derives from AgentCheck, and provides the required check method."""defcheck(self,instance):url=instance.get('url')search_string=instance.get('search_string')# It's a very good idea to do some basic sanity checking.# Try to be as specific as possible with the exceptions.ifnoturlornotsearch_string:raiseConfigurationError('Configuration error, please fix awesome.yaml')try:response=requests.get(url)response.raise_for_status()# Something went horribly wrongexceptExceptionase:# Ideally we'd use a more specific message...self.service_check('awesome.search',self.CRITICAL,message=str(e))# Submit an error logself.send_log({'message':f'Failed to access {url}: {str(e)}','timestamp':time.time(),'status':'error','service':'awesome','url':url})# Page is accessibleelse:# search_string is presentifsearch_stringinresponse.text:self.service_check('awesome.search',self.OK)# Submit an info logself.send_log({'message':f'Successfully found "{search_string}" at {url}','timestamp':time.time(),'status':'info','service':'awesome','url':url,'search_string':search_string})# search_string was not foundelse:self.service_check('awesome.search',self.WARNING)# Submit a warning logself.send_log({'message':f'String "{search_string}" not found at {url}','timestamp':time.time(),'status':'warning','service':'awesome','url':url,'search_string':search_string})
pytest와 hatch는 테스트를 실행하는 데 사용됩니다. 통합을 게시하려면 테스트가 필수입니다.
단위 테스트 작성
Awesome의 check 메서드 첫 부분에서는 구성 파일의 두 가지 요소를 가져와 검증합니다. 이 부분은 단위 테스트를 작성하기에 적합합니다.
awesome/tests/test_awesome.py에 있는 파일을 열고 내용을 다음과 같이 변경하세요.
test_awesome.py
importpytest# Don't forget to import your integrationfromdatadog_checks.awesomeimportAwesomeCheckfromdatadog_checks.baseimportConfigurationError@pytest.mark.unitdeftest_config():instance={}c=AwesomeCheck('awesome',{},[instance])# empty instancewithpytest.raises(ConfigurationError):c.check(instance)# only the urlwithpytest.raises(ConfigurationError):c.check({'url':'http://foobar'})# only the search stringwithpytest.raises(ConfigurationError):c.check({'search_string':'foo'})# this should not failc.check({'url':'http://foobar','search_string':'foo'})
pytest에는 테스트를 카테고리별로 묶는 데 사용할 수 있는 마커 개념이 있습니다. test_config가 unit 테스트로 마킹된 것을 확인하세요.
awesome/tests에 있는 모든 테스트를 실행하도록 스캐폴딩이 설정되어 있습니다. 테스트를 실행하려면 다음 명령을 실행하세요.
다음으로 awesome/tests/conftest.py에 있는 파일을 열고 내용을 다음과 같이 변경합니다.
conftest.py
importosimportpytestfromdatadog_checks.devimportdocker_run,get_docker_hostname,get_hereURL='http://{}:8000'.format(get_docker_hostname())SEARCH_STRING='Thank you for using nginx.'INSTANCE={'url':URL,'search_string':SEARCH_STRING}@pytest.fixture(scope='session')defdd_environment():compose_file=os.path.join(get_here(),'docker-compose.yml')# This does 3 things:## 1. Spins up the services defined in the compose file# 2. Waits for the url to be available before running the tests# 3. Tears down the services when the tests are finishedwithdocker_run(compose_file,endpoints=[URL]):yieldINSTANCE@pytest.fixturedefinstance():returnINSTANCE.copy()
통합 테스트 추가
통합 테스트를 위한 환경을 설정한 후 awesome/tests/test_awesome.py 파일에 통합 테스트를 추가하세요.
test_awesome.py
@pytest.mark.integration@pytest.mark.usefixtures('dd_environment')deftest_service_check(aggregator,instance):c=AwesomeCheck('awesome',{},[instance])# the check should send OKc.check(instance)aggregator.assert_service_check('awesome.search',AwesomeCheck.OK)# the check should send WARNINGinstance['search_string']='Apache'c.check(instance)aggregator.assert_service_check('awesome.search',AwesomeCheck.WARNING)
개발 속도를 높이려면 -m/--marker 옵션을 사용해 통합 테스트만 실행하세요.
ddev test -m integration awesome
Agent 검사 테스트
Agent 기반 통합은 고객이 Datadog Agent를 통해 설치하는 Python 휠(.whl) 파일로 배포됩니다. 통합을 게시하기 전에 휠 패키지를 수동으로 빌드하고 설치해 로컬에서 테스트할 수 있습니다.
휠 빌드하기
pyproject.toml 파일은 휠을 패키징하고 빌드하는 데 사용되는 메타데이터를 제공합니다. 휠에는 Agent 검사, 구성 예시 파일 및 휠 빌드 중 생성된 아티팩트 등 통합 자체의 기능 작동에 필요한 파일이 포함되어 있습니다.
기능을 추가, 제거 또는 수정할 때마다 버전 상향이 필요합니다(예: 새 메트릭 도입, 대시보드 업데이트, 통합 코드 변경 시). 텍스트 콘텐츠 변경, 브랜딩, 로고 또는 이미지 변경 등의 비기능적 업데이트에는 필요하지 않습니다.
다음 형식을 따라 개발자 플랫폼에서 릴리스 노트 탭에 새 항목을 포함하세요.
## Version Number / Date (YYYY-MM-DD)
***Added***:
* Description of new feature
* Description of new feature
***Fixed***:
* Description of fix
* Description of fix
***Changed***:
* Description of update or improvement
* Description of update or improvement
***Removed***:
* Description of removed feature
* Description of removed feature