Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ node_js:
- "10"

services:
- docker
- docker

before_install:
- COMMIT=`git rev-parse HEAD` && echo "export const gitCommit = \"${COMMIT}\";" >src/server/version.js
- VERSION=`git describe --always --tags` && echo "export const gitVersion =\"${VERSION}\";" >>src/server/version.js

install:
- npm install
- npm install

script:
- npm run eslint
- npm run test
- npm run eslint
- npm run test
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:16.04
FROM quay.io/cdis/ubuntu:16.04

ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -16,8 +16,8 @@ RUN apt-get update \
COPY . /guppy/
WORKDIR /guppy

RUN COMMIT=`git rev-parse HEAD` && echo "export const guppyCommit = \"${COMMIT}\";" >versions.js
RUN VERSION=`git describe --always --tags` && echo "export const guppyVersion =\"${VERSION}\";" >>versions.js
RUN COMMIT=`git rev-parse HEAD` && echo "export const gitCommit = \"${COMMIT}\";" >src/server/version.js
RUN VERSION=`git describe --always --tags` && echo "export const gitVersion =\"${VERSION}\";" >>src/server/version.js
RUN /bin/rm -rf .git
RUN /bin/rm -rf node_modules

Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,15 @@ npm start
>
> (E.g., `"tier_access_sensitive_record_exclusion_field": "sensitive"` in the Guppy config tells Guppy to look for a field in the ES index called `sensitive`, and to exclude records in the ES index which have `sensitive: "true"`)

### Download Endpoint:
Guppy has another special endpoint `/download` for just fetching raw data from elasticsearch. please see [here](https://github.com/uc-cdis/guppy/blob/master/doc/download.md) for more details.
### Additional Guppy Endpoints:
Guppy has a special endpoint `/download` for just fetching raw data from elasticsearch. This endpoint can be used to overcome Elastic Search's 10k record limit. Please see [here](https://github.com/uc-cdis/guppy/blob/master/doc/download.md) for details.

Guppy's `/_status` endpoint yields health check and array field information. This endpoint is publicly accessible and returns output of the form
```
{"statusCode":200,"warnings":null,"indices":{"<index-name>":{"aliases":{"alias-name":{}},"arrayFields":["<name-of-array-field>"]}}}
```

The `/_version` endpoint yields version and commit information. This endpoint is publicly accessible and returns output of the form
```
{"version":"<version-string>","commit":"<commit-hash>"}
```
20 changes: 20 additions & 0 deletions src/server/endpoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import esInstance from './es/index';
import { gitVersion, gitCommit } from './version';

export const statusRouter = async (req, res, next) => {
try {
const data = await esInstance.getAllESIndices();
res.send(data);
} catch (err) {
next(err);
}
return 0;
};

export const versionRouter = async (req, res) => {
res.send({
version: gitVersion,
commit: gitCommit,
});
return 0;
};
36 changes: 36 additions & 0 deletions src/server/es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,42 @@ class ES {
);
}

/**
* Get all es indices and their alias
*/
getAllESIndices() {
const indicesArray = this.config.indices.map((e) => e.index);
if (this.config.configIndex) {
indicesArray.push(this.config.configIndex);
}
return this.client.indices.getAlias({
index: indicesArray,
}).then((resp) => {
try {
const indicesMetadata = resp.body;
const indicesWithArrayFields = Object.keys(this.arrayFields);
for (let i = 0; i < indicesWithArrayFields.length; i += 1) {
const indexName = indicesWithArrayFields[i];
if (!indicesMetadata[indexName]) {
indicesMetadata[indexName] = {};
}
indicesMetadata[indexName].arrayFields = this.arrayFields[indexName];
}
return {
statusCode: resp.statusCode,
warnings: resp.warnings,
indices: {
...indicesMetadata,
},
};
} catch (err) {
throw new Error(err);
}
}, (err) => {
throw new Error(err);
});
}

/**
* Check if the field is array
*/
Expand Down
13 changes: 11 additions & 2 deletions src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import headerParser from './utils/headerParser';
import getAuthHelperInstance from './auth/authHelper';
import downloadRouter from './download';
import CodedError from './utils/error';
import { statusRouter, versionRouter } from './endpoints';

const app = express();
app.use(cors());
Expand Down Expand Up @@ -47,10 +48,18 @@ const startServer = () => {
});

// simple health check endpoint
app.get('/_status', (req, res) => {
res.send('hello guppy');
// eslint-disable-next-line no-unused-vars
app.get('/_status', statusRouter, (req, res, err, next) => {
if (err instanceof CodedError) {
res.status(err.code).send(err.msg);
} else {
res.status(500).send(err);
}
});

// eslint-disable-next-line no-unused-vars
app.get('/_version', versionRouter);

// download endpoint for fetching data directly from es
app.post('/download',
downloadRouter, (err, req, res, next) => { // eslint-disable-line no-unused-vars
Expand Down
2 changes: 2 additions & 0 deletions src/server/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const gitCommit = 'N/A';
export const gitVersion = 'N/A';