Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config slurper master #191

Closed
Closed
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
51d993a
Redesign generic loader and start creating tests
kevinhinterlong Mar 3, 2017
eb50f85
Fix unit tests for metrics/dimensions
kevinhinterlong Mar 3, 2017
64503c2
Expand test, set up for loading metrics
kevinhinterlong Mar 3, 2017
93af80d
Add interfaces. Need to guess time grain
kevinhinterlong Mar 3, 2017
daabf0e
Merge remote-tracking branch 'refs/remotes/yahoo/master' into configS…
kevinhinterlong Mar 5, 2017
52303e0
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 5, 2017
1766d91
Only use references to interfaces
kevinhinterlong Mar 7, 2017
3f2517d
Got most tests working. Still need to refactor and run maven tests fo…
kevinhinterlong Mar 8, 2017
9abe713
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 8, 2017
83a6fb8
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 8, 2017
f030d84
Remove unnecessary code and fix tests
kevinhinterlong Mar 8, 2017
a690dc0
create base url for coordinator in druidNavigator
kevinhinterlong Mar 8, 2017
a7f3ef5
Rename files to Generic* instead of Wiki*
kevinhinterlong Mar 8, 2017
2d3bb87
Fix url typo in DruidNavigator and refactor
kevinhinterlong Mar 8, 2017
d5be970
reordering
kevinhinterlong Mar 8, 2017
bb96450
Refactor to remove test code, Small rearrangements, remove some unuse…
kevinhinterlong Mar 8, 2017
b4b76e4
Remove GenericBinder singleton
kevinhinterlong Mar 11, 2017
af23ce1
Finish refactoring, remove unnecesary Singleton class
kevinhinterlong Mar 14, 2017
f1bbbb7
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 14, 2017
7aff9bb
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 14, 2017
0894bec
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 14, 2017
02789c4
Fix most code suggestions from review
kevinhinterlong Mar 14, 2017
98d3637
Remove unnecesary code/comments
kevinhinterlong Mar 16, 2017
7665012
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 16, 2017
4eb5d55
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 16, 2017
18a3ef8
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 16, 2017
99845c3
Reformatting, remove unused imports/code
kevinhinterlong Mar 16, 2017
da7773a
Merge changes from code review kevinhinterlong/configSlurperDevelopment
kevinhinterlong Mar 16, 2017
9071bce
Minor fixes to clean up from codacy review
kevinhinterlong Mar 16, 2017
78da58d
Merge pull request #9 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Mar 16, 2017
bda3a6c
Remove uses of ConfigLoader, Fix some checkstyle errors
kevinhinterlong Mar 16, 2017
0dad160
Comment Most classes and remove unneeded code.
kevinhinterlong Mar 16, 2017
aae028c
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 16, 2017
4f9e824
Clean up unneeded code and add comments
kevinhinterlong Mar 16, 2017
802e60f
Finish commenting and removing unneeded code.
kevinhinterlong Mar 16, 2017
62eedae
Fix existing test cases.
kevinhinterlong Mar 16, 2017
70c87fb
Add better timegrain checking and tests for it
kevinhinterlong Mar 17, 2017
8552f8e
Remove use of camelcase, change foreach to stream
kevinhinterlong Mar 17, 2017
412be7b
Remove unused import
kevinhinterlong Mar 17, 2017
d013895
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 17, 2017
e8bbb61
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 17, 2017
9ff07bf
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 17, 2017
e04d369
Remove accidental code duplication, more streams, some usage document…
kevinhinterlong Mar 17, 2017
c982d43
Remove unused variables from GenericMetricLoader
kevinhinterlong Mar 17, 2017
caf0052
Merge pull request #10 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Mar 17, 2017
3f8bd0b
Remove import, add final
kevinhinterlong Mar 23, 2017
fe09ada
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 23, 2017
4cf8108
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 23, 2017
56b8d3b
Refactor timegrain detection
kevinhinterlong Mar 27, 2017
6e5ca46
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 27, 2017
b8df865
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 27, 2017
9822d42
Merge pull request #11 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Mar 27, 2017
4504cd6
Rearranged import
kevinhinterlong Mar 29, 2017
a9c9094
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 29, 2017
2c233f5
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 29, 2017
7010ea3
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 29, 2017
f8b44bc
Fix test cases and config file
kevinhinterlong Mar 29, 2017
925599b
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 29, 2017
36ef864
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 29, 2017
e0b673e
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 29, 2017
f4b6488
Fix from upstream changes
kevinhinterlong Mar 29, 2017
fc69d89
Keep reference to datasourcemetadataservice
kevinhinterlong Mar 29, 2017
33ba9dd
Override DruidDimensionsLoader constructor and build it manually
kevinhinterlong Mar 30, 2017
f18830a
fix coordinator url in DruidNavigator
kevinhinterlong Mar 30, 2017
42fb25a
Fix getting DataSourceMetadataService
kevinhinterlong Mar 30, 2017
402ac33
Fix test cases, Manually build druid webservice, refactor DruidDimens…
kevinhinterlong Mar 30, 2017
5326ec0
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 30, 2017
c97f728
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 30, 2017
5406749
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 30, 2017
cf47962
Fix readme, mark dimension cache healthy, and build druid webservice …
kevinhinterlong Mar 31, 2017
60b3c15
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 31, 2017
4352c0c
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Mar 31, 2017
e1f131b
Style/comment cleanup
kevinhinterlong Mar 31, 2017
27e5f24
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 31, 2017
b51f921
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Mar 31, 2017
1e1f759
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Mar 31, 2017
43f398f
Update readme
kevinhinterlong Apr 2, 2017
a66db2b
Merge pull request #12 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Apr 2, 2017
0bb826a
Fix formatting, remove unused imports, add more logging
kevinhinterlong Apr 2, 2017
932144a
Merge pull request #13 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Apr 2, 2017
19c546a
Fix javadoc
kevinhinterlong Apr 2, 2017
a1f63fc
Merge pull request #14 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Apr 2, 2017
750ebc2
Small refactoring
kevinhinterlong Apr 5, 2017
82a8847
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Apr 5, 2017
3944ed1
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Apr 5, 2017
10bbc70
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Apr 5, 2017
2ab0669
Merge pull request #15 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Apr 5, 2017
d6c1b2a
Refactor java to be more clear, fix some logging levels
kevinhinterlong Apr 7, 2017
a9b9809
Address most comments from review
kevinhinterlong Apr 8, 2017
32f0a9e
Add fili's port as a system property
kevinhinterlong Apr 10, 2017
6ce0de3
Clean up Druid dimension loader and finish addressing comments
kevinhinterlong Apr 11, 2017
7b0799e
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Apr 11, 2017
c73b626
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Apr 11, 2017
bbc5720
Merge branch 'configSlurperMaster' of https://github.com/kevinhinterl…
kevinhinterlong Apr 11, 2017
8886b8c
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Apr 11, 2017
e0480a8
Merge pull request #17 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Apr 11, 2017
ccb1b57
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Apr 15, 2017
c32785f
Add expected druid responses to druid navigator
kevinhinterlong Apr 15, 2017
7c97a3c
Merge pull request #18 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Apr 15, 2017
b1c57cc
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Apr 15, 2017
a3cad5c
Merge remote-tracking branch 'origin/configSlurperMaster' into config…
kevinhinterlong Apr 15, 2017
3939765
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Apr 15, 2017
2edfedd
Fix missing import lines
kevinhinterlong Apr 16, 2017
0ee5996
Cleanup and more comments
kevinhinterlong Apr 18, 2017
d8b674c
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Apr 18, 2017
8adb318
Merge remote-tracking branch 'refs/remotes/yahoo/master'
kevinhinterlong Apr 20, 2017
ebd786a
Merge remote-tracking branch 'refs/remotes/origin/master' into config…
kevinhinterlong Apr 20, 2017
f598cbc
Merge remote-tracking branch 'refs/remotes/origin/configSlurperMaster…
kevinhinterlong Apr 20, 2017
c04817d
Merge pull request #19 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Apr 20, 2017
34c5c19
Update for upstream changes
kevinhinterlong Apr 20, 2017
6739979
Merge pull request #20 from kevinhinterlong/configSlurperDevelopment
kevinhinterlong Apr 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class DruidDimensionsLoader extends Loader<Boolean> {

/**
* DruidDimensionsLoader fetches data from Druid and adds it to the dimension cache.
* The dimensions loaded are taken from the system config.
*
* @param physicalTableDictionary The physical tables
* @param dimensionDictionary The dimensions to update
Expand All @@ -83,6 +84,30 @@ public DruidDimensionsLoader(
PhysicalTableDictionary physicalTableDictionary,
DimensionDictionary dimensionDictionary,
DruidWebService druidWebService
) {
this(
physicalTableDictionary,
dimensionDictionary,
//Our configuration framework automatically converts a comma-separated config value into a list.
SYSTEM_CONFIG.getListProperty(DRUID_DIM_LOADER_DIMENSIONS),
druidWebService
);
}

/**
* DruidDimensionsLoader fetches data from Druid and adds it to the dimension cache.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we update the javadoc on the other constructor to indicate what it's doing, and call out what it's doing differently than this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* The dimensions to be loaded can be passed in as a parameter.
*
* @param physicalTableDictionary The physical tables
* @param dimensionDictionary The dimension dictionary to load dimensions from.
* @param dimensionsToLoad The dimensions to use.
* @param druidWebService The druid webservice to query.
*/
public DruidDimensionsLoader(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this constructor up under the other one? In general, it's best to group constructors, since they tend to call each other, and it's easier to see what's going on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

PhysicalTableDictionary physicalTableDictionary,
DimensionDictionary dimensionDictionary,
List<String> dimensionsToLoad,
DruidWebService druidWebService
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this constructor needed, is it actually needed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor is called from GenericBinderFactory::buildDruidDimensionsLoader, right? It looks like it's doing something different with the dimensions (ie. different than what the buildDimensionList method does)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

super(
DruidDimensionsLoader.class.getSimpleName(),
Expand All @@ -100,17 +125,14 @@ public DruidDimensionsLoader(

lastRunTimestamp = new AtomicReference<>();

//Our configuration framework automatically converts a comma-separated config value into a list.
List<String> dimensionStr = SYSTEM_CONFIG.getListProperty(DRUID_DIM_LOADER_DIMENSIONS);

// A DruidSearchQuery requires a list of dimensions, which we would have to explicitly create at serialization
// time if `dimensions` were a flat list instead of a list of singleton lists.
dimensions = dimensionStr.stream()
// A DruidSearchQuery requires a list of dimensions, which we would have to explicitly create at serialization
// time if `dimensions` were a flat list instead of a list of singleton lists.
this.dimensions = dimensionsToLoad.stream()
.map(dimensionDictionary::findByApiName)
.map(Collections::singletonList)
.collect(Collectors.toList());

dataSources = physicalTableDictionary.values().stream()
this.dataSources = physicalTableDictionary.values().stream()
.filter(physicalTable -> physicalTable instanceof ConcretePhysicalTable)
.map(physicalTable -> (ConcretePhysicalTable) physicalTable)
.map(TableDataSource::new)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2016 Yahoo Inc.
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms.
package com.yahoo.bard.webservice.data.config.dimension;

import com.yahoo.bard.webservice.data.dimension.DimensionField;

/**
* DimensionField enum.
*/
public enum DefaultDimensionField implements DimensionField {
ID("Dimension ID");

private String description;
private String camelName;

/**
* Constructor.
*
* @param description Description of this field
*/
DefaultDimensionField(String description) {
this.description = description;
this.camelName = name();
}

@Override
public String getName() {
return camelName;
}

@Override
public String getDescription() {
return description;
}

@Override
public String toString() {
return camelName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.yahoo.bard.webservice.config.SystemConfig;
import com.yahoo.bard.webservice.config.SystemConfigProvider;
import com.yahoo.bard.webservice.data.time.ZonedTimeGrain;
import com.yahoo.bard.webservice.data.time.StandardGranularityParser;
import com.yahoo.bard.webservice.data.time.TimeGrain;
import com.yahoo.bard.webservice.druid.model.query.Granularity;
import com.yahoo.bard.webservice.table.PhysicalTable;
import com.yahoo.bard.webservice.table.PhysicalTableSchema;
Expand Down Expand Up @@ -230,4 +232,21 @@ public static Optional<ZonedTimeGrain> getCoarsestTimeGrain(Collection<PhysicalT
.map(PhysicalTable::getSchema)
.map(PhysicalTableSchema::getTimeGrain);
}

/**
* Find a valid timegrain for the interval based on the start and end date of the interval.
*
* @param interval The interval to find a timegrain for.
* @return the valid timegrain spanned by the interval.
*/
public static Optional<TimeGrain> getTimeGrain(Interval interval) {
return StandardGranularityParser.getDefaultGrainMap()
.values()
.stream()
.filter(granularity -> granularity instanceof TimeGrain)
.map(granularity -> (TimeGrain) granularity)
.filter(timeGrain -> timeGrain.aligns(interval))
.filter(timeGrain -> interval.getStart().plus(timeGrain.getPeriod()).equals(interval.getEnd()))
.findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import static com.yahoo.bard.webservice.data.time.DefaultTimeGrain.QUARTER
import static com.yahoo.bard.webservice.data.time.DefaultTimeGrain.WEEK
import static com.yahoo.bard.webservice.data.time.DefaultTimeGrain.YEAR

import com.yahoo.bard.webservice.data.time.DefaultTimeGrain
import com.yahoo.bard.webservice.data.time.TimeGrain
import com.yahoo.bard.webservice.data.time.ZonedTimeGrain
import com.yahoo.bard.webservice.druid.model.query.AllGranularity
import com.yahoo.bard.webservice.druid.model.query.Granularity
Expand Down Expand Up @@ -377,6 +379,31 @@ class IntervalUtilsSpec extends Specification {
IntervalUtils.getCoarsestTimeGrain([]) == Optional.empty()
}

@Unroll
def "test getTimeGrain from interval - #expectedTimeGrain"() {
setup:
String[] dates = stringInterval.split("/")
DateTime start = new DateTime(dates[0], DateTimeZone.UTC)
DateTime end = new DateTime(dates[1], DateTimeZone.UTC)
Interval interval = new Interval(start.toInstant(), end.toInstant())

when: "we parse the time"
Optional<TimeGrain> timeGrain = IntervalUtils.getTimeGrain(interval)

then: "what we expect"
timeGrain == expectedTimeGrain

where:
stringInterval | expectedTimeGrain
"2015-01-01T00:00:00.000Z/2016-01-01T00:00:00.000Z" | Optional.of(YEAR)
"2017-01-01T00:00:00.000Z/2017-02-01T00:00:00.000Z" | Optional.of(MONTH)
"2017-02-27T00:00:00.000Z/2017-03-06T00:00:00.000Z" | Optional.of(WEEK)
"2015-09-12T00:00:00.000Z/2015-09-13T01:01:01.000Z" | Optional.empty()
"2015-09-12T00:00:00.000Z/2015-09-13T00:00:00.000Z" | Optional.of(DAY)
"2015-09-12T00:00:00.000Z/2015-09-12T01:00:00.000Z" | Optional.of(DefaultTimeGrain.HOUR)
"2015-09-12T00:00:00.000Z/2015-09-12T00:01:00.000Z" | Optional.of(DefaultTimeGrain.MINUTE)
}

/**
* Returns the instant at which this year began.
*
Expand Down
93 changes: 93 additions & 0 deletions fili-generic-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Fili Generic Loader Application
==================================

This application will automatically configure fili to work with **any** instance of Druid and show the basic metrics and dimensions. This lets you test what it's like using Fili without putting any effort into setting it up.

In order to set up, this will connect to druid at [http://localhost:8081/druid/coordinator/v1](http://localhost:8081/druid/coordinator/v1). If your set up is different, you'll have to change the `bard__druid_coord` url in `applicationConfig.properties`.

## Setup and Launching
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably mention the default druid endpoint we are expecting somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


1. Have a [Druid](http://druid.io/docs/latest/tutorials/quickstart.html) cluster running on your Unix based machine.

2. Clone this repository to your computer.
```bash
git clone git@github.com:yahoo/fili.git
```
3. Use Maven to install and launch the Fili Generic example:


```bash
cd fili
mvn install
mvn -pl fili-generic-example exec:java
```

- Note that if your setup is different you can adjust it by changing the default parameters below

```bash
mvn -pl fili-generic-example exec:java -Dbard__fili_port=9998 -Dbard__druid_coord=http://localhost:8081/druid/coordinator/v1
```

From another window, run a test query against the default druid data.

## Example Queries

Here are some sample queries that you can run to verify your server:

### Any Server

- List tables:

GET http://localhost:9998/v1/tables

- List dimensions:

GET http://localhost:9998/v1/dimensions

- List metrics:

GET http://localhost:9998/v1/metrics/

### Specific to Wikipedia data

- If everything is working, the query below
```bash
curl "http://localhost:9998/v1/data/wikiticker/day/?metrics=deleted&dateTime=2015-09-12/PT24H" -H "Content-Type: application/json" | python -m json.tool
```
should show something like:
```
{
"rows": [{
"dateTime": "2015-09-12 00:00:00.000",
"deleted": 394298.0
}]
}
```

- Count of edits by hour for the last 72 hours:

GET http://localhost:9998/v1/data/wikiticker/day/?metrics=count&dateTime=PT72H/current
Note: this will should be something like the response below unless you have streaming data.
```json
{
"rows": [],
"meta": {
"missingIntervals": ["2017-03-30 00:00:00.000/2017-04-02 00:00:00.000"]
}
}
```

- Show debug info, including the query sent to Druid:

GET http://localhost:9998/v1/data/wikiticker/day/?format=debug&metrics=count&dateTime=PT72H/current

## Notable Restrictions

- Using this is great for testing out fili and druid, but it can't do interesting things with metrics.
- This can only use 1 timegrain even though a datasource in druid *could* have more.

## Importing and Running in IntelliJ

1. In IntelliJ, go to `File -> Open`
2. Select the `pom.xml` file at the root of the project
3. Run `GenericMain` which can be found in `fili-generic-example` (e.g. right click and choose run)
Loading