This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* avoid using unfiltered execution list because the query is very expesive on the database * refactor method * use time.get() supplier * mvn license:update-file-header * remove unused imports * bumped log4j * minus since once * cleanup * Add test for calling admin with filters * Remove obsolete TODO * Make since duration a constant Co-authored-by: Nelson Arapé Pérez <nelson@spotify.com>
- Loading branch information
Showing
5 changed files
with
132 additions
and
4 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
49 changes: 49 additions & 0 deletions
49
styx-flyte-client/src/main/java/com/spotify/styx/flyte/client/RpcHelper.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,49 @@ | ||
/*- | ||
* -\-\- | ||
* Spotify Styx Flyte Client | ||
* -- | ||
* Copyright (C) 2016 - 2022 Spotify AB | ||
* -- | ||
* 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 com.spotify.styx.flyte.client; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class RpcHelper { | ||
|
||
private RpcHelper() {} | ||
|
||
// Test this filter by printing it and using it on a flytectl command | ||
// example: flytectl get executions -p PROJECT -d DOMAIN --filter.fieldSelector="execution.phase in (RUNNING),execution.started_at>2022-02-07T18:23:05,execution.started_at<2022-02-08T18:10:05" -o json | ||
public static String getExecutionsListFilter(Instant timeNow, Duration since, Duration to) { | ||
|
||
final String dateSince = timeNow.minus(since) | ||
.atZone(ZoneId.of("UTC")) | ||
.toLocalDateTime() | ||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")); | ||
|
||
|
||
String dateTo = timeNow.minus(to) | ||
.atZone(ZoneId.of("UTC")) | ||
.toLocalDateTime() | ||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")); | ||
|
||
return String.format("execution.phase in (RUNNING),execution.started_at>%s,execution.started_at<%s", dateSince, dateTo); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
styx-flyte-client/src/test/java/com/spotify/styx/flyte/client/RpcHelperTest.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,52 @@ | ||
/*- | ||
* -\-\- | ||
* Spotify Styx Flyte Client | ||
* -- | ||
* Copyright (C) 2016 - 2022 Spotify AB | ||
* -- | ||
* 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 com.spotify.styx.flyte.client; | ||
|
||
import static com.spotify.styx.flyte.client.RpcHelper.getExecutionsListFilter; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.temporal.ChronoUnit; | ||
import org.junit.Test; | ||
|
||
public class RpcHelperTest { | ||
|
||
|
||
@Test | ||
public void testGtExecutionsListFilter() { | ||
final Instant someTime = LocalDateTime.of(2022, 2, 2, 12, 12, 05) | ||
.atZone(ZoneOffset.UTC) | ||
.toInstant(); | ||
|
||
final String executionsListFilter = getExecutionsListFilter( | ||
someTime, | ||
Duration.of(24, ChronoUnit.HOURS), | ||
Duration.of(3, ChronoUnit.MINUTES)); | ||
|
||
assertThat(executionsListFilter, | ||
equalTo("execution.phase in (RUNNING),execution.started_at>2022-02-01T12:12:05,execution.started_at<2022-02-02T12:09:05")); | ||
|
||
} | ||
} |
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