Skip to content

Commit 0734f4d

Browse files
authored
Feat: Enable hystrix metrics stream for core APIML services (#1899)
* Enable hystrix stream for api catalog Signed-off-by: Carson Cook <carson.cook@ibm.com> * Remove hystrix dashboard from ac Signed-off-by: Carson Cook <carson.cook@ibm.com> * Enable hystrix metrics for caching service Signed-off-by: Carson Cook <carson.cook@ibm.com> * Enable hystrix metrics for gateway Signed-off-by: Carson Cook <carson.cook@ibm.com> * Enable hystrix metrics for discovery service Signed-off-by: Carson Cook <carson.cook@ibm.com> * Add flag to enable access to hystrix stream Signed-off-by: Carson Cook <carson.cook@ibm.com> * Remove unused imports Signed-off-by: Carson Cook <carson.cook@ibm.com> * Add HystrixCommand to missed controllers Signed-off-by: Carson Cook <carson.cook@ibm.com>
1 parent a0a7f9e commit 0734f4d

36 files changed

+152
-41
lines changed

api-catalog-services/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ dependencies {
6464
implementation libraries.spring_boot_starter_actuator
6565
implementation libraries.spring_boot_configuration_processor
6666
implementation libraries.spring_cloud_starter_eureka
67+
implementation libraries.spring_cloud_starter_hystrix
6768
implementation libraries.spring_retry
6869
implementation libraries.swagger_core
6970
implementation libraries.swagger3_core

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/ApiCatalogApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
import org.springframework.boot.SpringApplication;
1313
import org.springframework.boot.autoconfigure.SpringBootApplication;
14+
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
1415
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
15-
import org.springframework.cloud.netflix.hystrix.HystrixAutoConfiguration;
1616
import org.springframework.context.annotation.ComponentScan;
1717
import org.springframework.retry.annotation.EnableRetry;
1818
import org.springframework.scheduling.annotation.EnableAsync;
@@ -21,7 +21,7 @@
2121
import org.zowe.apiml.product.monitoring.LatencyUtilsConfigInitializer;
2222
import org.zowe.apiml.product.version.BuildInfo;
2323

24-
@SpringBootApplication(exclude = HystrixAutoConfiguration.class)
24+
@SpringBootApplication
2525
@EnableEurekaClient
2626
@ComponentScan(value = {
2727
"org.zowe.apiml.apicatalog",
@@ -33,6 +33,7 @@
3333
@EnableRetry
3434
@EnableAsync
3535
@EnableApimlLogger
36+
@EnableCircuitBreaker
3637
public class ApiCatalogApplication {
3738

3839
public static void main(String[] args) {

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/controllers/api/ApiCatalogController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.zowe.apiml.apicatalog.controllers.api;
1111

12+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
1213
import io.swagger.annotations.Api;
1314
import io.swagger.annotations.ApiOperation;
1415
import io.swagger.annotations.Authorization;
@@ -75,6 +76,7 @@ public ApiCatalogController(CachedProductFamilyService cachedProductFamilyServic
7576
@Authorization("LoginBasicAuth"), @Authorization("CookieAuth")
7677
}
7778
)
79+
@HystrixCommand
7880
public ResponseEntity<List<APIContainer>> getAllAPIContainers() throws ContainerStatusRetrievalThrowable {
7981
try {
8082
Iterable<APIContainer> allContainers = cachedProductFamilyService.getAllContainers();
@@ -104,6 +106,7 @@ public ResponseEntity<List<APIContainer>> getAllAPIContainers() throws Container
104106
@Authorization("LoginBasicAuth"), @Authorization("CookieAuth")
105107
}
106108
)
109+
@HystrixCommand
107110
public ResponseEntity<List<APIContainer>> getAPIContainerById(@PathVariable(value = "id") String id) throws ContainerStatusRetrievalThrowable {
108111
try {
109112
List<APIContainer> apiContainers = new ArrayList<>();

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/controllers/api/CatalogApiDocController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.zowe.apiml.apicatalog.controllers.api;
1111

12+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
1213
import org.zowe.apiml.apicatalog.services.status.APIServiceStatusService;
1314
import io.swagger.annotations.*;
1415
import org.springframework.beans.factory.annotation.Autowired;
@@ -63,6 +64,7 @@ public CatalogApiDocController(APIServiceStatusService apiServiceStatusService)
6364
@ApiResponse(code = 404, message = "URI not found"),
6465
@ApiResponse(code = 500, message = "An unexpected condition occurred"),
6566
})
67+
@HystrixCommand
6668
public ResponseEntity<String> getApiDocInfo(
6769
@ApiParam(name = "serviceId", value = "The unique identifier of the registered service", required = true, example = "apicatalog")
6870
@PathVariable(value = "serviceId") String serviceId,
@@ -89,6 +91,7 @@ public ResponseEntity<String> getApiDocInfo(
8991
@ApiResponse(code = 404, message = "URI not found"),
9092
@ApiResponse(code = 500, message = "An unexpected condition occurred"),
9193
})
94+
@HystrixCommand
9295
public ResponseEntity<String> getApiDiff(
9396
@ApiParam(name = "serviceId", value = "The unique identifier of the registered service", required = true, example = "apicatalog")
9497
@PathVariable(value = "serviceId") String serviceId,

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/controllers/handlers/NotFoundErrorController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.zowe.apiml.apicatalog.controllers.handlers;
1111

12+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
1213
import org.springframework.boot.web.servlet.error.ErrorController;
1314
import org.springframework.core.Ordered;
1415
import org.springframework.core.annotation.Order;
@@ -32,6 +33,7 @@ public class NotFoundErrorController implements ErrorController {
3233

3334

3435
@GetMapping(value = "/not_found")
36+
@HystrixCommand
3537
public String handleError(HttpServletRequest request) {
3638
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
3739

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/security/SecurityConfiguration.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public class SecurityConfiguration {
7272
@Value("${server.attls.enabled:false}")
7373
private boolean isAttlsEnabled;
7474

75+
@Value("${apiml.metrics.enabled:false}")
76+
private boolean isMetricsEnabled;
77+
7578
/**
7679
* Filter chain for protecting /apidoc/** endpoints with MF credentials for client certificate.
7780
*/
@@ -164,8 +167,15 @@ protected void configure(HttpSecurity http) throws Exception {
164167
.antMatchers("/static-api/**").authenticated()
165168
.antMatchers("/containers/**").authenticated()
166169
.antMatchers(APIDOC_ROUTES).authenticated()
167-
.antMatchers("/application/health", "/application/info").permitAll()
168-
.antMatchers("/application/**").authenticated();
170+
.antMatchers("/application/health", "/application/info").permitAll();
171+
172+
if (isMetricsEnabled) {
173+
http.authorizeRequests().antMatchers("/application/hystrix.stream").permitAll();
174+
}
175+
176+
177+
http.authorizeRequests().antMatchers("/application/**").authenticated();
178+
169179
if (isAttlsEnabled) {
170180
http.addFilterBefore(new SecureConnectionFilter(), BasicContentFilter.class);
171181
}

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/staticapi/StaticAPIRefreshController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.zowe.apiml.apicatalog.staticapi;
1111

12+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
1213
import lombok.RequiredArgsConstructor;
1314
import org.springframework.http.MediaType;
1415
import org.springframework.http.ResponseEntity;
@@ -24,6 +25,7 @@ public class StaticAPIRefreshController {
2425
private final StaticAPIService staticAPIService;
2526

2627
@PostMapping(value = "/refresh", produces = MediaType.APPLICATION_JSON_VALUE)
28+
@HystrixCommand
2729
public ResponseEntity<String> refreshStaticApis() {
2830
StaticAPIResponse staticAPIResponse = staticAPIService.refresh();
2931
return ResponseEntity

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/staticapi/StaticDefinitionController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
package org.zowe.apiml.apicatalog.staticapi;
1212

13+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
1314
import lombok.RequiredArgsConstructor;
1415
import org.springframework.http.MediaType;
1516
import org.springframework.http.ResponseEntity;
@@ -36,6 +37,7 @@ public class StaticDefinitionController {
3637
* @return the response entity
3738
*/
3839
@PostMapping(value = "/generate", produces = MediaType.APPLICATION_JSON_VALUE)
40+
@HystrixCommand
3941
public ResponseEntity<String> generateStaticDef(@RequestBody String payload, @RequestHeader(value = "Service-Id") String serviceId) throws IOException {
4042
StaticAPIResponse staticAPIResponse = staticDefinitionGenerator.generateFile(payload, serviceId);
4143
return ResponseEntity
@@ -50,6 +52,7 @@ public ResponseEntity<String> generateStaticDef(@RequestBody String payload, @Re
5052
* @return the response entity
5153
*/
5254
@PostMapping(value = "/override", produces = MediaType.APPLICATION_JSON_VALUE)
55+
@HystrixCommand
5356
public ResponseEntity<String> overrideStaticDef(@RequestBody String payload, @RequestHeader(value = "Service-Id") String serviceId) throws IOException {
5457
StaticAPIResponse staticAPIResponse = staticDefinitionGenerator.overrideFile(payload, serviceId);
5558
return ResponseEntity
@@ -59,6 +62,7 @@ public ResponseEntity<String> overrideStaticDef(@RequestBody String payload, @Re
5962

6063

6164
@DeleteMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
65+
@HystrixCommand
6266
public ResponseEntity<String> deleteStaticDef(@RequestHeader(value = "Service-Id") String serviceId) throws IOException {
6367
StaticAPIResponse staticAPIResponse = staticDefinitionGenerator.deleteFile(serviceId);
6468
return ResponseEntity.status(staticAPIResponse.getStatusCode()).body(staticAPIResponse.getBody());

api-catalog-services/src/main/resources/application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ management:
157157
web:
158158
base-path: /application
159159
exposure:
160-
include: health,info
160+
include: health,info,hystrix.stream
161161
health:
162162
defaults:
163163
enabled: false
@@ -175,7 +175,7 @@ management:
175175
web:
176176
base-path: /application
177177
exposure:
178-
include: health,info,loggers
178+
include: health,info,loggers,hystrix.stream
179179

180180
logging:
181181
level:

caching-service/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dependencies {
6161
implementation libraries.spring_boot_starter_actuator
6262
implementation libraries.spring_retry
6363
implementation libraries.spring_boot_starter_aop
64+
implementation libraries.spring_cloud_starter_hystrix
6465
implementation libraries.lettuce
6566
implementation libraries.spring_security_web
6667
implementation libraries.spring_security_config

0 commit comments

Comments
 (0)