<1> API Tracing 각 단계 로깅, 실패 확인


1. IS 서비스 설정


insert_elasticsearch_1~5 까지 생성

  1. MAP

  • request_id (request 별 id 값을 저장) : 001로 Test
  • apiName (APIs 의 name값) : BANK-001
  • status (상태 값 , Test에서는 policy 경로 이름을 명명하였음)
    • _1 identify_access
    • _2 request_processing
    • _3 routing
    • _4 response_processing
  • current_time (getCurrentDateString)



  1. client.http



  • url (elasticsearch request url) : http://192.168.1.130:9240/logging_data2/_doc/ 로 테스트
  • method : post
    • put method로 elasticsearch에 입력이 가능하지만 id값을 특정 지어 url 뒤에 붙여야 함
    • pub.apigateway.invokeISService.specifications:RequestSpec 로 input값을 지정 시에 flow 에서 currentID값을 id값으로 지정하여 url : http://192.168.1.130:9240/logging_data2/_doc/(currentID)값 으로 입력하면 가능할 수도..
  • data : documentToJSONString 에서 생성된 jsonString을 매핑
  • auth : user > Administrator // pass > manage
  • headers : content-Type > application/json


같은 방법으로 insert_elasicsearch_1~4 까지 생성


2. Gateway Policy 설정


+) Comply To Spec을 True로 설정 후 테스트 시에 정상 호출 시 마지막 log 인 Response Processing 만 남음,
중간 Request 단계에서 오류를 발생 시켰을 때 IS service 를 invoke 하지 않아 Logging 이 안되는 문제가 있음



3. Elasticsearch 설정

내부 Elasticsearch 에 로그를 받을 Index를 생성 (logging_data2 생성)

+) 인덱스 삭제



4. 호출 테스트

  1. 정상 호출 시 log


http://192.168.1.130:9240/logging_data2/_search

결과 값

{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "D83lGXgBLr9HF4rsAS82",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Identify_Access",
"current_time": "170901"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "EM3lGXgBLr9HF4rsAS88",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "RequestProcessing",
"current_time": "170901"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "Ec3lGXgBLr9HF4rsAS9J",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Routing",
"current_time": "170901"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "Es3lGXgBLr9HF4rsAS9g",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "ResponseProcessing",
"current_time": "170901"
}
}
]
}
}


  1. Identify_Access Error 시에


{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "GM3mGXgBLr9HF4rsyi9B",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Identify_Access",
"current_time": "171058"
}
}
]
}
}


+)

Policy 설정 시 순서를 변경 시키면

{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}

호출 시에 identify 에서 error가 발생하여 custom extension이 실행되지 않음
=> policy 설정 순서에 영향을 받는 듯


  1. Request Processing 에서 Error 발생


{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "HM3qGXgBLr9HF4rsKC_k",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Identify_Access",
"current_time": "171439"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "Hc3qGXgBLr9HF4rsKC_t",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "RequestProcessing",
"current_time": "171439"
}
}
]
}
}

+) Policy 설정 순서를 바꾸어 테스트 시


{
"took": 591,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "Is3rGXgBLr9HF4rsuy_f",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Identify_Access",
"current_time": "171622"
}
}
]
}
}


  1. Rountig 에서 Error 발생 시킬 때


{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "KM3tGXgBLr9HF4rsvC_F",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Identify_Access",
"current_time": "171834"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "Kc3tGXgBLr9HF4rsvC_N",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "RequestProcessing",
"current_time": "171834"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "Ks3tGXgBLr9HF4rsvC_Y",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Routing",
"current_time": "171834"
}
}
]
}
}

+) 순서를 바꾸면 Routing 이 IS service 가 Invoke 되지 않음



추가 스터디 자료 정리

  • request_id 값에 들어갈 id를 발생 시키는 방법, 매핑 하는 방법 생각하기
  • apiName 도 마찬가지로 강제 입력한 값이 아닌 입력 받을 것인지, 불러와서 input값으로 설정할 것인지 생각해보기
  • Comply to IS Spec (pub.apigateway.invokeISService.specifications)을 이용하면 savePipelineToFile 서비스를 이용하여 txt 파일을 찍어 냈을 때 corrcetionID값이 이어 지는 것을 확인 할 수 있는데, 이 값을 id 값으로 이용할 수 있는지 테스트..(true 설정 시 logging이 안되.. 어떻게 해결 해야 할지..)




<2> Response Processing 에서 Errorcode Logging



+) Error 코드 Response Processing 화면에서 추가

예시 서비스 구현

(BANK-001 API 예시)



  • Try Sequence 쪽 MAP
    • code (document)
      • http_code : 200
      • rsp_code : 00000
      • rsp_msg : 성공
      • description : 처리 성공


  • Catch Sequence 쪽 MAP -> getLastError의 error 필드와 errorDump 필드를 이용해서 Error_doc 를 Response 받는다고 가정
    • Error_doc (document)
      • http_code : 400 Error로 가정
      • rsp_code : 40101 로 가정
      • rsp_msg : error 메세지로 가정
      • description : errorDump 로 가정




Response Processing Custom Extension 설정

  1. 예시 IS 서비스 수정 (insert_elasticsearch_Error_2)


Specification Reference : pub.apigateway.invokeISService.specifications:RequestSpec 로 설정


  1. Gateway Custom Extension 수정

Gateway 설정에서 Comply to IS Spec : true
기존 Invoke IS 서비스를 (insert_elasticsearch_Error_2) 로 변경



Payload 값을 분기로 Exception이 포함되어있으면 Error Logging 처리(예시) // default로는 성공 Logging 처리

  1. Elasticsearch 설정


{
"settings":{
"number_of_shards" :1,
"number_of_replicas":1
},
"mappings": {
"properties": {
"apiName": {
"type": "text"
},
"current_time": {
"type": "text"
},
"request_id": {
"type": "text"
},
"status": {
"type": "text"
},
"error_msg" : {
"type":"nested"
}
}
}
}


  1. 호출 테스트

4-1. 정상 호출 시



Logging Index(logging_data2) 결과 값

{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "VCDnJHgBMbvGprlb-sJi",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Identify_Access",
"current_time": "202805"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "VSDnJHgBMbvGprlb-sJn",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "RequestProcessing",
"current_time": "202805"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "ViDnJHgBMbvGprlb-sJz",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Routing",
"current_time": "202806"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "VyDnJHgBMbvGprlb-sJ5",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "ResponseProcessing",
"current_time": "202806",
"error_msg": {
"code": {
"http_code": "200",
"rsp_code": "00000",
"rsp_msg": "성공",
"description": "호출성공"
},
"result": "0",
"status": "Success",
"계좌목록": {
"계좌번호1": "110-176-068697",
"계좌번호2": "110-252-352612",
"계좌번호3": "110-235-126236"
}
}
}
}
]
}
}

4-2 에러 발생 시



Logging Index(logging_data2) 결과 값

{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "WCDpJHgBMbvGprlbacJ4",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Identify_Access",
"current_time": "202939"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "WSDpJHgBMbvGprlbacJ-",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "RequestProcessing",
"current_time": "202939"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "WiDpJHgBMbvGprlbacKL",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Routing",
"current_time": "202939"
}
},
{
"_index": "logging_data2",
"_type": "_doc",
"_id": "WyDpJHgBMbvGprlbacKQ",
"_score": 1.0,
"_source": {
"request_id": "001",
"apiName": "BANK-001",
"status": "Error",
"current_time": "202939",
"error_msg": {
"http_code": "400(Bad Request)",
"rsp_code": "40101",
"rsp_msg": "java.lang.NumberFormatException: b",
"description": "com.wm.app.b2b.server.ServiceException: java.lang.NumberFormatException: b\n\tat pub.math.addInts(math.java:427)\n\tat sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:411)\n\tat com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:739)\n\tat com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:46)\n\tat com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:61)\n\tat com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:250)\n\tat com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:56)\n\tat com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:178)\n\tat com.wm.app.b2b.server.ACLManager.process(ACLManager.java:334)\n\tat com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:41)\n\tat com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:401)\n\tat com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:611)\n\tat com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:423)\n\tat com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:381)\n\tat com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:253)\n\tat com.wm.app.b2b.server.BaseService.invoke(BaseService.java:236)\n\tat com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:267)\n\tat com.wm.lang.flow.FlowState.invokeNode(FlowState.java:668)\n\tat com.wm.lang.flow.FlowState.step(FlowState.java:534)\n\tat com.wm.lang.flow.FlowState.invoke(FlowState.java:501)\n\tat com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:1150)\n\tat com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:739)\n\tat com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:46)\n\tat com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:61)\n\tat com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:250)\n\tat com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:56)\n\tat com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:178)\n\tat com.wm.app.b2b.server.ACLManager.process(ACLManager.java:334)\n\tat com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:41)\n\tat com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:401)\n\tat com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:611)\n\tat com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:423)\n\tat com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:381)\n\tat com.wm.app.b2b.server.HTTPInvokeHandler._process(HTTPInvokeHandler.java:267)\n\tat com.wm.app.b2b.server.RESTHandlerV2.process(RESTHandlerV2.java:146)\n\tat com.wm.app.b2b.server.HTTPDispatch.handleRequest(HTTPDispatch.java:223)\n\tat com.wm.app.b2b.server.Dispatch.run(Dispatch.java:430)\n\tat com.wm.util.pool.PooledThread.run(PooledThread.java:134)\n\tat java.lang.Thread.run(Thread.java:748)\nCaused by: java.lang.NumberFormatException: b\n\tat pub.math.addInts(math.java:414)\n\t... 41 more\n"
}
}
}
]
}
}