Skip to content

Commit

Permalink
renamed schedule density
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Oct 13, 2020
1 parent e9db32e commit 5ff008d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/task_manager/server/MONITORING.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ For example, if you _curl_ the `/api/task_manager/_health` endpoint, you might g
Here we see that on the 3rd polling interval from *now* (which is ~9 seconds from now, as pollInterval is `3s`) there is one task due to run.
We also see that there are 5 due two intervals later, which is fine as we have a max workers of `10`
*/
"scheduleDensity": [0, 0, 1, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
"estimatedScheduleDensity": [0, 0, 1, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}
},
"runtime": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('Workload Statistics Aggregator', () => {
// 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57
// [0, 0, 0, 0, 0, 0, 0, 2, 2, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
// Above you see each bucket and the number of scheduled tasks we expect to have in them
scheduleDensity: [0, 0, 0, 0, 0, 0, 0, 2, 2, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
estimatedScheduleDensity: [0, 0, 0, 0, 0, 0, 0, 2, 2, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
});
resolve();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface WorkloadStat extends JsonObject {
taskTypes: TaskTypeStat;
schedule: Array<[string, number]>;
overdue: number;
scheduleDensity: number[];
estimatedScheduleDensity: number[];
}

export interface WorkloadAggregation {
Expand Down Expand Up @@ -219,7 +219,7 @@ export function createWorkloadAggregator(
)
.map((schedule) => [schedule.key as string, schedule.doc_count]),
overdue,
scheduleDensity: padBuckets(scheduleDensityBuckets, pollInterval, scheduleDensity),
estimatedScheduleDensity: padBuckets(scheduleDensityBuckets, pollInterval, scheduleDensity),
};
return {
key: 'workload',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/task_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class TaskManagerPlugin
router,
this.taskManager.then((tm) => createMonitoringStats(tm, config, logger)),
logger,
this.taskManagerId,
// if "hot" health stats are any more stale than monitored_stats_required_freshness (pollInterval +1s buffer by default)
// consider the system unhealthy
config.monitored_stats_required_freshness,
Expand Down
16 changes: 11 additions & 5 deletions x-pack/plugins/task_manager/server/routes/health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { Observable, of, Subject } from 'rxjs';
import { take } from 'rxjs/operators';
import { merge } from 'lodash';
import uuid from 'uuid';
import { httpServiceMock } from 'src/core/server/mocks';
import { healthRoute } from './health';
import { mockHandlerArguments } from './_mock_handler_arguments';
Expand All @@ -22,7 +23,7 @@ describe('healthRoute', () => {
it('registers the route', async () => {
const router = httpServiceMock.createRouter();

healthRoute(router, Promise.resolve(of()), mockLogger(), 1000, 1000);
healthRoute(router, Promise.resolve(of()), mockLogger(), uuid.v4(), 1000, 1000);

const [config] = router.get.mock.calls[0];

Expand All @@ -41,7 +42,8 @@ describe('healthRoute', () => {

const stats = Promise.resolve(new Subject<MonitoringStats>());

healthRoute(router, stats, logger, 1000, 60000);
const id = uuid.v4();
healthRoute(router, stats, logger, id, 1000, 60000);

const stats$ = await stats;

Expand All @@ -53,18 +55,21 @@ describe('healthRoute', () => {

const firstDebug = JSON.parse(logger.debug.mock.calls[0][0]);
expect(firstDebug).toMatchObject({
id,
timestamp: expect.any(String),
status: expect.any(String),
...summarizeMonitoringStats(mockStat),
});

const secondDebug = JSON.parse(logger.debug.mock.calls[1][0]);
expect(secondDebug).not.toMatchObject({
id,
timestamp: expect.any(String),
status: expect.any(String),
...summarizeMonitoringStats(skippedMockStat),
});
expect(secondDebug).toMatchObject({
id,
timestamp: expect.any(String),
status: expect.any(String),
...summarizeMonitoringStats(nextMockStat),
Expand All @@ -84,6 +89,7 @@ describe('healthRoute', () => {
router,
Promise.resolve(of(mockStat)),
mockLogger(),
uuid.v4(),
1000,
60000
);
Expand Down Expand Up @@ -162,7 +168,7 @@ describe('healthRoute', () => {
},
},
});
healthRoute(router, Promise.resolve(of(mockStat)), mockLogger(), 5000, 60000);
healthRoute(router, Promise.resolve(of(mockStat)), mockLogger(), uuid.v4(), 5000, 60000);

const [, handler] = router.get.mock.calls[0];

Expand Down Expand Up @@ -213,7 +219,7 @@ describe('healthRoute', () => {
},
},
});
healthRoute(router, Promise.resolve(of(mockStat)), mockLogger(), 1000, 60000);
healthRoute(router, Promise.resolve(of(mockStat)), mockLogger(), uuid.v4(), 1000, 60000);

const [, handler] = router.get.mock.calls[0];

Expand Down Expand Up @@ -277,7 +283,7 @@ function mockHealthStats(overrides = {}) {
},
schedule: {},
overdue: 0,
scheduleDensity: [],
estimatedScheduleDensity: [],
},
},
runtime: {
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/task_manager/server/routes/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
RawMonitoringStats,
} from '../monitoring';

type MonitoredHealth = RawMonitoringStats & { status: HealthStatus; timestamp: string };
type MonitoredHealth = RawMonitoringStats & { id: string; status: HealthStatus; timestamp: string };

const LEVEL_SUMMARY = {
[ServiceStatusLevels.available.toString()]: 'Task Manager is healthy',
Expand All @@ -36,6 +36,7 @@ export function healthRoute(
router: IRouter,
monitoringStats: Promise<Observable<MonitoringStats>>,
logger: Logger,
taskManagerId: string,
requiredHotStatsFreshness: number,
requiredColdStatsFreshness: number
): Observable<ServiceStatus> {
Expand All @@ -56,7 +57,7 @@ export function healthRoute(
: hasStatus(summarizedStats.stats, HealthStatus.Warning)
? HealthStatus.Warning
: HealthStatus.OK;
return { timestamp, status: healthStatus, ...summarizedStats };
return { id: taskManagerId, timestamp, status: healthStatus, ...summarizedStats };
}

// Only calculate the summerized stats (calculates all runnign averages and evaluates state)
Expand Down

0 comments on commit 5ff008d

Please sign in to comment.