Skip to content

Commit f140d2e

Browse files
alparishAlekhya Parisha
andauthored
Add configurable range parameter to Office 365 source plugin (#6261)
Signed-off-by: Alekhya Parisha <aparisha@amazon.com> Co-authored-by: Alekhya Parisha <aparisha@amazon.com>
1 parent 7ad502b commit f140d2e

4 files changed

Lines changed: 37 additions & 2 deletions

File tree

data-prepper-plugins/saas-source-plugins/microsoft-office365-source/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424
implementation 'io.micrometer:micrometer-core'
2525
implementation 'javax.inject:javax.inject:1'
2626
implementation 'org.jsoup:jsoup:1.18.3'
27+
implementation 'org.hibernate.validator:hibernate-validator:8.0.1.Final'
2728

2829
implementation 'org.projectlombok:lombok:1.18.30'
2930
annotationProcessor 'org.projectlombok:lombok:1.18.30'

data-prepper-plugins/saas-source-plugins/microsoft-office365-source/src/main/java/org/opensearch/dataprepper/plugins/source/microsoft_office365/Office365Source.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class Office365Source extends CrawlerSourcePlugin {
4949
private final Office365AuthenticationInterface office365AuthProvider;
5050
private final Office365Service office365Service;
5151
private final AtomicBoolean isRunning = new AtomicBoolean(false);
52-
private static final int OFFICE365_LOOKBACK_HOURS = 0;
5352

5453
@DataPrepperPluginConstructor
5554
public Office365Source(final PluginMetrics pluginMetrics,
@@ -89,7 +88,7 @@ public void start(Buffer<Record<Event>> buffer) {
8988

9089
@Override
9190
protected LeaderProgressState createLeaderProgressState() {
92-
return new DimensionalTimeSliceLeaderProgressState(Instant.now(), OFFICE365_LOOKBACK_HOURS);
91+
return new DimensionalTimeSliceLeaderProgressState(Instant.now(), office365SourceConfig.getLookBackHours());
9392
}
9493

9594
@Override

data-prepper-plugins/saas-source-plugins/microsoft-office365-source/src/main/java/org/opensearch/dataprepper/plugins/source/microsoft_office365/Office365SourceConfig.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
import jakarta.validation.Valid;
1414
import jakarta.validation.constraints.NotNull;
1515
import lombok.Getter;
16+
import org.hibernate.validator.constraints.time.DurationMax;
1617
import org.opensearch.dataprepper.plugins.source.microsoft_office365.auth.AuthenticationConfiguration;
1718
import org.opensearch.dataprepper.plugins.source.source_crawler.base.CrawlerSourceConfig;
1819

20+
import java.time.Duration;
21+
1922
/**
2023
* Configuration class for Office 365 source plugin.
2124
*/
@@ -46,6 +49,28 @@ public class Office365SourceConfig implements CrawlerSourceConfig {
4649
@JsonProperty("acknowledgments")
4750
private boolean acknowledgments = false;
4851

52+
/**
53+
* Time range for lookback data collection using ISO 8601 duration format.
54+
* Specifies how far back in time to collect data from the current time.
55+
* Default: null (no lookback, only incremental data)
56+
* Maximum: P7D (7 days due to Office 365 API limitation)
57+
*/
58+
@JsonProperty("range")
59+
@DurationMax(days = 7, message = "Range cannot exceed 7 days due to Office 365 API limitation")
60+
private Duration range;
61+
62+
/**
63+
* Gets the look back range as hours for compatibility with existing crawler framework.
64+
*
65+
* @return the number of hours to look back, or 0 if no range is specified
66+
*/
67+
public int getLookBackHours() {
68+
if (range == null || range.toHours() <= 0) {
69+
return 0;
70+
}
71+
return (int) range.toHours();
72+
}
73+
4974
@Override
5075
public int getNumberOfWorkers() {
5176
return NUMBER_OF_WORKERS;

data-prepper-plugins/saas-source-plugins/microsoft-office365-source/src/test/java/org/opensearch/dataprepper/plugins/source/microsoft_office365/Office365SourceConfigTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.opensearch.dataprepper.plugins.source.microsoft_office365.auth.Oauth2Config;
2020

2121
import java.lang.reflect.Field;
22+
import java.time.Duration;
2223

2324
import static org.junit.jupiter.api.Assertions.assertEquals;
2425
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -78,6 +79,7 @@ void testGetters() {
7879
void testDefaultValues() {
7980
assertFalse(config.isAcknowledgments());
8081
assertEquals(4, config.getNumberOfWorkers());
82+
assertEquals(0, config.getLookBackHours());
8183
}
8284

8385
@Test
@@ -91,4 +93,12 @@ void testGetClientSecretValue() {
9193
String actualClientSecret = (String) config.getAuthenticationConfiguration().getOauth2().getClientSecret().getValue();
9294
assertEquals(clientSecret, actualClientSecret);
9395
}
96+
97+
@Test
98+
void testNegativeDurationRange() throws Exception {
99+
Duration negativeDuration = Duration.ofDays(-1);
100+
setField(config, "range", negativeDuration);
101+
102+
assertEquals(0, config.getLookBackHours());
103+
}
94104
}

0 commit comments

Comments
 (0)