private EventsIO getEventsIO() { if (this.eventsIO == null) { this.eventsIO = (EventsIO) ModuleLoader.getInstance(EventsIO.class, CoreConfig.EVENTS_MODULES); } return this.eventsIO; }
public DateTime updateDateTime(DateTime baseDateTime) { baseDateTime = extractAndUpdateTime(baseDateTime); baseDateTime = extractAndUpdateDate(baseDateTime); if (!offset.equals("")) baseDateTime = updateDateTimeWithOffset(baseDateTime); return baseDateTime; }
private String getRegex(String glob) { GlobPattern pattern = new GlobPattern(glob); return pattern.compiled().toString(); }
public static DateTime parse(String dateTimeOffsetString) { String stringToParse = dateTimeOffsetString.replace(" ", "").replace(",", "").replace("_", ""); if (StringUtils.isNumeric(stringToParse) && !isLikelyDateTime(stringToParse)) return dateTimeFromTimestamp(stringToParse); DateTime dateTime = tryParseDateTime("HH:mmyyyyMMdd", stringToParse); if (dateTime != null) return dateTime; List<String> splitList = splitDateTimeAndOffset(stringToParse); String offset = splitList.get(1); String dateTimeString = splitList.get(0); DateTimeOffsetParser parser = new DateTimeOffsetParser(dateTimeString, offset); return parser.updateDateTime(new DateTime()); }
@Test public void testDayKeywords() { String todayTimestamp = "today"; String yesterdayTimestamp = "yesterday"; String tomorrowTimeStamp = "tomorrow"; Assert.assertEquals(DateTimeParser.parse(todayTimestamp), referenceDateTime()); Assert.assertEquals(DateTimeParser.parse(yesterdayTimestamp), referenceDateTime().minusDays(1)); Assert.assertEquals(DateTimeParser.parse(tomorrowTimeStamp), referenceDateTime().plusDays(1)); }
@Test public void testNowKeyword() { String nowTimestamp = "now"; Assert.assertEquals(DateTimeParser.parse(nowTimestamp), nowDateTime()); }
@Test public void testDecrementUnits() { testFormat("now-10s", nowDateTime().minusSeconds(10)); testFormat("now-15min", nowDateTime().minusMinutes(15)); testFormat("now-100h", nowDateTime().minusHours(100)); testFormat("now-2d", nowDateTime().minusDays(2)); testFormat("now-6mon", nowDateTime().minusMonths(6)); testFormat("now-5y", nowDateTime().minusYears(5)); testFormat("-6h", nowDateTime().minusHours(6)); }
public JSONMetricsContainer getContainer(String tenantId, String jsonBody) throws IOException { HttpMetricsIngestionHandler handler = new HttpMetricsIngestionHandler(null, new TimeValue(5, TimeUnit.SECONDS)); return handler.createContainer(jsonBody, tenantId); } }
@Test public void testComplexFormats() { testFormat("12:24 yesterday", nowDateTime().minusDays(1).withHourOfDay(12).withMinuteOfHour(24)); testFormat("12:24 tomorrow", nowDateTime().plusDays(1).withHourOfDay(12).withMinuteOfHour(24)); testFormat("12:24 today", nowDateTime().withHourOfDay(12).withMinuteOfHour(24)); testFormat("noon 12/30/2014", nowDateTime().withDate(2014, 12, 30).withHourOfDay(12).withMinuteOfHour(0)); int currentYear = referenceDateTime().getYear(); testFormat("15:45 12/30/14", new DateTime(2014, 12, 30, 15, 45, 0, 0)); testFormat("teatime 12/30/2014", new DateTime(2014, 12, 30, 16, 0, 0, 0)); testFormat("midnight Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0)); testFormat("Jul 30, 2013", new DateTime(2013, 07, 30, 0, 0, 0, 0)); testFormat("Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0)); testFormat("20141230", new DateTime(2014, 12, 30, 0, 0, 0, 0)); }
private String extractDateFieldFromQuery(List<String> value) { DateTime dateTime = DateTimeParser.parse(value.get(0)); return Long.toString(dateTime.getMillis() / 1000); } }
@Test public void testDateFormats() { int currentYear = referenceDateTime().getYear(); testFormat("12/30/14", new DateTime(2014, 12, 30, 0, 0, 0, 0)); testFormat("12/30/2014", new DateTime(2014, 12, 30, 0, 0, 0, 0)); testFormat("Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0)); testFormat("Jul 30, 2013", new DateTime(2013, 07, 30, 0, 0, 0, 0)); testFormat("20141230", new DateTime(2014, 12, 30, 0, 0, 0, 0)); }
@Test public void testRegularHourMinute() { String hourMinuteTimestamp = "12:24"; String hourMinuteWithAm = "9:13am"; String hourMinuteWithPm = "09:13pm"; Assert.assertEquals(DateTimeParser.parse(hourMinuteTimestamp), referenceDateTime().withHourOfDay(12).withMinuteOfHour(24)); Assert.assertEquals(DateTimeParser.parse(hourMinuteWithAm), referenceDateTime().withHourOfDay(9).withMinuteOfHour(13)); Assert.assertEquals(DateTimeParser.parse(hourMinuteWithPm), referenceDateTime().withHourOfDay(21).withMinuteOfHour(13)); }
@Test public void testFromUnixTimestamp() { long unixTimestamp = nowDateTime().getMillis() / 1000; Assert.assertEquals(DateTimeParser.parse(Long.toString(unixTimestamp)), nowDateTime()); }
public HttpMetricNamesHandler() { log.info("Token search improvements enabled: " + EXP_TOKEN_SEARCH_IMPROVEMENTS); if (EXP_TOKEN_SEARCH_IMPROVEMENTS) { discoveryHandle = (TokenDiscoveryIO) ModuleLoader.getInstance(TokenDiscoveryIO.class, CoreConfig.TOKEN_DISCOVERY_MODULES); } else { discoveryHandle = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); } }
@Test public void testIncrementUnits() { testFormat("now+10s", nowDateTime().plusSeconds(10)); testFormat("now+15min", nowDateTime().plusMinutes(15)); testFormat("now+100h", nowDateTime().plusHours(100)); testFormat("now+2d", nowDateTime().plusDays(2)); testFormat("now+6mon", nowDateTime().plusMonths(6)); testFormat("now+5y", nowDateTime().plusYears(5)); }
private void testFormat(String dateString, DateTime date) { Assert.assertEquals(DateTimeParser.parse(dateString), date); }
@Test public void testHourMinuteKeywords() { String noonTimestamp = "noon"; String teatimeTimestamp = "teatime"; String midnightTimestamp = "midnight"; Assert.assertEquals(DateTimeParser.parse(noonTimestamp), referenceDateTime().withHourOfDay(12).withMinuteOfHour(0)); Assert.assertEquals(DateTimeParser.parse(teatimeTimestamp), referenceDateTime().withHourOfDay(16).withMinuteOfHour(0)); Assert.assertEquals(DateTimeParser.parse(midnightTimestamp), referenceDateTime().withHourOfDay(0).withMinuteOfHour(0)); }
private HttpEventsIngestionHandler getHttpEventsIngestionHandler() { if (this.httpEventsIngestionHandler == null) { this.httpEventsIngestionHandler = new HttpEventsIngestionHandler((EventsIO) ModuleLoader.getInstance(EventsIO.class, CoreConfig.EVENTS_MODULES)); } return this.httpEventsIngestionHandler; }
@Test public void testIncrementDecrement() { testFormat("now-10h", nowDateTime().minusHours(10)); testFormat("now+10h", nowDateTime().plusHours(10)); }
@Test public void testDayOfWeekFormat() { DateTime todayDate = referenceDateTime(); for (String dateTimeString: Arrays.asList("Fri", "14:42 Fri", "noon Fri")) { DateTime date = DateTimeParser.parse(dateTimeString); Assert.assertEquals(date.getDayOfWeek(), 5); Assert.assertTrue(todayDate.getDayOfYear() - date.getDayOfYear() <= 7); } }