Skip to content

Commit 6748f2a

Browse files
committed
Update to remove random exceptions
1 parent 598aed5 commit 6748f2a

File tree

9 files changed

+56
-199
lines changed

9 files changed

+56
-199
lines changed

src/main/java/org/springframework/samples/petclinic/Util.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ public static void waitWithDeviation(int median) {
3636
}
3737
}
3838

39-
public static boolean isEvenDay() {
40-
return LocalDate.now().getDayOfYear() % 2 == 0;
41-
}
42-
4339
public static boolean timeForFakeError() {
4440
String nowMillisStr = Long.toString(System.currentTimeMillis());
4541
return nowMillisStr.endsWith("7");

src/main/java/org/springframework/samples/petclinic/clm/ClmController.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
public class ClmController {
2525

2626
private final OwnerRepository ownerRepository;
27-
private final ErrorService errorService;
2827
private final RestClient restClient;
2928

3029
private static final Logger logger = LoggerFactory.getLogger(ClmController.class);
3130

32-
public ClmController(OwnerRepository ownerRepository, ErrorService errorService, RestClient.Builder restClientBuilder) {
31+
public ClmController(OwnerRepository ownerRepository, RestClient.Builder restClientBuilder) {
3332
this.restClient = restClientBuilder.build();
3433
this.ownerRepository = ownerRepository;
35-
this.errorService = errorService;
3634
}
3735

3836
/**
@@ -47,19 +45,6 @@ public String autoOnly(Model model) {
4745
return "welcome";
4846
}
4947

50-
// What happens when error outside of controller
51-
@GetMapping("/clm/error")
52-
public String error(Model model) {
53-
MetricService.increaseCount("/clm/error");
54-
doWait();
55-
logger.info("/clm/error");
56-
if (timeForFakeError()) {
57-
errorService.iAmError();
58-
}
59-
model.addAttribute("message", "on no!");
60-
return "error";
61-
}
62-
6348
/**
6449
* Besides the auto instrumentation, this also demonstrates a manual trace created by an annotation.
6550
*/
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.springframework.samples.petclinic.clm;
2+
3+
import com.newrelic.api.agent.Trace;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.springframework.samples.petclinic.owner.OwnerRepository;
7+
import org.springframework.samples.petclinic.owner.PetType;
8+
import org.springframework.scheduling.annotation.Scheduled;
9+
import org.springframework.stereotype.Component;
10+
11+
import java.util.List;
12+
13+
@Component
14+
public class ClmJobs {
15+
16+
private final OwnerRepository ownerRepository;
17+
private static final Logger logger = LoggerFactory.getLogger(ClmJobs.class);
18+
19+
public ClmJobs(OwnerRepository ownerRepository) {
20+
this.ownerRepository = ownerRepository;
21+
}
22+
23+
// No CLM expected - needs @Trace annotation
24+
@Scheduled(fixedRate = 35000)
25+
protected void doStuff1() {
26+
logger.info("doStuff1");
27+
List<PetType> petTypes = ownerRepository.findPetTypes();
28+
logger.info("doStuff petTypes {}", petTypes);
29+
}
30+
31+
// Expected CLM - but might be too fast to get recorded
32+
@Trace(dispatcher = true)
33+
@Scheduled(fixedRate = 90000)
34+
protected void doStuff4() {
35+
logger.info("doStuff4");
36+
}
37+
38+
// Expected CLM
39+
@Trace(dispatcher = true)
40+
@Scheduled(fixedRate = 60000)
41+
protected void doStuff2() {
42+
logger.info("doStuff2");
43+
List<PetType> petTypes = ownerRepository.findPetTypes();
44+
logger.info("doStuff2 petTypes {}", petTypes);
45+
}
46+
47+
// Expected CLM
48+
@Trace(dispatcher = true, metricName = "clmJobs/doStuff3")
49+
@Scheduled(fixedRate = 70000)
50+
protected void doStuff3() {
51+
logger.info("doStuff3");
52+
List<PetType> petTypes = ownerRepository.findPetTypes();
53+
logger.info("doStuff3 petTypes {}", petTypes);
54+
}
55+
}

src/main/java/org/springframework/samples/petclinic/clm/ClmJobs.kt

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/main/java/org/springframework/samples/petclinic/clm/ErrorService.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/org/springframework/samples/petclinic/clm/RandomExceptionGenerator.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/main/java/org/springframework/samples/petclinic/system/CrashController.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/main/java/org/springframework/samples/petclinic/vet/VetController.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import org.springframework.data.domain.Page;
2121
import org.springframework.data.domain.PageRequest;
2222
import org.springframework.data.domain.Pageable;
23-
import org.springframework.samples.petclinic.Util;
24-
import org.springframework.samples.petclinic.clm.RandomExceptionGenerator;
2523
import org.springframework.stereotype.Controller;
2624
import org.springframework.ui.Model;
2725
import org.springframework.web.bind.annotation.GetMapping;
@@ -54,9 +52,6 @@ public String showVetList(@RequestParam(defaultValue = "1") int page, Model mode
5452
// Here we are returning an object of type 'Vets' rather than a collection of Vet
5553
// objects so it is simpler for Object-Xml mapping
5654
Vets vets = new Vets();
57-
if (Util.isEvenDay() && System.currentTimeMillis() % 2 == 0) {
58-
throw RandomExceptionGenerator.generateRandomException();
59-
}
6055
Page<Vet> paginated = findPaginated(page);
6156
logger.info("Getting Vets for Page={}", page);
6257
vets.getVetList().addAll(paginated.toList());

tester.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ while true; do
3333
sleep 1
3434
curl -s -o /dev/null http://localhost:8081/vets/Carter
3535
sleep 1
36-
# curl -s -o /dev/null http://localhost:8081/oups
37-
# sleep 1
38-
curl -s -o /dev/null http://localhost:8081/clm/error
39-
sleep 1
4036

4137
timestamp=$(date +"%Y-%m-%dT%H:%M:%S%z")
4238
echo "$timestamp Completed a full set of operations."

0 commit comments

Comments
 (0)