Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents 738bc41 + 9c242c5 commit 4b298fe
Show file tree
Hide file tree
Showing 46 changed files with 4,070 additions and 166 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ jobs:
- name: Lint
run: npm run lint

- name: Test
run: npm run test
- name: Unit Test
run: npm run unit-test

- name: Integration Test
run: npm run integration
run: npm run integration-test

test-examples:
strategy:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/on-push-to-main-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
- name: Lint
run: npm run lint

- name: Test
run: npm run test
- name: Unit Test
run: npm run unit-test

- name: Integration Test
run: npm run integration
run: npm run integration-test

- name: Generate README
uses: momentohq/standards-and-practices/github-actions/generate-and-commit-oss-readme@gh-actions-v1
Expand Down
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ npm run lint
### Run unit tests

```
npm run test
npm run unit-test
```

### Run integration tests

```
export TEST_AUTH_TOKEN=<YOUR_AUTH_TOKEN>
npm run integration
npm run integration-test
```

### Run all tests

```
export TEST_AUTH_TOKEN=<YOUR_AUTH_TOKEN>
npm run test
```
55 changes: 55 additions & 0 deletions examples/advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import {
Configurations,
MomentoLoggerFactory,
DefaultMomentoLoggerFactory,
DefaultMomentoLoggerLevel,
ExperimentalMetricsCsvMiddleware,
ExperimentalRequestLoggingMiddleware,
CredentialProvider,
} from '@gomomento/sdk';
import {range} from './utils/collections';
import * as fs from 'fs';
import {delay} from './utils/time';

const cacheName = 'cache';
const cacheKey = 'key';
Expand All @@ -34,6 +39,7 @@ async function main() {
await listCachesExample();
await setGetDeleteExample();
await concurrentGetsExample();
await middlewaresExample();
}

async function createCacheExample() {
Expand Down Expand Up @@ -123,6 +129,55 @@ async function concurrentGetsExample() {
});
}

async function middlewaresExample() {
const middlewaresExampleloggerFactory: MomentoLoggerFactory =
new DefaultMomentoLoggerFactory(DefaultMomentoLoggerLevel.DEBUG);
const middlewaresExamplelogger = middlewaresExampleloggerFactory.getLogger(
'AdvancedMiddlewaresExample'
);
middlewaresExamplelogger.info(
'Constructing a new Momento client with logging and metrics middlewares enabled'
);

const metricsCsvPath = './advanced-middlewares-example-metrics.csv';

const middlewaresExampleClient = new SimpleCacheClient({
configuration: Configurations.Laptop.v1(
middlewaresExampleloggerFactory
).withMiddlewares([
new ExperimentalRequestLoggingMiddleware(middlewaresExampleloggerFactory),
new ExperimentalMetricsCsvMiddleware(
metricsCsvPath,
middlewaresExampleloggerFactory
),
]),
credentialProvider: CredentialProvider.fromEnvironmentVariable({
environmentVariableName: 'MOMENTO_AUTH_TOKEN',
}),
defaultTtlSeconds: 60,
});

middlewaresExamplelogger.info(
'Issuing 2 set and get requests to demonstrate middleware request logging and metrics.'
);

for (let i = 0; i < 2; i++) {
await middlewaresExampleClient.set(cacheName, `middleware${i}`, 'VALUE');
await middlewaresExampleClient.get(cacheName, `middleware${i}`);
}

// wait for metrics to flush to disk
await delay(100);

logger.info(
`Here are the contents of the metrics csv file:\n\n${fs
.readFileSync(metricsCsvPath)
.toString()}`
);

middlewaresExamplelogger.info('Middlewares example complete!');
}

main()
.then(() => {
logger.info('success!!');
Expand Down
Loading

0 comments on commit 4b298fe

Please sign in to comment.