🎨 Format
This commit is contained in:
parent
16a5627b39
commit
e165df6076
18
pom.xml
18
pom.xml
@ -163,6 +163,24 @@
|
|||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>net.revelc.code.formatter</groupId>
|
||||||
|
<artifactId>formatter-maven-plugin</artifactId>
|
||||||
|
<version>2.29.0</version>
|
||||||
|
<configuration>
|
||||||
|
<configFile>https://git.dinauer.dev/andreas.dinauer/formatter/raw/branch/main/format.xml</configFile>
|
||||||
|
<lineEnding>LF</lineEnding>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>validate</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>net.revelc.code</groupId>
|
<groupId>net.revelc.code</groupId>
|
||||||
<artifactId>impsort-maven-plugin</artifactId>
|
<artifactId>impsort-maven-plugin</artifactId>
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public class IngressResource
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<Ingress> getIngresses(@QueryParam("namespace") String namespace)
|
public List<Ingress> getIngresses(@QueryParam("namespace") String namespace)
|
||||||
{
|
{
|
||||||
if(namespace != null)
|
if (namespace != null)
|
||||||
{
|
{
|
||||||
ingressService.findByNamespace(namespace);
|
ingressService.findByNamespace(namespace);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,10 +47,10 @@ public class ProcessRunner
|
|||||||
List<String> text = new ArrayList<>();
|
List<String> text = new ArrayList<>();
|
||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
executor.submit(() -> {
|
executor.submit(() -> {
|
||||||
try(BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())))
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())))
|
||||||
{
|
{
|
||||||
String line;
|
String line;
|
||||||
while((line = br.readLine()) != null)
|
while ((line = br.readLine()) != null)
|
||||||
{
|
{
|
||||||
text.add(line);
|
text.add(line);
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ public class ProcessRunner
|
|||||||
process.destroyForcibly();
|
process.destroyForcibly();
|
||||||
if (endedInTime)
|
if (endedInTime)
|
||||||
{
|
{
|
||||||
if(exitCode == 0)
|
if (exitCode == 0)
|
||||||
{
|
{
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,7 +86,7 @@ public class ResourceResource
|
|||||||
{
|
{
|
||||||
if (ResourceType.DEPLOYMENT.equals(resourceType))
|
if (ResourceType.DEPLOYMENT.equals(resourceType))
|
||||||
{
|
{
|
||||||
if(namespace != null && !namespace.isBlank() && name != null && !name.isBlank() && replicaCount != null && replicaCount > 0)
|
if (namespace != null && !namespace.isBlank() && name != null && !name.isBlank() && replicaCount != null && replicaCount > 0)
|
||||||
{
|
{
|
||||||
deploymentService.rescale(namespace, name, replicaCount);
|
deploymentService.rescale(namespace, name, replicaCount);
|
||||||
}
|
}
|
||||||
@ -101,44 +101,34 @@ public class ResourceResource
|
|||||||
{
|
{
|
||||||
switch (resourceType)
|
switch (resourceType)
|
||||||
{
|
{
|
||||||
case ResourceType.STATEFUL_SET ->
|
case ResourceType.STATEFUL_SET -> {
|
||||||
{
|
|
||||||
return statefulSetService;
|
return statefulSetService;
|
||||||
}
|
}
|
||||||
case ResourceType.DEPLOYMENT ->
|
case ResourceType.DEPLOYMENT -> {
|
||||||
{
|
|
||||||
return deploymentService;
|
return deploymentService;
|
||||||
}
|
}
|
||||||
case ResourceType.SERVICE ->
|
case ResourceType.SERVICE -> {
|
||||||
{
|
|
||||||
return serviceService;
|
return serviceService;
|
||||||
}
|
}
|
||||||
case ResourceType.INGRESS ->
|
case ResourceType.INGRESS -> {
|
||||||
{
|
|
||||||
return ingressService;
|
return ingressService;
|
||||||
}
|
}
|
||||||
case ResourceType.POD ->
|
case ResourceType.POD -> {
|
||||||
{
|
|
||||||
return podService;
|
return podService;
|
||||||
}
|
}
|
||||||
case ResourceType.CUSTOM_RESOURCE_DEFINITION ->
|
case ResourceType.CUSTOM_RESOURCE_DEFINITION -> {
|
||||||
{
|
|
||||||
return customResourceDefinitionService;
|
return customResourceDefinitionService;
|
||||||
}
|
}
|
||||||
case ResourceType.NODE ->
|
case ResourceType.NODE -> {
|
||||||
{
|
|
||||||
return nodeService;
|
return nodeService;
|
||||||
}
|
}
|
||||||
case ResourceType.SECRET ->
|
case ResourceType.SECRET -> {
|
||||||
{
|
|
||||||
return secretService;
|
return secretService;
|
||||||
}
|
}
|
||||||
case ResourceType.CONFIG_MAP ->
|
case ResourceType.CONFIG_MAP -> {
|
||||||
{
|
|
||||||
return configMapService;
|
return configMapService;
|
||||||
}
|
}
|
||||||
default ->
|
default -> {
|
||||||
{
|
|
||||||
LOG.errorf("Invalid resource type %s.", resourceType);
|
LOG.errorf("Invalid resource type %s.", resourceType);
|
||||||
throw new BadRequestException();
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,36 +3,33 @@ package dev.dinauer;
|
|||||||
public enum ResourceType
|
public enum ResourceType
|
||||||
{
|
{
|
||||||
// Cluster Resources
|
// Cluster Resources
|
||||||
NODE("nodes"),
|
NODE("nodes"), NAMESPACE("namespaces"), CUSTOM_RESOURCE_DEFINITION("custom-resource-definitions"),
|
||||||
NAMESPACE("namespaces"),
|
|
||||||
CUSTOM_RESOURCE_DEFINITION("custom-resource-definitions"),
|
|
||||||
|
|
||||||
// Workloads
|
// Workloads
|
||||||
STATEFUL_SET("stateful-sets"),
|
STATEFUL_SET("stateful-sets"), DEPLOYMENT("deployments"), POD("pods"),
|
||||||
DEPLOYMENT("deployments"),
|
|
||||||
POD("pods"),
|
|
||||||
|
|
||||||
// Networking
|
// Networking
|
||||||
SERVICE("services"),
|
SERVICE("services"), INGRESS("ingresses"),
|
||||||
INGRESS("ingresses"),
|
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
SECRET("secrets"),
|
SECRET("secrets"), CONFIG_MAP("config-maps"),
|
||||||
CONFIG_MAP("config-maps"),
|
|
||||||
|
|
||||||
// Storage
|
// Storage
|
||||||
PVC("pvcs"),
|
PVC("pvcs"), PV("pvs");
|
||||||
PV("pvs");
|
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
ResourceType(String value) {
|
ResourceType(String value)
|
||||||
|
{
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceType fromString(String text) {
|
public static ResourceType fromString(String text)
|
||||||
for (ResourceType type : ResourceType.values()) {
|
{
|
||||||
if (type.value.equalsIgnoreCase(text)) {
|
for (ResourceType type : ResourceType.values())
|
||||||
|
{
|
||||||
|
if (type.value.equalsIgnoreCase(text))
|
||||||
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +37,8 @@ public enum ResourceType
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ public class ServiceResource
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<Service> getServices(@QueryParam("namespace") String namespace)
|
public List<Service> getServices(@QueryParam("namespace") String namespace)
|
||||||
{
|
{
|
||||||
if(namespace != null && !namespace.isBlank())
|
if (namespace != null && !namespace.isBlank())
|
||||||
{
|
{
|
||||||
return serviceService.findByNamespace(namespace);
|
return serviceService.findByNamespace(namespace);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public class LogWebsocket
|
|||||||
LogWatch watch = clientProvider.getClient().pods().inNamespace(namespace).withName(name).usingTimestamps().tailingLines(0).watchLog();
|
LogWatch watch = clientProvider.getClient().pods().inNamespace(namespace).withName(name).usingTimestamps().tailingLines(0).watchLog();
|
||||||
sessions.put(session, watch);
|
sessions.put(session, watch);
|
||||||
|
|
||||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(watch.getOutput())))
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(watch.getOutput())))
|
||||||
{
|
{
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null && !Thread.currentThread().isInterrupted())
|
while ((line = reader.readLine()) != null && !Thread.currentThread().isInterrupted())
|
||||||
|
|||||||
@ -49,8 +49,7 @@ public class ResourceWebsocket
|
|||||||
ResourceType resourceType = ResourceType.fromString(rawResourceType);
|
ResourceType resourceType = ResourceType.fromString(rawResourceType);
|
||||||
if (tokenService.validateTokenByQueryString(session.getQueryString()))
|
if (tokenService.validateTokenByQueryString(session.getQueryString()))
|
||||||
{
|
{
|
||||||
executor.submit(() ->
|
executor.submit(() -> {
|
||||||
{
|
|
||||||
ResourceService<?> service = serviceFactory.getService(resourceType);
|
ResourceService<?> service = serviceFactory.getService(resourceType);
|
||||||
send(session, EventType.INIT, service.findByNamespace(namespace));
|
send(session, EventType.INIT, service.findByNamespace(namespace));
|
||||||
sessions.put(session, service.watch(namespace, getWatcher(session)));
|
sessions.put(session, service.watch(namespace, getWatcher(session)));
|
||||||
|
|||||||
@ -55,55 +55,55 @@ public class ServiceFactory
|
|||||||
{
|
{
|
||||||
switch (resourceType)
|
switch (resourceType)
|
||||||
{
|
{
|
||||||
case ResourceType.STATEFUL_SET ->
|
case ResourceType.STATEFUL_SET:
|
||||||
{
|
{
|
||||||
return statefulSetService;
|
return statefulSetService;
|
||||||
}
|
}
|
||||||
case ResourceType.DEPLOYMENT ->
|
case ResourceType.DEPLOYMENT:
|
||||||
{
|
{
|
||||||
return deploymentService;
|
return deploymentService;
|
||||||
}
|
}
|
||||||
case ResourceType.SERVICE ->
|
case ResourceType.SERVICE:
|
||||||
{
|
{
|
||||||
return serviceService;
|
return serviceService;
|
||||||
}
|
}
|
||||||
case ResourceType.INGRESS ->
|
case ResourceType.INGRESS:
|
||||||
{
|
{
|
||||||
return ingressService;
|
return ingressService;
|
||||||
}
|
}
|
||||||
case ResourceType.POD ->
|
case ResourceType.POD:
|
||||||
{
|
{
|
||||||
return podService;
|
return podService;
|
||||||
}
|
}
|
||||||
case ResourceType.CUSTOM_RESOURCE_DEFINITION ->
|
case ResourceType.CUSTOM_RESOURCE_DEFINITION:
|
||||||
{
|
{
|
||||||
return customResourceDefinitionService;
|
return customResourceDefinitionService;
|
||||||
}
|
}
|
||||||
case ResourceType.NODE ->
|
case ResourceType.NODE:
|
||||||
{
|
{
|
||||||
return nodeService;
|
return nodeService;
|
||||||
}
|
}
|
||||||
case ResourceType.SECRET ->
|
case ResourceType.SECRET:
|
||||||
{
|
{
|
||||||
return secretService;
|
return secretService;
|
||||||
}
|
}
|
||||||
case ResourceType.CONFIG_MAP ->
|
case ResourceType.CONFIG_MAP:
|
||||||
{
|
{
|
||||||
return configMapService;
|
return configMapService;
|
||||||
}
|
}
|
||||||
case ResourceType.PVC ->
|
case ResourceType.PVC:
|
||||||
{
|
{
|
||||||
return pvcService;
|
return pvcService;
|
||||||
}
|
}
|
||||||
case ResourceType.PV ->
|
case ResourceType.PV:
|
||||||
{
|
{
|
||||||
return pvService;
|
return pvService;
|
||||||
}
|
}
|
||||||
case ResourceType.NAMESPACE ->
|
case ResourceType.NAMESPACE:
|
||||||
{
|
{
|
||||||
return namespaceService;
|
return namespaceService;
|
||||||
}
|
}
|
||||||
default ->
|
default :
|
||||||
{
|
{
|
||||||
LOG.errorf("Invalid resource type %s.", resourceType);
|
LOG.errorf("Invalid resource type %s.", resourceType);
|
||||||
throw new BadRequestException();
|
throw new BadRequestException();
|
||||||
|
|||||||
@ -30,16 +30,12 @@ public class LoginResource
|
|||||||
public String login(Login login)
|
public String login(Login login)
|
||||||
{
|
{
|
||||||
Optional<UserEntity> userOptional = userRepo.findOptionalByUsername(login.username());
|
Optional<UserEntity> userOptional = userRepo.findOptionalByUsername(login.username());
|
||||||
if(userOptional.isPresent())
|
if (userOptional.isPresent())
|
||||||
{
|
{
|
||||||
UserEntity user = userOptional.get();
|
UserEntity user = userOptional.get();
|
||||||
if(BcryptUtil.matches(login.password(), user.getPassword()))
|
if (BcryptUtil.matches(login.password(), user.getPassword()))
|
||||||
{
|
{
|
||||||
return Jwt
|
return Jwt.upn(user.getId()).expiresAt(ZonedDateTime.now().plusDays(15).toInstant()).groups(user.getRoles()).sign();
|
||||||
.upn(user.getId())
|
|
||||||
.expiresAt(ZonedDateTime.now().plusDays(15).toInstant())
|
|
||||||
.groups(user.getRoles())
|
|
||||||
.sign();
|
|
||||||
}
|
}
|
||||||
LOG.info("Cannot access user. Forbidden");
|
LOG.info("Cannot access user. Forbidden");
|
||||||
throw new ForbiddenException(Response.status(403).type(MediaType.TEXT_PLAIN).entity("wrong_password").build());
|
throw new ForbiddenException(Response.status(403).type(MediaType.TEXT_PLAIN).entity("wrong_password").build());
|
||||||
|
|||||||
@ -52,7 +52,8 @@ public class UserResource
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Transactional
|
@Transactional
|
||||||
@RolesAllowed({"ADMIN", "OWNER"})
|
@RolesAllowed(
|
||||||
|
{"ADMIN", "OWNER"})
|
||||||
public void createUser(UserCreation user)
|
public void createUser(UserCreation user)
|
||||||
{
|
{
|
||||||
if (List.of("ADMIN", "USER").contains(user.role()))
|
if (List.of("ADMIN", "USER").contains(user.role()))
|
||||||
@ -78,10 +79,10 @@ public class UserResource
|
|||||||
public void changePassword(@PathParam("username") String username, String password)
|
public void changePassword(@PathParam("username") String username, String password)
|
||||||
{
|
{
|
||||||
Optional<UserEntity> persistentUserOptional = userRepo.findOptionalByUsername(username);
|
Optional<UserEntity> persistentUserOptional = userRepo.findOptionalByUsername(username);
|
||||||
if(persistentUserOptional.isPresent() && password != null && !password.isBlank())
|
if (persistentUserOptional.isPresent() && password != null && !password.isBlank())
|
||||||
{
|
{
|
||||||
UserEntity persistentUser = persistentUserOptional.get();
|
UserEntity persistentUser = persistentUserOptional.get();
|
||||||
if(securityIdentity.getPrincipal().getName().equals(persistentUser.getId()))
|
if (securityIdentity.getPrincipal().getName().equals(persistentUser.getId()))
|
||||||
{
|
{
|
||||||
persistentUser.setPassword(BcryptUtil.bcryptHash(password));
|
persistentUser.setPassword(BcryptUtil.bcryptHash(password));
|
||||||
userRepo.persist(persistentUser);
|
userRepo.persist(persistentUser);
|
||||||
|
|||||||
@ -91,14 +91,17 @@ public class MonitoringJobRunner
|
|||||||
LOG.infof("Running %s %s monitoring.", config.getConfigName(), config.getType().toString().toLowerCase());
|
LOG.infof("Running %s %s monitoring.", config.getConfigName(), config.getType().toString().toLowerCase());
|
||||||
switch (config.getType())
|
switch (config.getType())
|
||||||
{
|
{
|
||||||
case VOLUME ->
|
case VOLUME:
|
||||||
{
|
{
|
||||||
volumeMonitoringJobRunner.run(config);
|
volumeMonitoringJobRunner.run(config);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
case WORKLOAD ->
|
case WORKLOAD:
|
||||||
{
|
{
|
||||||
memoryMonitoringJobRunner.run(config);
|
memoryMonitoringJobRunner.run(config);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,7 +55,7 @@ public class MonitoringResource
|
|||||||
|
|
||||||
switch (configCreation.type())
|
switch (configCreation.type())
|
||||||
{
|
{
|
||||||
case MonitoringType.VOLUME ->
|
case MonitoringType.VOLUME:
|
||||||
{
|
{
|
||||||
VolumeConfig volumeConfig = new VolumeConfig();
|
VolumeConfig volumeConfig = new VolumeConfig();
|
||||||
volumeConfig.setId(UUID.randomUUID().toString());
|
volumeConfig.setId(UUID.randomUUID().toString());
|
||||||
|
|||||||
@ -24,12 +24,10 @@ public class MonitoringService
|
|||||||
TargetConfig targetConfig = config.getTargetConfig();
|
TargetConfig targetConfig = config.getTargetConfig();
|
||||||
switch (targetConfig.getType())
|
switch (targetConfig.getType())
|
||||||
{
|
{
|
||||||
case LABEL ->
|
case LABEL -> {
|
||||||
{
|
|
||||||
return podService.findByNamespaceAndLabels(targetConfig.getNamespace(), targetConfig.getLabels()).stream().filter(pod -> pod.getStatus().getPhase().equals("Running")).toList();
|
return podService.findByNamespaceAndLabels(targetConfig.getNamespace(), targetConfig.getLabels()).stream().filter(pod -> pod.getStatus().getPhase().equals("Running")).toList();
|
||||||
}
|
}
|
||||||
case DEPLOYMENT, STATEFUL_SET ->
|
case DEPLOYMENT, STATEFUL_SET -> {
|
||||||
{
|
|
||||||
throw new NotImplementedYet();
|
throw new NotImplementedYet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,10 +38,10 @@ public class TopNodesService
|
|||||||
List<String> stats = runTopNodesCommand();
|
List<String> stats = runTopNodesCommand();
|
||||||
Map<String, Integer> podsOnNodes = countPods();
|
Map<String, Integer> podsOnNodes = countPods();
|
||||||
Map<String, NodeDiskMetrics> nodeDiskMetrics = nodeDiskService.getDiskMetrics();
|
Map<String, NodeDiskMetrics> nodeDiskMetrics = nodeDiskService.getDiskMetrics();
|
||||||
for(String nodeName : stats)
|
for (String nodeName : stats)
|
||||||
{
|
{
|
||||||
String[] parts = nodeName.split("\\s+");
|
String[] parts = nodeName.split("\\s+");
|
||||||
if(parts.length == 5)
|
if (parts.length == 5)
|
||||||
{
|
{
|
||||||
String name = parts[0];
|
String name = parts[0];
|
||||||
Node node = clientProvider.getClient().nodes().withName(name).get();
|
Node node = clientProvider.getClient().nodes().withName(name).get();
|
||||||
@ -92,15 +92,15 @@ public class TopNodesService
|
|||||||
|
|
||||||
private Integer extractMemory(String input)
|
private Integer extractMemory(String input)
|
||||||
{
|
{
|
||||||
if(input.contains("Ki"))
|
if (input.contains("Ki"))
|
||||||
{
|
{
|
||||||
return Integer.parseInt(input.replace("Ki", ""));
|
return Integer.parseInt(input.replace("Ki", ""));
|
||||||
}
|
}
|
||||||
if(input.contains("Mi"))
|
if (input.contains("Mi"))
|
||||||
{
|
{
|
||||||
return Integer.parseInt(input.replace("Mi", "")) * 1024;
|
return Integer.parseInt(input.replace("Mi", "")) * 1024;
|
||||||
}
|
}
|
||||||
if(input.contains("Gi"))
|
if (input.contains("Gi"))
|
||||||
{
|
{
|
||||||
return Integer.parseInt(input.replace("Gi", "")) * 1024 * 1024;
|
return Integer.parseInt(input.replace("Gi", "")) * 1024 * 1024;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,5 @@ package dev.dinauer.monitoring.entity;
|
|||||||
|
|
||||||
public enum MonitoringTargetType
|
public enum MonitoringTargetType
|
||||||
{
|
{
|
||||||
DEPLOYMENT,
|
DEPLOYMENT, STATEFUL_SET, LABEL
|
||||||
STATEFUL_SET,
|
|
||||||
LABEL
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,9 @@ public class TargetConfig
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return OBJECT_MAPPER.readValue(labels, new TypeReference<Map<String, String>>() {});
|
return OBJECT_MAPPER.readValue(labels, new TypeReference<Map<String, String>>()
|
||||||
|
{
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (JsonProcessingException e)
|
catch (JsonProcessingException e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,10 +2,6 @@ package dev.dinauer.monitoring.entity.creation;
|
|||||||
|
|
||||||
import dev.dinauer.monitoring.entity.MonitoringType;
|
import dev.dinauer.monitoring.entity.MonitoringType;
|
||||||
|
|
||||||
public record MonitoringConfigCreation(
|
public record MonitoringConfigCreation(String configName, MonitoringType type, String interval, VolumeConfigCreation volumeConfig, MonitoringTargetConfigCreation targetConfig)
|
||||||
String configName,
|
{
|
||||||
MonitoringType type,
|
}
|
||||||
String interval,
|
|
||||||
VolumeConfigCreation volumeConfig,
|
|
||||||
MonitoringTargetConfigCreation targetConfig
|
|
||||||
) {}
|
|
||||||
@ -2,11 +2,6 @@ package dev.dinauer.monitoring.entity.creation;
|
|||||||
|
|
||||||
import dev.dinauer.monitoring.entity.MonitoringTargetType;
|
import dev.dinauer.monitoring.entity.MonitoringTargetType;
|
||||||
|
|
||||||
public record MonitoringTargetConfigCreation(
|
public record MonitoringTargetConfigCreation(MonitoringTargetType type, String namespace, String deploymentName, String statefulSetName, String labelKey, String labelValue)
|
||||||
MonitoringTargetType type,
|
{
|
||||||
String namespace,
|
}
|
||||||
String deploymentName,
|
|
||||||
String statefulSetName,
|
|
||||||
String labelKey,
|
|
||||||
String labelValue
|
|
||||||
) {}
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
package dev.dinauer.monitoring.entity.creation;
|
package dev.dinauer.monitoring.entity.creation;
|
||||||
|
|
||||||
public record VolumeConfigCreation(
|
public record VolumeConfigCreation(String mountPath, String containerName)
|
||||||
String mountPath,
|
{
|
||||||
String containerName
|
}
|
||||||
) {}
|
|
||||||
|
|||||||
@ -28,15 +28,7 @@ public class NodeMonitoringService
|
|||||||
for (MonitoredNode node : nodes)
|
for (MonitoredNode node : nodes)
|
||||||
{
|
{
|
||||||
NodeMetrics nodeMetrics = node.getMetrics();
|
NodeMetrics nodeMetrics = node.getMetrics();
|
||||||
Map<String, Number> metrics = Stream.of(
|
Map<String, Number> metrics = Stream.of(new AbstractMap.SimpleEntry<>("RELATIVE_CPU", nodeMetrics.relativeCpuUsage()), new AbstractMap.SimpleEntry<>("RELATIVE_MEMORY", nodeMetrics.relativeMemory()), new AbstractMap.SimpleEntry<>("ABSOLUTE_MEMORY", nodeMetrics.absoluteMemory()), new AbstractMap.SimpleEntry<>("ABSOLUTE_CPU", nodeMetrics.absoluteCpuUsage()), new AbstractMap.SimpleEntry<>("RELATIVE_DISK_SPACE", nodeMetrics.relativeDiskUsage()), new AbstractMap.SimpleEntry<>("TOTAL_DISK_SPACE", nodeMetrics.totalDiskSpace())).filter(entry -> entry.getValue() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
new AbstractMap.SimpleEntry<>("RELATIVE_CPU", nodeMetrics.relativeCpuUsage()),
|
|
||||||
new AbstractMap.SimpleEntry<>("RELATIVE_MEMORY", nodeMetrics.relativeMemory()),
|
|
||||||
new AbstractMap.SimpleEntry<>("ABSOLUTE_MEMORY", nodeMetrics.absoluteMemory()),
|
|
||||||
new AbstractMap.SimpleEntry<>("ABSOLUTE_CPU", nodeMetrics.absoluteCpuUsage()),
|
|
||||||
new AbstractMap.SimpleEntry<>("RELATIVE_DISK_SPACE", nodeMetrics.relativeDiskUsage()),
|
|
||||||
new AbstractMap.SimpleEntry<>("TOTAL_DISK_SPACE", nodeMetrics.totalDiskSpace()))
|
|
||||||
.filter(entry -> entry.getValue() != null)
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
|
|
||||||
bigBucketService.index(String.format("NODE-%s", node.getMetadata().getUid()), "NODE_METRICS", metrics);
|
bigBucketService.index(String.format("NODE-%s", node.getMetadata().getUid()), "NODE_METRICS", metrics);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,20 +10,16 @@ public class Duration
|
|||||||
long value = Long.parseLong(input.substring(0, input.length() - 1));
|
long value = Long.parseLong(input.substring(0, input.length() - 1));
|
||||||
switch (unit)
|
switch (unit)
|
||||||
{
|
{
|
||||||
case 's' ->
|
case 's' -> {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
case 'm' ->
|
case 'm' -> {
|
||||||
{
|
|
||||||
return value * 60;
|
return value * 60;
|
||||||
}
|
}
|
||||||
case 'h' ->
|
case 'h' -> {
|
||||||
{
|
|
||||||
return value * 60 * 60;
|
return value * 60 * 60;
|
||||||
}
|
}
|
||||||
default ->
|
default -> {
|
||||||
{
|
|
||||||
throw new IllegalArgumentException(String.format("Invalid unit %s", unit));
|
throw new IllegalArgumentException(String.format("Invalid unit %s", unit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class DeploymentService implements ResourceService<Deployment>
|
|||||||
@Override
|
@Override
|
||||||
public List<Deployment> findByNamespace(String namespace)
|
public List<Deployment> findByNamespace(String namespace)
|
||||||
{
|
{
|
||||||
try(AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||||
{
|
{
|
||||||
if (namespace.equals("_all"))
|
if (namespace.equals("_all"))
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ public class DeploymentService implements ResourceService<Deployment>
|
|||||||
|
|
||||||
public List<Deployment> findAll()
|
public List<Deployment> findAll()
|
||||||
{
|
{
|
||||||
try(AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||||
{
|
{
|
||||||
return dsl.deployments().inAnyNamespace().list().getItems();
|
return dsl.deployments().inAnyNamespace().list().getItems();
|
||||||
}
|
}
|
||||||
@ -63,7 +63,8 @@ public class DeploymentService implements ResourceService<Deployment>
|
|||||||
@Override
|
@Override
|
||||||
public Watch watch(String namespace, Watcher<Deployment> watcher)
|
public Watch watch(String namespace, Watcher<Deployment> watcher)
|
||||||
{
|
{
|
||||||
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps()) {
|
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||||
|
{
|
||||||
String version = dsl.deployments().inAnyNamespace().list().getMetadata().getResourceVersion();
|
String version = dsl.deployments().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||||
if (namespace.equals("_all"))
|
if (namespace.equals("_all"))
|
||||||
{
|
{
|
||||||
@ -75,7 +76,7 @@ public class DeploymentService implements ResourceService<Deployment>
|
|||||||
|
|
||||||
public void rescale(String namespace, String name, int replicaCount)
|
public void rescale(String namespace, String name, int replicaCount)
|
||||||
{
|
{
|
||||||
try(AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||||
{
|
{
|
||||||
dsl.deployments().inNamespace(namespace).withName(name).scale(replicaCount);
|
dsl.deployments().inNamespace(namespace).withName(name).scale(replicaCount);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class IngressService implements ResourceService<Ingress>
|
|||||||
@Override
|
@Override
|
||||||
public Ingress findByNameAndNamespace(String name, String namespace)
|
public Ingress findByNameAndNamespace(String name, String namespace)
|
||||||
{
|
{
|
||||||
try(NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
try (NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
||||||
{
|
{
|
||||||
List<Ingress> ingresses = dsl.v1().ingresses().list().getItems();
|
List<Ingress> ingresses = dsl.v1().ingresses().list().getItems();
|
||||||
for (Ingress ingress : ingresses)
|
for (Ingress ingress : ingresses)
|
||||||
@ -48,7 +48,7 @@ public class IngressService implements ResourceService<Ingress>
|
|||||||
|
|
||||||
public List<Ingress> findByNamespace(String namespace)
|
public List<Ingress> findByNamespace(String namespace)
|
||||||
{
|
{
|
||||||
try(NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
try (NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
||||||
{
|
{
|
||||||
if (namespace.equals("_all"))
|
if (namespace.equals("_all"))
|
||||||
{
|
{
|
||||||
@ -60,7 +60,7 @@ public class IngressService implements ResourceService<Ingress>
|
|||||||
|
|
||||||
public List<Ingress> findAll()
|
public List<Ingress> findAll()
|
||||||
{
|
{
|
||||||
try(NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
try (NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
||||||
{
|
{
|
||||||
return dsl.v1().ingresses().inAnyNamespace().list().getItems();
|
return dsl.v1().ingresses().inAnyNamespace().list().getItems();
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ public class IngressService implements ResourceService<Ingress>
|
|||||||
@Override
|
@Override
|
||||||
public Watch watch(String namespace, Watcher<Ingress> watcher)
|
public Watch watch(String namespace, Watcher<Ingress> watcher)
|
||||||
{
|
{
|
||||||
try(NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
try (NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
||||||
{
|
{
|
||||||
String version = dsl.v1().ingresses().inAnyNamespace().list().getMetadata().getResourceVersion();
|
String version = dsl.v1().ingresses().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||||
if (namespace.equals("_all"))
|
if (namespace.equals("_all"))
|
||||||
|
|||||||
@ -25,14 +25,10 @@ public class PodService implements ResourceService<Pod>
|
|||||||
public void delete(String name, String namespace)
|
public void delete(String name, String namespace)
|
||||||
{
|
{
|
||||||
Optional<Pod> podOptional = findOptionalByNameAndNamespace(name, namespace);
|
Optional<Pod> podOptional = findOptionalByNameAndNamespace(name, namespace);
|
||||||
if(podOptional.isPresent())
|
if (podOptional.isPresent())
|
||||||
{
|
{
|
||||||
Pod pod = podOptional.get();
|
Pod pod = podOptional.get();
|
||||||
clientProvider.getClient()
|
clientProvider.getClient().pods().inNamespace(pod.getMetadata().getNamespace()).withName(pod.getMetadata().getName()).delete();
|
||||||
.pods()
|
|
||||||
.inNamespace(pod.getMetadata().getNamespace())
|
|
||||||
.withName(pod.getMetadata().getName())
|
|
||||||
.delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +49,7 @@ public class PodService implements ResourceService<Pod>
|
|||||||
|
|
||||||
public List<Pod> findByStatefulSet(String name, String namespace)
|
public List<Pod> findByStatefulSet(String name, String namespace)
|
||||||
{
|
{
|
||||||
try(AppsAPIGroupDSL apps = clientProvider.getClient().apps())
|
try (AppsAPIGroupDSL apps = clientProvider.getClient().apps())
|
||||||
{
|
{
|
||||||
StatefulSet set = apps.statefulSets().inNamespace(namespace).withName(name).get();
|
StatefulSet set = apps.statefulSets().inNamespace(namespace).withName(name).get();
|
||||||
if (set != null)
|
if (set != null)
|
||||||
@ -98,9 +94,9 @@ public class PodService implements ResourceService<Pod>
|
|||||||
|
|
||||||
public Optional<Pod> findPodById(String id)
|
public Optional<Pod> findPodById(String id)
|
||||||
{
|
{
|
||||||
for(Pod pod : clientProvider.getClient().pods().inAnyNamespace().list().getItems())
|
for (Pod pod : clientProvider.getClient().pods().inAnyNamespace().list().getItems())
|
||||||
{
|
{
|
||||||
if(pod.getMetadata().getUid().equals(id))
|
if (pod.getMetadata().getUid().equals(id))
|
||||||
{
|
{
|
||||||
return Optional.of(pod);
|
return Optional.of(pod);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,9 +65,9 @@ public class ServiceService implements ResourceService<Service>
|
|||||||
|
|
||||||
public Optional<Service> findById(String id)
|
public Optional<Service> findById(String id)
|
||||||
{
|
{
|
||||||
for(Service service : clientProvider.getClient().services().list().getItems())
|
for (Service service : clientProvider.getClient().services().list().getItems())
|
||||||
{
|
{
|
||||||
if(service.getMetadata().getUid().equals(id))
|
if (service.getMetadata().getUid().equals(id))
|
||||||
{
|
{
|
||||||
return Optional.of(service);
|
return Optional.of(service);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public class StatefulSetService implements ResourceService<StatefulSet>
|
|||||||
@Override
|
@Override
|
||||||
public List<StatefulSet> findByNamespace(String namespace)
|
public List<StatefulSet> findByNamespace(String namespace)
|
||||||
{
|
{
|
||||||
try(AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||||
{
|
{
|
||||||
if (namespace.equals("_all"))
|
if (namespace.equals("_all"))
|
||||||
{
|
{
|
||||||
@ -62,7 +62,8 @@ public class StatefulSetService implements ResourceService<StatefulSet>
|
|||||||
@Override
|
@Override
|
||||||
public Watch watch(String namespace, Watcher<StatefulSet> watcher)
|
public Watch watch(String namespace, Watcher<StatefulSet> watcher)
|
||||||
{
|
{
|
||||||
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps()) {
|
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||||
|
{
|
||||||
String version = dsl.statefulSets().inAnyNamespace().list().getMetadata().getResourceVersion();
|
String version = dsl.statefulSets().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||||
if (namespace.equals("_all"))
|
if (namespace.equals("_all"))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class StartupService
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
if(userRepo.findOptionalByUsername(INITIAL_USERNAME).isEmpty())
|
if (userRepo.findOptionalByUsername(INITIAL_USERNAME).isEmpty())
|
||||||
{
|
{
|
||||||
QuarkusTransaction.begin();
|
QuarkusTransaction.begin();
|
||||||
userRepo.persist(buildInitialUser());
|
userRepo.persist(buildInitialUser());
|
||||||
|
|||||||
@ -10,9 +10,9 @@ public class ByteExtractorTest
|
|||||||
void test()
|
void test()
|
||||||
{
|
{
|
||||||
String input = """
|
String input = """
|
||||||
NAME CPU(cores) MEMORY(bytes)
|
NAME CPU(cores) MEMORY(bytes)
|
||||||
postgres-cluster-1 13m 50Mi
|
postgres-cluster-1 13m 50Mi
|
||||||
""";
|
""";
|
||||||
|
|
||||||
long bytes = ByteExtractor.extractBytes(input);
|
long bytes = ByteExtractor.extractBytes(input);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user