Skip to content

Commit 67fcf5f

Browse files
committed
added tracing
fixed bug in mlcp dialog
1 parent 110158c commit 67fcf5f

File tree

14 files changed

+75
-74
lines changed

14 files changed

+75
-74
lines changed

marklogic-data-hub/build.gradle

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -171,42 +171,3 @@ ext {
171171
modulePaths = ["marklogic-data-hub/src/main/resources/ml-modules"]
172172
}
173173
}
174-
175-
ext {
176-
// don't create the REST Api. We will do it manually
177-
mlAppDeployer.commands.remove(mlAppDeployer.getCommand("DeployRestApiServersCommand"))
178-
mlAppDeployer.commands.remove(mlAppDeployer.getCommand("UpdateRestApiServersCommand"))
179-
180-
// remove the original deploy content database command
181-
// as we do not need it.
182-
def deployDbCmd = mlAppDeployer.getCommand("DeployContentDatabasesCommand")
183-
mlAppDeployer.commands.remove(deployDbCmd)
184-
185-
// install the staging database
186-
def stagingDbCommand = new com.marklogic.appdeployer.command.databases.DeployDatabaseCommand("staging-database.json")
187-
stagingDbCommand.setForestsPerHost(Integer.parseInt(mlStagingForestsPerHost));
188-
mlAppDeployer.commands.add(stagingDbCommand)
189-
mlDatabaseCommands.add(stagingDbCommand)
190-
191-
// install the final database
192-
def finalDbCommand = new com.marklogic.appdeployer.command.databases.DeployDatabaseCommand("final-database.json")
193-
finalDbCommand.setForestsPerHost(Integer.parseInt(mlFinalForestsPerHost));
194-
mlAppDeployer.commands.add(finalDbCommand)
195-
mlDatabaseCommands.add(finalDbCommand)
196-
197-
// install the trace database
198-
def traceDbCommand = new com.marklogic.appdeployer.command.databases.DeployDatabaseCommand("trace-database.json")
199-
traceDbCommand.setForestsPerHost(Integer.parseInt(mlTraceForestsPerHost));
200-
mlAppDeployer.commands.add(traceDbCommand)
201-
mlDatabaseCommands.add(traceDbCommand)
202-
203-
// install the modules database
204-
def modulesDbCommand = new com.marklogic.appdeployer.command.databases.DeployDatabaseCommand("modules-database.json")
205-
mlAppDeployer.commands.add(modulesDbCommand)
206-
mlDatabaseCommands.add(modulesDbCommand)
207-
208-
// temp workaround for ml-gradle issue #78
209-
// https://github.com/rjrudin/ml-gradle/issues/78
210-
def lmc = mlAppDeployer.getCommand("LoadModulesCommand")
211-
lmc.setModulesLoader(new com.marklogic.client.modulesloader.impl.DefaultModulesLoader(mlAppConfig.newXccAssetLoader()))
212-
}

marklogic-data-hub/src/main/java/com/marklogic/hub/TraceManager.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import com.marklogic.client.DatabaseClient;
55
import com.marklogic.client.MarkLogicIOException;
66
import com.marklogic.client.document.GenericDocumentManager;
7+
import com.marklogic.client.document.ServerTransform;
78
import com.marklogic.client.helper.LoggingObject;
9+
import com.marklogic.client.io.Format;
810
import com.marklogic.client.io.SearchHandle;
911
import com.marklogic.client.io.StringHandle;
1012
import com.marklogic.client.query.QueryManager;
@@ -83,8 +85,9 @@ private String serializeQuery(StructuredQueryBuilder sb, StructuredQueryBuilder.
8385
return result;
8486
}
8587

86-
public SearchHandle getTraces(String query, long start, long count) {
88+
public StringHandle getTraces(String query, long start, long count) {
8789
QueryManager queryMgr = databaseClient.newQueryManager();
90+
queryMgr.setPageLength(count);
8891

8992
StructuredQueryBuilder sb = queryMgr.newStructuredQueryBuilder(SEARCH_OPTIONS_NAME);
9093

@@ -99,13 +102,15 @@ public SearchHandle getTraces(String query, long start, long count) {
99102
String searchXml = serializeQuery(sb, sqd, sort);
100103

101104
RawCombinedQueryDefinition querydef = queryMgr.newRawCombinedQueryDefinition(new StringHandle(searchXml), SEARCH_OPTIONS_NAME);
102-
queryMgr.setPageLength(count);
103-
SearchHandle results = queryMgr.search(querydef, new SearchHandle(), start);
105+
querydef.setResponseTransform(new ServerTransform("trace-search"));
106+
StringHandle sh = new StringHandle();
107+
sh.setFormat(Format.JSON);
108+
StringHandle results = queryMgr.search(querydef, sh, start);
104109
return results;
105110
}
106111

107112
public JsonNode getTrace(String traceId) {
108113
GenericDocumentManager docMgr = databaseClient.newDocumentManager();
109-
return docMgr.readAs("/" + traceId, JsonNode.class);
114+
return docMgr.readAs("/" + traceId, JsonNode.class, new ServerTransform("trace-json"));
110115
}
111116
}

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/trace-lib.xqy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ declare function trace:enabled() as xs:boolean
5555
fn:false()
5656
};
5757

58-
declare function trace:has-errors()
58+
declare function trace:has-errors() as xs:boolean
5959
{
60-
map:get($current-trace-settings, "_has_errors") eq fn:true()
60+
(map:get($current-trace-settings, "_has_errors"), fn:false())[1] eq fn:true()
6161
};
6262

6363
declare function trace:init-trace($format as xs:string)
@@ -242,6 +242,8 @@ declare function trace:_walk_json($nodes as node()* ,$o)
242242
map:put($o, fn:local-name($n), xdmp:quote($n/node(), $quote-options))
243243
case element(duration) return
244244
map:put($o, "duration", fn:seconds-from-duration(xs:dayTimeDuration($n)))
245+
case element(hasError) return
246+
map:put($o, "hasError", xs:boolean($n))
245247
case element() return
246248
if ($n/*) then
247249
let $oo := json:object()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
xquery version "1.0-ml";
2+
3+
module namespace transform = "http://marklogic.com/rest-api/transform/trace-json";
4+
5+
import module namespace perf = "http://marklogic.com/data-hub/perflog-lib"
6+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
7+
8+
import module namespace trace = "http://marklogic.com/data-hub/trace"
9+
at "/com.marklogic.hub/lib/trace-lib.xqy";
10+
11+
declare namespace envelope = "http://marklogic.com/data-hub/envelope";
12+
13+
declare function transform(
14+
$context as map:map,
15+
$params as map:map,
16+
$content as document-node()
17+
) as document-node()
18+
{
19+
perf:log('/transforms/trace-json:transform', function() {
20+
21+
document {
22+
map:put($context, "output-types", "application/json"),
23+
xdmp:to-json(trace:trace-to-json($content/trace))
24+
}
25+
})
26+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var trace = require("/com.marklogic.hub/lib/trace-lib.xqy");
2+
3+
4+
function transform(contenxt, params, content) {
5+
var response = content.toObject();
6+
7+
for (var i = 0; i < response.results.length; i++) {
8+
var result = response.results[i];
9+
var doc = cts.doc(result.uri).root;
10+
xdmp.log(doc);
11+
result.content = trace.traceToJson(doc);
12+
response.pageLength = response['page-length'];
13+
}
14+
return response;
15+
}
16+
17+
exports.transform = transform;

marklogic-data-hub/src/trace-ui/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var modulePackage;
1313
for (dependency in packageJson.dependencies) {
1414
if (packageJson.dependencies.hasOwnProperty(dependency)) {
1515
modulePackage = require(pathUtil.join(dependency, 'package.json'));
16-
if (pathUtil.extname(modulePackage.main) === '.js') {
16+
if (modulePackage.main && pathUtil.extname(modulePackage.main) === '.js') {
1717
vendors.push(dependency);
1818
}
1919
}

quick-start/src/main/java/com/marklogic/quickstart/web/TracesController.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ TraceManager traceManager() {
3232
@ResponseBody
3333
public String getTraces(@RequestParam(required = false) String query, @RequestParam long start, @RequestParam long count) throws JsonProcessingException {
3434
requireAuth();
35-
ObjectMapper om = new ObjectMapper();
36-
SimpleModule module = new SimpleModule();
37-
module.addSerializer(SearchHandle.class, new SearchHandleSerializer());
38-
om.registerModule(module);
39-
return om.writeValueAsString(traceManager.getTraces(query, start, count));
35+
return traceManager.getTraces(query, start, count).get();
4036
}
4137

4238
@RequestMapping(value = "/{traceId}", method = RequestMethod.GET)

quick-start/src/main/ui/app/mlcp-ui/mlcp-ui.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h3 (click)="toggleSection(group.category)"><i class="fa fa-caret-right" [ngClas
3333
[labelText]="setting.label"
3434
[items]="setting.options"
3535
[initialSelectedItem]="setting.value"
36-
(selectedItem)="setting.value = $event"
36+
(selectedItem)="updateSetting(setting, $event)"
3737
*ngIf="setting.type === 'type'"
3838
[tooltip]="setting.description"
3939
label="label"

quick-start/src/main/ui/app/mlcp-ui/mlcp-ui.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class MlcpUi {
5757
startY: number = 0;
5858

5959
vizState: string = 'hidden';
60+
isVisible: boolean = false;
6061

6162
groups: Array<any>;
6263

@@ -97,6 +98,7 @@ export class MlcpUi {
9798
this.startY = $event.clientY;
9899
}
99100
this.vizState = 'active';
101+
this.isVisible = true;
100102
return this.finishedEvent;
101103
}
102104

@@ -506,6 +508,7 @@ export class MlcpUi {
506508

507509
hide() {
508510
this.vizState = 'hidden';
511+
this.isVisible = false;
509512
}
510513

511514
private cancel() {

quick-start/src/main/ui/app/pagination/pagination.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class Pagination implements OnInit, OnChanges {
4040
if (this.start && this.pageLength) {
4141
this.end = Math.min(this.start + this.pageLength - 1, this.total);
4242
this.currentPage = (this.start - 1) / this.pageLength + 1;
43-
this.totalPages = Math.floor(this.total / this.pageLength);
43+
this.totalPages = Math.ceil(this.total / this.pageLength);
4444
s = this.currentPage - 4;
4545
s = (s < 1) ? 1 : s;
4646
e = s + 8;

0 commit comments

Comments
 (0)