Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6018528bab | |||
| 85a549ad2a | |||
| 2918f35c35 | |||
| 866d344833 | |||
| 05f9cb76d4 | |||
| 67e9b74cad | |||
| 7447f998d8 |
15
.gitignore
vendored
Normal file
15
.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
target/
|
||||
*.class
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
*.log
|
||||
.DS_Store
|
||||
.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.vscode/
|
||||
.mvn/
|
||||
mvnw
|
||||
mvnw.cmd
|
||||
30
Dockerfile
Normal file
30
Dockerfile
Normal file
@@ -0,0 +1,30 @@
|
||||
# ---- Build stage ----
|
||||
FROM maven:3.9-eclipse-temurin-17-alpine AS build
|
||||
WORKDIR /workspace
|
||||
|
||||
COPY pom.xml .
|
||||
RUN mvn dependency:go-offline -q
|
||||
|
||||
COPY src ./src
|
||||
RUN mvn package -DskipTests -q
|
||||
|
||||
# ---- Runtime stage ----
|
||||
FROM eclipse-temurin:17-jre-alpine
|
||||
WORKDIR /app
|
||||
|
||||
# Download OTel Java agent for zero-code auto-instrumentation
|
||||
RUN wget -q -O /app/otel-agent.jar \
|
||||
"https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.5.0/opentelemetry-javaagent.jar"
|
||||
|
||||
# Non-root user
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
USER appuser
|
||||
|
||||
COPY --from=build /workspace/target/*.jar app.jar
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
|
||||
CMD wget -qO- http://localhost:8080/actuator/health | grep -q '"status":"UP"' || exit 1
|
||||
|
||||
ENTRYPOINT ["java", "-javaagent:/app/otel-agent.jar", "-jar", "app.jar"]
|
||||
57
pom.xml
Normal file
57
pom.xml
Normal file
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.kyndryl.platform</groupId>
|
||||
<artifactId>test-for-174--014</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>test-for-174--014</name>
|
||||
<description>Test for issue 174 PR</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Actuator for health + prometheus metrics -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
11
src/main/java/com/kyndryl/platform/service/Application.java
Normal file
11
src/main/java/com/kyndryl/platform/service/Application.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.kyndryl.platform.service;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.kyndryl.platform.service;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* A minimal but fully functional CRUD REST API for "items".
|
||||
*
|
||||
* Endpoints:
|
||||
* GET /api/items — list all items
|
||||
* POST /api/items — create an item { "name": "...", "description": "..." }
|
||||
* GET /api/items/{id} — get single item
|
||||
* PUT /api/items/{id} — update item
|
||||
* DELETE /api/items/{id} — delete item
|
||||
*
|
||||
* Health + metrics are exposed via Spring Actuator at /actuator/health and
|
||||
* /actuator/prometheus (see application.yml).
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/items")
|
||||
public class ItemsController {
|
||||
|
||||
record Item(long id, String name, String description) {}
|
||||
|
||||
private final Map<Long, Item> store = new ConcurrentHashMap<>();
|
||||
private final AtomicLong counter = new AtomicLong(1);
|
||||
|
||||
@GetMapping
|
||||
public Collection<Item> list() {
|
||||
return store.values();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public Item create(@RequestBody Map<String, String> body) {
|
||||
long id = counter.getAndIncrement();
|
||||
Item item = new Item(id,
|
||||
body.getOrDefault("name", "unnamed"),
|
||||
body.getOrDefault("description", ""));
|
||||
store.put(id, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Item get(@PathVariable long id) {
|
||||
Item item = store.get(id);
|
||||
if (item == null) throw new NoSuchElementException("Item not found: " + id);
|
||||
return item;
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public Item update(@PathVariable long id, @RequestBody Map<String, String> body) {
|
||||
if (!store.containsKey(id)) throw new NoSuchElementException("Item not found: " + id);
|
||||
Item updated = new Item(id,
|
||||
body.getOrDefault("name", store.get(id).name()),
|
||||
body.getOrDefault("description", store.get(id).description()));
|
||||
store.put(id, updated);
|
||||
return updated;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable long id) {
|
||||
store.remove(id);
|
||||
return Map.of("deleted", id);
|
||||
}
|
||||
}
|
||||
21
src/main/resources/application.yml
Normal file
21
src/main/resources/application.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: test-for-174--014
|
||||
profiles:
|
||||
active: ${SPRING_PROFILES_ACTIVE:default}
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,prometheus,metrics
|
||||
base-path: /actuator
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
metrics:
|
||||
tags:
|
||||
application: test-for-174--014
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.kyndryl.platform.service;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user