-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.23.0' into main
- Loading branch information
Showing
277 changed files
with
2,549 additions
and
1,564 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: PR Labeler | ||
on: | ||
pull_request: | ||
pull_request_target: | ||
types: [opened] | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.22.0 | ||
0.23.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
backend/api/admin/src/main/java/co/airy/core/api/config/ComponentResponsePayload.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
backend/api/admin/src/main/java/co/airy/core/api/config/ComponentsResponsePayload.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
backend/api/admin/src/main/java/co/airy/core/api/config/HealthApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package co.airy.core.api.config; | ||
|
||
import co.airy.log.AiryLoggerFactory; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.scheduling.annotation.AsyncResult; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
@Component | ||
public class HealthApi { | ||
private static final Logger log = AiryLoggerFactory.getLogger(HealthApi.class); | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
private final String namespace; | ||
private final RestTemplate restTemplate; | ||
|
||
public HealthApi(@Value("${kubernetes.namespace}") String namespace, RestTemplate restTemplate) { | ||
this.namespace = namespace; | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
@Async | ||
public Future<Boolean> isHealthy(String service) { | ||
try { | ||
final ResponseEntity<String> response = restTemplate.getForEntity(String.format("http://%s.%s/actuator/health", service, namespace), String.class); | ||
log.info("response body {}", response.getBody()); | ||
final JsonNode jsonNode = objectMapper.readTree(response.getBody()); | ||
return new AsyncResult<>("UP".equalsIgnoreCase(jsonNode.get("status").textValue())); | ||
} catch (Exception e) { | ||
return new AsyncResult<>(false); | ||
} | ||
} | ||
} | ||
|
55 changes: 40 additions & 15 deletions
55
backend/api/admin/src/main/java/co/airy/core/api/config/ServiceDiscovery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,66 @@ | ||
package co.airy.core.api.config; | ||
|
||
import co.airy.core.api.config.dto.ServiceInfo; | ||
import co.airy.core.api.config.payload.ServicesResponsePayload; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.scheduling.annotation.AsyncResult; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.CopyOnWriteArraySet; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
@Component | ||
public class ServiceDiscovery { | ||
private final String namespace; | ||
private final RestTemplate restTemplate; | ||
private final HealthApi healthApi; | ||
|
||
private Map<String, Map<String, Object>> components = new ConcurrentHashMap<>(); | ||
private final Map<String, ServiceInfo> services = new ConcurrentHashMap<>(); | ||
|
||
public ServiceDiscovery(@Value("${kubernetes.namespace}") String namespace, RestTemplate restTemplate) { | ||
public ServiceDiscovery(@Value("${kubernetes.namespace}") String namespace, RestTemplate restTemplate, HealthApi healthApi) { | ||
this.namespace = namespace; | ||
this.restTemplate = restTemplate; | ||
this.healthApi = healthApi; | ||
} | ||
|
||
public Map<String, Map<String, Object>> getComponents() { | ||
return components; | ||
public Map<String, ServiceInfo> getServices() { | ||
return services; | ||
} | ||
|
||
@Scheduled(fixedRate = 1_000) | ||
private void updateComponentsStatus() { | ||
final ResponseEntity<ComponentsResponsePayload> response = restTemplate.getForEntity("http://airy-controller.default/components", ComponentsResponsePayload.class); | ||
Map<String, Map<String, Object>> newComponents = new ConcurrentHashMap<>(); | ||
for (String component: response.getBody().getComponents()) { | ||
newComponents.put(component, Map.of("enabled", true)); | ||
} | ||
components.clear(); | ||
components.putAll(newComponents); | ||
public void updateComponentsStatus() { | ||
final ResponseEntity<ServicesResponsePayload> response = restTemplate.getForEntity(String.format("http://airy-controller.%s/services", namespace), | ||
ServicesResponsePayload.class); | ||
|
||
final Map<String, ServiceInfo> newServices = response.getBody().getServices(); | ||
// Start all requests in parallel | ||
final Map<String, Future<Boolean>> healthRequests = newServices | ||
.keySet().stream() | ||
.collect(toMap(serviceName -> serviceName, healthApi::isHealthy)); | ||
|
||
healthRequests.forEach((serviceName, value) -> { | ||
Boolean healthResponse; | ||
try { | ||
healthResponse = value.get(30, TimeUnit.SECONDS); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
healthResponse = false; | ||
} | ||
|
||
newServices.get(serviceName).setHealthy(healthResponse); | ||
}); | ||
|
||
this.services.clear(); | ||
this.services.putAll(newServices); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/api/admin/src/main/java/co/airy/core/api/config/dto/ServiceInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package co.airy.core.api.config.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ServiceInfo { | ||
private boolean enabled; | ||
private boolean healthy; | ||
private String component; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
backend/api/admin/src/main/java/co/airy/core/api/config/payload/ServicesResponsePayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package co.airy.core.api.config.payload; | ||
|
||
import co.airy.core.api.config.dto.ServiceInfo; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ServicesResponsePayload implements Serializable { | ||
private Map<String, ServiceInfo> services; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.