Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Mar 26, 2024
1 parent ef9d56b commit f1711c3
Show file tree
Hide file tree
Showing 13 changed files with 838 additions and 207 deletions.
1 change: 1 addition & 0 deletions compose/sample-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ services:
CRYOSTAT_AGENT_HARVESTER_MAX_FILES: 3
CRYOSTAT_AGENT_HARVESTER_EXIT_MAX_AGE_MS: 60000
CRYOSTAT_AGENT_HARVESTER_EXIT_MAX_SIZE_B: 153600 # "$(echo 1024*150 | bc)"
CRYOSTAT_AGENT_API_WRITES_ENABLED: "true"
restart: always
healthcheck:
test: curl --fail http://localhost:10010 || exit 1
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/cryostat/JsonRequestFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.inject.Inject;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -36,7 +37,7 @@ public class JsonRequestFilter implements ContainerRequestFilter {
static final Set<String> allowedPaths =
Set.of("/api/v2.2/discovery", "/api/beta/matchexpressions");

private final ObjectMapper objectMapper = new ObjectMapper();
@Inject ObjectMapper objectMapper;

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/io/cryostat/credentials/CredentialsFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright The Cryostat Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cryostat.credentials;

import java.net.URI;
import java.util.Optional;

import io.cryostat.expressions.MatchExpressionEvaluator;
import io.cryostat.targets.Target;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import org.projectnessie.cel.tools.ScriptException;

@ApplicationScoped
public class CredentialsFinder {

@Inject MatchExpressionEvaluator expressionEvaluator;
@Inject Logger logger;

public Optional<Credential> getCredentialsForTarget(Target target) {
return Credential.<Credential>listAll().stream()
.filter(
c -> {
try {
return expressionEvaluator.applies(c.matchExpression, target);
} catch (ScriptException e) {
logger.error(e);
return false;
}
})
.findFirst();
}

public Optional<Credential> getCredentialsForConnectUrl(URI connectUrl) {
return Target.find("connectUrl", connectUrl)
.<Target>firstResultOptional()
.map(this::getCredentialsForTarget)
.orElse(Optional.empty());
}
}
17 changes: 7 additions & 10 deletions src/main/java/io/cryostat/discovery/ContainerDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,14 @@ private void doContainerListRequest(Consumer<List<ContainerSpec>> successHandler
item.body(),
new TypeReference<List<ContainerSpec>>() {}));
} catch (JsonProcessingException e) {
logger.error("Json processing error");
logger.error("Json processing error", e);
}
},
failure -> {
logger.error(
String.format("%s API request failed", getRealm()),
failure);
logger.errorv(failure, "{0} API request failed", getRealm());
});
} catch (JsonProcessingException e) {
logger.error("Json processing error");
logger.error("Json processing error", e);
}
}

Expand All @@ -279,13 +277,12 @@ private CompletableFuture<ContainerDetails> doContainerInspectRequest(ContainerS
result.complete(
mapper.readValue(item.body(), ContainerDetails.class));
} catch (JsonProcessingException e) {
logger.error("Json processing error");
logger.error("Json processing error", e);
result.completeExceptionally(e);
}
},
failure -> {
logger.error(
String.format("%s API request failed", getRealm()), failure);
logger.errorv(failure, "{0} API request failed", getRealm());
result.completeExceptionally(failure);
});
return result;
Expand Down Expand Up @@ -322,7 +319,7 @@ public void handleContainerEvent(ContainerSpec desc, EventKind evtKind) {
.Hostname;
} catch (InterruptedException | TimeoutException | ExecutionException e) {
containers.remove(desc);
logger.warn(String.format("Invalid %s target observed", getRealm()), e);
logger.warnv(e, "Invalid {0} target observed", getRealm());
return;
}
}
Expand All @@ -331,7 +328,7 @@ public void handleContainerEvent(ContainerSpec desc, EventKind evtKind) {
connectUrl = URI.create(serviceUrl.toString());
} catch (MalformedURLException | URISyntaxException e) {
containers.remove(desc);
logger.warn(String.format("Invalid %s target observed", getRealm()), e);
logger.warnv(e, "Invalid {0} target observed", getRealm());
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/cryostat/recordings/RecordingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public ActiveRecording startRecording(
IRecordingDescriptor desc =
connection
.getService()
.start(recordingOptions, enableEvents(target, eventTemplate));
.start(recordingOptions, eventTemplate.getName(), eventTemplate.getType());

Map<String, String> labels = metadata.labels();
labels.put("template.name", eventTemplate.getName());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/cryostat/recordings/Recordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public Response createRecording(
@RestForm Optional<String> replace,
// restart param is deprecated, only 'replace' should be used and takes priority if both
// are provided
@RestForm Optional<Boolean> restart,
@Deprecated @RestForm Optional<Boolean> restart,
@RestForm Optional<Long> duration,
@RestForm Optional<Boolean> toDisk,
@RestForm Optional<Long> maxAge,
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/cryostat/rules/RuleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,11 @@ private void scheduleArchival(Rule rule, Target target, ActiveRecording recordin
try {
quartz.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
logger.infov(
logger.errorv(
e,
"Failed to schedule archival job for rule {0} in target {1}",
rule.name, target.alias);
logger.error(e);
rule.name,
target.alias);
}
jobs.add(jobDetail.getKey());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,10 @@
*/
package io.cryostat.targets;

import java.net.URI;
import jakarta.ws.rs.WebApplicationException;

import io.cryostat.core.sys.Clock;

import io.vertx.mutiny.core.Vertx;
import io.vertx.mutiny.ext.web.client.WebClient;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

@ApplicationScoped
class AgentConnectionFactory {

@Inject Vertx vertx;
@Inject Clock clock;

AgentConnection createConnection(URI agentUri) {
return new AgentConnection(agentUri, WebClient.create(vertx), clock);
public class AgentApiException extends WebApplicationException {
public AgentApiException(int statusCode) {
super(String.format("Unexpected HTTP response code %d", statusCode));
}
}
Loading

0 comments on commit f1711c3

Please sign in to comment.