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

Added Dashboard table item for Rate Limits #3893

Merged
merged 4 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions webui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ProvidersComponent } from './components/providers/providers.component';
import { LetDirective } from './directives/let.directive';
import { BackendFilterPipe } from './pipes/backend.filter.pipe';
import { FrontendFilterPipe } from './pipes/frontend.filter.pipe';
import { HumanReadableFilterPipe } from './pipes/humanreadable.filter.pipe';
import { KeysPipe } from './pipes/keys.pipe';
import { ApiService } from './services/api.service';
import { WindowService } from './services/window.service';
Expand All @@ -28,6 +29,7 @@ import { WindowService } from './services/window.service';
KeysPipe,
FrontendFilterPipe,
BackendFilterPipe,
HumanReadableFilterPipe,
LetDirective
],
imports: [
Expand Down
35 changes: 35 additions & 0 deletions webui/src/app/components/providers/providers.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,41 @@ <h2>Hosts Proxy Headers</h2>
</div>
</div>

<!-- details.ratelimit-->
<div *ngIf="p.ratelimit">
<hr>
<div class="section-line">
<div class="columns">
<div class="column is-3">
<h2 class="section-line-header">Rate Limiting</h2>
</div>
<div class="column is-9">
<div class="control">
<div class="tags has-addons">
<span class="tag is-light">Extractor Function</span>
<span class="tag is-info">{{ p.ratelimit.extractorFunc }}</span>
</div>
</div>
<table class="table is-fullwidth is-hoverable table-fixed">
<thead>
<td>Rateset</td>
<td>Period</td>
<td>Average</td>
<td>Burst</td>
</thead>
<tbody>
<tr *ngFor="let rateset of p.ratelimit.rateset">
<td>{{rateset.id}}</td>
<td>{{rateset.period | humanreadable}}</td>
<td>{{rateset.average}}</td>
<td>{{rateset.burst}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

</div>
Expand Down
46 changes: 46 additions & 0 deletions webui/src/app/pipes/humanreadable.filter.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { HumanReadableFilterPipe } from './humanreadable.filter.pipe';

describe('HumanReadableFilterPipe', () => {
const pipe = new HumanReadableFilterPipe();

const datatable = [{
'given': '180000000000',
'expected': '180s'
},
{
'given': '4096.0',
'expected': '4096ns'
},
{
'given': '7200000000000',
'expected': '120m'
},
{
'given': '1337',
'expected': '1337ns'
},
{
'given': 'traefik',
'expected': 'traefik',
},
{
'given': '-23',
'expected': '-23',
},
{
'given': '0',
'expected': '0',
},
];

datatable.forEach(item => {
it((item.given + ' should be transformed to ' + item.expected ), () => {
expect(pipe.transform(item.given)).toEqual(item.expected);
});
});

it('create an instance', () => {
expect(pipe).toBeTruthy();
});

});
27 changes: 27 additions & 0 deletions webui/src/app/pipes/humanreadable.filter.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Pipe, PipeTransform } from '@angular/core';

/**
* HumanReadableFilterPipe converts a time period in nanoseconds to a human-readable
* string.
*/
@Pipe({name: 'humanreadable'})
export class HumanReadableFilterPipe implements PipeTransform {
transform(value): any {
let result = '';
const powerOf10 = Math.floor(Math.log10(value));

if (powerOf10 > 11) {
result = value / (60 * Math.pow(10, 9)) + 'm';
} else if (powerOf10 > 9) {
result = value / Math.pow(10, 9) + 's';
} else if (powerOf10 > 6) {
result = value / Math.pow(10, 6) + 'ms';
} else if (value > 0) {
result = Math.floor(value) + 'ns';
} else {
result = value;
}

return result;
}
}
3 changes: 3 additions & 0 deletions webui/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class ApiService {
frontend.headers.customResponseHeaders = this.toHeaderArray(frontend.headers.customResponseHeaders);
frontend.headers.sslProxyHeaders = this.toHeaderArray(frontend.headers.sslProxyHeaders);
}
if (frontend.ratelimit && frontend.ratelimit.rateset) {
frontend.ratelimit.rateset = this.toArray(frontend.ratelimit.rateset, 'id');
}
return frontend;
});

Expand Down