-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates new data service for Angular frontend with DataServiceInterface
PiperOrigin-RevId: 720673081
- Loading branch information
1 parent
3b04a3c
commit 6349c96
Showing
8 changed files
with
2,035 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
load("//defs:defs.bzl", "xprof_ng_module") | ||
|
||
package(default_visibility = ["//frontend:internal"]) | ||
|
||
xprof_ng_module( | ||
name = "data_service", | ||
srcs = [ | ||
"data_service.ts", | ||
], | ||
deps = [ | ||
":data_service_interface", | ||
"//third_party/javascript/safevalues/dom", | ||
"@npm//@angular/common", | ||
"@npm//@angular/core", | ||
"@npm//rxjs", | ||
"@org_xprof//frontend/app/common/angular:angular_common_http", | ||
"@org_xprof//frontend/app/common/constants", | ||
"@org_xprof//frontend/app/common/interfaces", | ||
], | ||
) | ||
|
||
xprof_ng_module( | ||
name = "data_service_interface", | ||
srcs = [ | ||
"data_service_interface.ts", | ||
"mock_interface_data.ts", | ||
], | ||
deps = [ | ||
"//third_party/javascript/safevalues/dom", | ||
"@npm//@angular/common", | ||
"@npm//@angular/core", | ||
"@npm//rxjs", | ||
"@org_xprof//frontend/app/common/angular:angular_common_http", | ||
"@org_xprof//frontend/app/common/constants", | ||
"@org_xprof//frontend/app/common/interfaces", | ||
], | ||
) |
84 changes: 84 additions & 0 deletions
84
frontend/app/services/consolidated_data_service/data_service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import {PlatformLocation} from '@angular/common'; | ||
import {HttpClient, HttpParams} from '@angular/common/http'; | ||
import {Injectable} from '@angular/core'; | ||
import {API_PREFIX, DATA_API, LOCAL_URL, PLUGIN_NAME} from 'org_xprof/frontend/app/common/constants/constants'; | ||
import {DataTable} from 'org_xprof/frontend/app/common/interfaces/data_table'; | ||
import {DataServiceInterface} from 'org_xprof/frontend/app/services/consolidated_data_service/data_service_interface'; | ||
import {Observable, of} from 'rxjs'; | ||
import {delay} from 'rxjs/operators'; | ||
|
||
import * as mockData from './mock_interface_data'; | ||
|
||
/** Delay time for milisecond for testing */ | ||
const DELAY_TIME_MS = 1000; | ||
|
||
/** The data service class that calls API and return response. */ | ||
@Injectable() | ||
export class ConsolidatedDataService implements DataServiceInterface { | ||
isLocalDevelopment = false; | ||
pathPrefix = ''; | ||
searchParams?: URLSearchParams; | ||
|
||
constructor( | ||
private readonly httpClient: HttpClient, | ||
platformLocation: PlatformLocation) { | ||
this.isLocalDevelopment = platformLocation.pathname === LOCAL_URL; | ||
if (String(platformLocation.pathname).includes(API_PREFIX + PLUGIN_NAME)) { | ||
this.pathPrefix = | ||
String(platformLocation.pathname).split(API_PREFIX + PLUGIN_NAME)[0]; | ||
} | ||
this.searchParams = new URLSearchParams(window.location.search); | ||
} | ||
|
||
getData( | ||
tag: string, run: string, host: string, | ||
parameters: Map<string, string> = new Map()): Observable<DataTable|null> { | ||
if (this.isLocalDevelopment) { | ||
if (tag.startsWith('overview_page')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_OVERVIEW_PAGE_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else if (tag.startsWith('input_pipeline_analyzer')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_INPUT_PIPELINE_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else if (tag.startsWith('tensorflow_stats')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_TENSORFLOW_STATS_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else if (tag.startsWith('memory_viewer')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_MEMORY_VIEWER_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else if (tag.startsWith('op_profile')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_OP_PROFILE_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else if (tag.startsWith('pod_viewer')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_POD_VIEWER_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else if (tag.startsWith('kernel_stats')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_KERNEL_STATS_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else if (tag.startsWith('memory_profile')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_MEMORY_PROFILE_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else if (tag.startsWith('tf_data_bottleneck_analysis')) { | ||
return of(mockData.DATA_PLUGIN_PROFILE_TF_DATA_BOTTLENECK_ANALYSIS_DATA) | ||
.pipe(delay(DELAY_TIME_MS)); | ||
} else { | ||
return of([]).pipe(delay(DELAY_TIME_MS)); | ||
} | ||
} | ||
const params = | ||
new HttpParams().set('run', run).set('tag', tag).set('host', host); | ||
parameters.forEach((value, key) => { | ||
params.set(key, value); | ||
}); | ||
return this.httpClient.get(this.pathPrefix + DATA_API, {params}) as | ||
Observable<DataTable>; | ||
} | ||
|
||
getDataWithParams( | ||
tool: string, | ||
run: string, | ||
paramsMap: Map<string, string>, | ||
): Observable<DataTable|null> { | ||
return this.getData(tool, run, '', paramsMap); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
frontend/app/services/consolidated_data_service/data_service_interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @fileoverview Data service interface meant to replace and consolidate | ||
* 1P/3P data services in the xprof frontend. | ||
*/ | ||
|
||
import {InjectionToken} from '@angular/core'; | ||
import {DataTable} from 'org_xprof/frontend/app/common/interfaces/data_table'; | ||
import {Observable} from 'rxjs'; | ||
|
||
/** The data service class that calls API and return response. */ | ||
export interface DataServiceInterface { | ||
getData( | ||
tool: string, | ||
run: string, | ||
host?: string, | ||
parameters?: Map<string, string>, | ||
ignoreError?: boolean, | ||
): Observable<DataTable|null>; | ||
getDataWithParams( | ||
run: string, | ||
tool: string, | ||
paramsMap: Map<string, string>, | ||
): Observable<DataTable|null>; | ||
} | ||
|
||
/** Injection token for the data service interface. */ | ||
export const DataServiceInterfaceToken = | ||
new InjectionToken<DataServiceInterface>( | ||
'DataServiceInterface', | ||
); |
Oops, something went wrong.