blob: 1f80b15596b09698a638ef52688570e2c46dba80 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metrics.docs;
import ai.vespa.metrics.Unit;
import java.io.FileWriter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author olaa
*/
public class UnitDocumentation {
protected static void writeUnitDocumentation(String path, Unit[] units) {
var referenceBuilder = new StringBuilder();
referenceBuilder.append(String.format("""
---
# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
title: "Metric Units Reference"
---
<table class="table">
<thead>
<tr><th>Unit</th><th>Description</th></tr>
</thead>
<tbody>
%s </tbody>
</table>
""", htmlRows(units)));
try (FileWriter fileWriter = new FileWriter(path + "/unit-metrics-reference.html")) {
fileWriter.write(referenceBuilder.toString());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private static String htmlRows(Unit[] units) {
return Stream.of(units)
.map(unit ->
String.format(
"""
<tr>
<td>%s</td>
<td>%s</td>
</tr>
""",
unit.fullName(),
unit.getDescription())
).collect(Collectors.joining());
}
}
|