Skip to content

Commit

Permalink
Merge branch 'develop' into feat/query-filter-operation
Browse files Browse the repository at this point in the history
  • Loading branch information
aeSouid committed Feb 6, 2025
2 parents e0c59a5 + 21aebe4 commit a2945c9
Show file tree
Hide file tree
Showing 36 changed files with 228 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ yarn.lock
ui/coverage
ui/stats.html
ui/.frontend-gradle-plugin
ui/utils/CHANGELOG.md

### Docker
/.env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import lombok.extern.jackson.Jacksonized;

@Builder(toBuilder = true)
@Getter
@Jacksonized
public class HttpConfiguration {
@Schema(title = "The timeout configuration.")
@PluginProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.kestra.core.runners.pebble.functions;

import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.runners.RunVariables;
import io.kestra.core.secret.SecretNotFoundException;
import io.kestra.core.secret.SecretService;
import io.kestra.core.services.FlowService;
import io.pebbletemplates.pebble.error.PebbleException;
import io.pebbletemplates.pebble.extension.Function;
import io.pebbletemplates.pebble.template.EvaluationContext;
Expand All @@ -15,7 +15,6 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;

@Slf4j
Expand All @@ -24,18 +23,32 @@ public class SecretFunction implements Function {
@Inject
private SecretService secretService;

@Inject
private FlowService flowService;

@Override
public List<String> getArgumentNames() {
return List.of("key");
return List.of("key", "namespace");
}

@SuppressWarnings("unchecked")
@Override
public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {
String key = getSecretKey(args, self, lineNumber);
String namespace = (String) args.get("namespace");

Map<String, String> flow = (Map<String, String>) context.getVariable("flow");
String flowNamespace = flow.get("namespace");
String flowTenantId = flow.get("tenantId");

if (namespace == null) {
namespace = flowNamespace;
} else {
flowService.checkAllowedNamespace(flowTenantId, namespace, flowTenantId, flowNamespace);
}

try {
String secret = secretService.findSecret(flow.get("tenantId"), flow.get("namespace"), key);
String secret = secretService.findSecret(flowTenantId, namespace, key);

try {
Consumer<String> addSecretConsumer = (Consumer<String>) context.getVariable(RunVariables.SECRET_CONSUMER_VARIABLE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Output run(RunContext runContext) throws Exception {
flowService.checkAllowedNamespace(flowInfo.tenantId(), runContext.render(namespace).as(String.class).orElse(null), flowInfo.tenantId(), flowInfo.namespace());
}

var logLevelsRendered = runContext.render(this.logLevels).asList(String.class);
var logLevelsRendered = runContext.render(this.logLevels).asList(Level.class);
var renderedDate = runContext.render(startDate).as(String.class).orElse(null);
int deleted = logService.purge(
flowInfo.tenantId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.kestra.core.secret;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

import io.kestra.core.junit.annotations.KestraTest;
import io.kestra.core.junit.annotations.LoadFlows;
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.executions.LogEntry;
import io.kestra.core.models.flows.State;
import io.kestra.core.queues.QueueException;
import io.kestra.core.queues.QueueFactoryInterface;
import io.kestra.core.queues.QueueInterface;
Expand All @@ -22,6 +21,7 @@
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import reactor.core.publisher.Flux;

import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

@KestraTest(startRunner = true)
Expand All @@ -48,6 +48,9 @@ void getSecret() throws TimeoutException, QueueException {
Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "secrets");
assertThat(execution.getTaskRunList().getFirst().getOutputs().get("value"), is("secretValue"));
assertThat(execution.getTaskRunList().get(2).getOutputs().get("value"), is("passwordveryveryveyrlongpasswordveryveryveyrlongpasswordveryveryveyrlongpasswordveryveryveyrlongpasswordveryveryveyrlong"));
assertThat(execution.getTaskRunList().get(3).getOutputs().get("value"), is("secretValue"));
assertThat(execution.getTaskRunList().get(4).getOutputs(), anEmptyMap());
assertThat(execution.getTaskRunList().get(4).getState().getCurrent(), is(State.Type.WARNING));

LogEntry matchingLog = TestsUtils.awaitLog(logs, logEntry -> logEntry.getTaskId() != null && logEntry.getTaskId().equals("log-secret"));
receive.blockLast();
Expand Down
92 changes: 80 additions & 12 deletions core/src/test/java/io/kestra/plugin/core/log/PurgeLogsTest.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
package io.kestra.plugin.core.log;

import io.kestra.core.junit.annotations.KestraTest;
import io.kestra.core.junit.annotations.LoadFlows;
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.executions.LogEntry;
import io.kestra.core.models.property.Property;
import io.kestra.core.repositories.LogRepositoryInterface;
import io.kestra.core.runners.RunContextFactory;
import io.kestra.core.runners.RunnerUtils;
import jakarta.inject.Inject;
import java.time.temporal.ChronoUnit;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.event.Level;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;

@KestraTest
@KestraTest(startRunner = true)
class PurgeLogsTest {
@Inject
private RunContextFactory runContextFactory;

@Inject
private LogRepositoryInterface logRepository;

@Inject
protected RunnerUtils runnerUtils;

@Test
void run() throws Exception {
@LoadFlows("flows/valids/purge_logs_no_arguments.yaml")
void run_with_no_arguments() throws Exception {
// create an execution to delete
var logEntry = LogEntry.builder()
.namespace("namespace")
Expand All @@ -37,12 +46,71 @@ void run() throws Exception {
.build();
logRepository.save(logEntry);

var purge = PurgeLogs.builder()
.endDate(Property.of(ZonedDateTime.now().plusMinutes(1).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)))
.build();
var runContext = runContextFactory.of(Map.of("flow", Map.of("namespace", "namespace", "id", "flowId")));
var output = purge.run(runContext);
Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "purge_logs_no_arguments");

assertTrue(execution.getState().isSuccess());
assertThat(execution.getTaskRunList().size(), is(1));
assertThat(execution.getTaskRunList().getFirst().getOutputs().get("count"), is(1));
}


@ParameterizedTest
@MethodSource("buildArguments")
@LoadFlows("flows/valids/purge_logs_full_arguments.yaml")
void run_with_full_arguments(LogEntry logEntry, int resultCount, String failingReason) throws Exception {
logRepository.save(logEntry);

Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "purge_logs_full_arguments");

assertTrue(execution.getState().isSuccess());
assertThat(execution.getTaskRunList().size(), is(1));
assertThat(failingReason, execution.getTaskRunList().getFirst().getOutputs().get("count"), is(resultCount));
}

assertThat(output.getCount(), is(1));
static Stream<Arguments> buildArguments() {
return Stream.of(
Arguments.of(LogEntry.builder()
.namespace("purge.namespace")
.flowId("purgeFlowId")
.timestamp(Instant.now().plus(5, ChronoUnit.HOURS))
.level(Level.INFO)
.message("Hello World")
.build(), 0, "The log is too recent to be found"),
Arguments.of(LogEntry.builder()
.namespace("purge.namespace")
.flowId("purgeFlowId")
.timestamp(Instant.now().minus(5, ChronoUnit.HOURS))
.level(Level.INFO)
.message("Hello World")
.build(), 0, "The log is too old to be found"),
Arguments.of(LogEntry.builder()
.namespace("uncorrect.namespace")
.flowId("purgeFlowId")
.timestamp(Instant.now().minusSeconds(10))
.level(Level.INFO)
.message("Hello World")
.build(), 0, "The log has an incorrect namespace"),
Arguments.of(LogEntry.builder()
.namespace("purge.namespace")
.flowId("wrongFlowId")
.timestamp(Instant.now().minusSeconds(10))
.level(Level.INFO)
.message("Hello World")
.build(), 0, "The log has an incorrect flow id"),
Arguments.of(LogEntry.builder()
.namespace("purge.namespace")
.flowId("purgeFlowId")
.timestamp(Instant.now().minusSeconds(10))
.level(Level.WARN)
.message("Hello World")
.build(), 0, "The log has an incorrect LogLevel"),
Arguments.of(LogEntry.builder()
.namespace("purge.namespace")
.flowId("purgeFlowId")
.timestamp(Instant.now().minusSeconds(10))
.level(Level.INFO)
.message("Hello World")
.build(), 1, "The log should be deleted")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: purge_logs_full_arguments
namespace: io.kestra.tests

tasks:
- id: purge_logs
type: io.kestra.plugin.core.log.PurgeLogs
endDate: "{{ now() | dateAdd(2, 'HOURS') }}"
startDate: "{{ now() | dateAdd(-2, 'HOURS') }}"
namespace: purge.namespace
flowId: purgeFlowId
logLevels:
- INFO
- ERROR
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id: purge_logs_no_arguments
namespace: io.kestra.tests

tasks:
- id: purge_logs
type: io.kestra.plugin.core.log.PurgeLogs
endDate: "{{ now() | dateAdd(2, 'HOURS') }}"
9 changes: 8 additions & 1 deletion core/src/test/resources/flows/valids/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ tasks:
message: "{{ secret('my_secret') }}"
- id: get-multiline-secret
type: io.kestra.plugin.core.debug.Return
format: "{{ secret('new_line') }}"
format: "{{ secret('new_line') }}"
- id: get-secret-namespace
type: io.kestra.plugin.core.debug.Return
format: "{{ json(secret('my_secret', 'some.namespace')).secretKey }}"
- id: get-secret-not-found
type: io.kestra.plugin.core.debug.Return
format: "{{ secret('not_found') }}"
allowFailure: true
5 changes: 3 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"test-storybook": "test-storybook",
"prepare": "cd .. && husky ui/.husky && rm -f .git/hooks/*"
"prepare": "cd .. && husky ui/.husky && rm -f .git/hooks/*",
"notes": "node ./utils/generateReleaseNotes"
},
"dependencies": {
"@js-joda/core": "^5.6.3",
Expand Down Expand Up @@ -128,4 +129,4 @@
"lint-staged": {
"**/*.{js,mjs,cjs,ts,vue}": "eslint --fix"
}
}
}
3 changes: 0 additions & 3 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@
},
methods: {
displayApp() {
console.log("App is loaded");
Utils.switchTheme(this.$store);
console.log(this.$store.getters["misc/theme"]);
document.getElementById("loader-wrapper").style.display = "none";
document.getElementById("app-container").style.display = "block";
this.loaded = true;
Expand Down
File renamed without changes.
File renamed without changes.
Binary file added ui/src/assets/empty-ns-files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ui/src/components/dashboard/components/DashboardEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
import YamlUtils from "../../../utils/yamlUtils.js";
import yaml from "yaml";
import ContentSave from "vue-material-design-icons/ContentSave.vue";
import intro from "../../../assets/markdown/dashboard_home.md?raw";
import intro from "../../../assets/docs/dashboard_home.md?raw";
import Markdown from "../../layout/Markdown.vue";
import TimeSeries from "./charts/custom/TimeSeries.vue";
import Bar from "./charts/custom/Bar.vue";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@
const tooltipContent = ref("")
const parsedData = computed(() => {
console.log("theme", theme.value)
let datasets = props.data.reduce(function (accumulator, value) {
Object.keys(value.executionCounts).forEach(function (state) {
console.log("theme", theme.value)
if (accumulator[state] === undefined) {
accumulator[state] = {
label: state,
Expand Down
Loading

0 comments on commit a2945c9

Please sign in to comment.