Skip to content

Commit 78d04d5

Browse files
committed
Labels refactoring.
1 parent 78796fa commit 78d04d5

7 files changed

Lines changed: 31 additions & 19 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'io.github.mjfryc'
9-
version '1.0.0'
9+
version '1.0.1'
1010

1111
repositories {
1212
mavenCentral()

src/main/java/pl/mjaron/tinyloki/Labels.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,33 @@ public static Labels prettify(final Labels labels, final LabelSettings labelSett
394394
*
395395
* @param labels Map with label-name mapped to label-value pairs.
396396
* @return New instance of {@link Labels}.
397-
* @since 1.0.0
397+
* @since 1.0.1
398398
*/
399-
public static Labels make(final Map<String, String> labels) {
399+
public static Labels of(final Map<String, String> labels) {
400400
return new Labels(labels);
401401
}
402402

403403
/**
404-
* Creates a new empty labels instance.
404+
* Creates labels containing single name-value pair. Call {@link #l(String, String)} method to add more labels.
405405
*
406+
* @param name Label name. Valid label identifier starts with letter and contains only letters, digits or '_'.
407+
* @param value Label value. Valid label identifier starts with letter and contains only letters, digits or '_'.
406408
* @return New instance of {@link Labels}.
407-
* @since 1.0.0
409+
* @see #l(String, String)
410+
* @since 1.0.1
408411
*/
409-
public static Labels make() {
412+
public static Labels of(final String name, final String value) {
413+
return new Labels().l(name, value);
414+
}
415+
416+
/**
417+
* Creates a new empty labels instance. Call {@link #l(String, String)} method to add any labels.
418+
*
419+
* @return New instance of {@link Labels}.
420+
* @see #l(String, String)
421+
* @since 1.0.1
422+
*/
423+
public static Labels of() {
410424
return new Labels();
411425
}
412426

@@ -479,16 +493,14 @@ public String toString() {
479493
/**
480494
* Add a new label and return this object.
481495
*
482-
* @param labelName Label name. Valid label identifier starts with letter and contains only letters, digits or
483-
* '_'.
484-
* @param labelValue Label value. Valid label identifier starts with letter and contains only letters, digits or
485-
* '_'.
496+
* @param name Label name. Valid label identifier starts with letter and contains only letters, digits or '_'.
497+
* @param value Label value. Valid label identifier starts with letter and contains only letters, digits or '_'.
486498
* @return This object with added label.
487-
* @throws RuntimeException when given <code>labelName</code> or <code>labelValue</code> is null or empty.
499+
* @throws RuntimeException when given <code>name</code> or <code>value</code> is null or empty.
488500
* @since 0.1.22
489501
*/
490-
public Labels l(final String labelName, final String labelValue) {
491-
map.put(labelName, labelValue);
502+
public Labels l(final String name, final String value) {
503+
map.put(name, value);
492504
return this;
493505
}
494506

src/main/java/pl/mjaron/tinyloki/TinyLoki.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public IExecutor getExecutor() {
239239
*/
240240
@SuppressWarnings("unused")
241241
public ILogStream createStream(final Map<String, String> labels) {
242-
return this.createStream(Labels.make(labels));
242+
return this.createStream(Labels.of(labels));
243243
}
244244

245245
/**

src/test/java/pl/mjaron/tinyloki/IntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void verboseTest() throws InterruptedException {
3535

3636
// Initialize the log controller instance with URL.
3737
// The endpoint loki/api/v1/push will be added by default if missing.
38-
// Usually creating more than one TinyLoki instance doesn't make sense.
38+
// Usually creating more than one TinyLoki instance doesn't of sense.
3939
// TinyLoki (its default IExecutor implementation) owns separate thread which sends logs periodically.
4040
// It may be called inside try-with-resources block, but the default close() method doesn't synchronize the logs,
4141
// but just interrupts the background worker thread.

src/test/java/pl/mjaron/tinyloki/JsonLogCollectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static String byteArrayToCode(byte[] array) {
6868
}
6969

7070
public static byte[] hexStringToByteArray(String hexStr) {
71-
System.out.println(hexStr); // log our input make sure it is what we think it is.
71+
System.out.println(hexStr); // log our input of sure it is what we think it is.
7272
byte[] bArray = new byte[hexStr.length() / 3];
7373
int index = 0;
7474
for (String cell : hexStr.split(" ")) {

src/test/java/pl/mjaron/tinyloki/LabelsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void from() {
140140
HashMap<String, String> map = new HashMap<>();
141141
map.put("abc", "123");
142142
map.put("def", "456");
143-
Labels l = Labels.make(map);
143+
Labels l = Labels.of(map);
144144
assertEquals(l.getMap(), map);
145145
}
146146

@@ -149,7 +149,7 @@ void getMap() {
149149
HashMap<String, String> map = new HashMap<>();
150150
map.put("abc", "123");
151151
map.put("def", "456");
152-
Labels l = Labels.make(map);
152+
Labels l = Labels.of(map);
153153
assertEquals(l.getMap(), map);
154154
}
155155

src/test/java/pl/mjaron/tinyloki/TinyLokiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class TinyLokiTest {
99
@Test
1010
void dummySendLegacyTest() {
1111
TinyLoki tinyLoki = TinyLoki.withUrl("http://localhost/loki/api/v1/push").withLogSender(new DummyLogSender(1000)).withLogMonitor(new VerboseLogMonitor()).withLabelLength(1, 1).start();
12-
ILogStream abcStream = tinyLoki.createStream(Labels.make().info().l("abc", "bcd"));
12+
ILogStream abcStream = tinyLoki.createStream(Labels.of().info().l("abc", "bcd"));
1313
abcStream.log(1, "Hello world.");
1414
tinyLoki.softStop().hardStop();
1515
}

0 commit comments

Comments
 (0)