Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ public PushGateway(String address) {
}

/**
* Pushes all metrics in a registry, replacing all those with the same job as the grouping key.
* Pushes all metrics in a registry, replacing all those with the same job and no grouping key.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment was correct, the job is part of the grouping key.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are three other methods down below with similar signature that say "same job and no grouping key". I think this is to differentiate with the methods which take groupingKey map as argument.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just offering them as optional parameters. The grouping key comprises the job label plus whatever other optional labels you add.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that.

There are eight methods:

1. push(CollectorRegistry registry, String job)
2. push(Collector collector, String job)

3. push(CollectorRegistry registry, String job, Map<String, String> groupingKey)
4. push(Collector collector, String job, Map<String, String> groupingKey)

5. pushAdd(CollectorRegistry registry, String job)
6. pushAdd(Collector collector, String job)

7. pushAdd(CollectorRegistry registry, String job, Map<String, String> groupingKey)
8. pushAdd(Collector collector, String job, Map<String, String> groupingKey)

Methods 1,2,5,6 should have similar documentation. I made the documentation for method 1 similar to what was there for methods 2,5,6.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

* <p>
* This uses the POST HTTP method.
* This uses the PUT HTTP method.
*/
public void push(CollectorRegistry registry, String job) throws IOException {
doRequest(registry, job, null, "POST");
doRequest(registry, job, null, "PUT");
}

/**
* Pushes all metrics in a Collector, replacing all those with the same job and no grouping key.
* <p>
* This is useful for pushing a single Gauge.
* <p>
* This uses the POST HTTP method.
* This uses the PUT HTTP method.
*/
public void push(Collector collector, String job) throws IOException {
CollectorRegistry registry = new CollectorRegistry();
Expand All @@ -88,22 +88,20 @@ public void push(Collector collector, String job) throws IOException {
}

/**
* Pushes all metrics in a Collector, replacing all those with the same job and grouping key.
* Pushes all metrics in a registry, replacing all those with the same job and grouping key.
* <p>
* This is useful for pushing a single Gauge.
* <p>
* This uses the POST HTTP method.
* This uses the PUT HTTP method.
*/
public void push(CollectorRegistry registry, String job, Map<String, String> groupingKey) throws IOException {
doRequest(registry, job, groupingKey, "POST");
doRequest(registry, job, groupingKey, "PUT");
}

/**
* Pushes all metrics in a Collector, replacing all those with the same job and grouping key.
* <p>
* This is useful for pushing a single Gauge.
* <p>
* This uses the POST HTTP method.
* This uses the PUT HTTP method.
*/
public void push(Collector collector, String job, Map<String, String> groupingKey) throws IOException {
CollectorRegistry registry = new CollectorRegistry();
Expand All @@ -114,18 +112,18 @@ public void push(Collector collector, String job, Map<String, String> groupingKe
/**
* Pushes all metrics in a registry, replacing only previously pushed metrics of the same name and job and no grouping key.
* <p>
* This uses the PUT HTTP method.
* This uses the POST HTTP method.
*/
public void pushAdd(CollectorRegistry registry, String job) throws IOException {
doRequest(registry, job, null, "PUT");
doRequest(registry, job, null, "POST");
}

/**
* Pushes all metrics in a Collector, replacing only previously pushed metrics of the same name and job and no grouping key.
* <p>
* This is useful for pushing a single Gauge.
* <p>
* This uses the PUT HTTP method.
* This uses the POST HTTP method.
*/
public void pushAdd(Collector collector, String job) throws IOException {
CollectorRegistry registry = new CollectorRegistry();
Expand All @@ -134,22 +132,20 @@ public void pushAdd(Collector collector, String job) throws IOException {
}

/**
* Pushes all metrics in a Collector, replacing only previously pushed metrics of the same name, job and grouping key.
* <p>
* This is useful for pushing a single Gauge.
* Pushes all metrics in a registry, replacing only previously pushed metrics of the same name, job and grouping key.
* <p>
* This uses the PUT HTTP method.
* This uses the POST HTTP method.
*/
public void pushAdd(CollectorRegistry registry, String job, Map<String, String> groupingKey) throws IOException {
doRequest(registry, job, groupingKey, "PUT");
doRequest(registry, job, groupingKey, "POST");
}

/**
* Pushes all metrics in a Collector, replacing only previously pushed metrics of the same name, job and grouping key.
* <p>
* This is useful for pushing a single Gauge.
* <p>
* This uses the PUT HTTP method.
* This uses the POST HTTP method.
*/
public void pushAdd(Collector collector, String job, Map<String, String> groupingKey) throws IOException {
CollectorRegistry registry = new CollectorRegistry();
Expand Down Expand Up @@ -182,7 +178,7 @@ public void delete(String job, Map<String, String> groupingKey) throws IOExcepti
/**
* Pushes all metrics in a registry, replacing all those with the same job and instance.
* <p>
* This uses the POST HTTP method.
* This uses the PUT HTTP method.
* @deprecated use {@link #push(CollectorRegistry, String, Map)}
*/
@Deprecated
Expand All @@ -195,7 +191,7 @@ public void push(CollectorRegistry registry, String job, String instance) throws
* <p>
* This is useful for pushing a single Gauge.
* <p>
* This uses the POST HTTP method.
* This uses the PUT HTTP method.
* @deprecated use {@link #push(Collector, String, Map)}
*/
@Deprecated
Expand All @@ -206,7 +202,7 @@ public void push(Collector collector, String job, String instance) throws IOExce
/**
* Pushes all metrics in a registry, replacing only previously pushed metrics of the same name.
* <p>
* This uses the PUT HTTP method.
* This uses the POST HTTP method.
* @deprecated use {@link #pushAdd(CollectorRegistry, String, Map)}
*/
@Deprecated
Expand All @@ -219,7 +215,7 @@ public void pushAdd(CollectorRegistry registry, String job, String instance) thr
* <p>
* This is useful for pushing a single Gauge.
* <p>
* This uses the PUT HTTP method.
* This uses the POST HTTP method.
* @deprecated use {@link #pushAdd(Collector, String, Map)}
*/
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void setUp() {
public void testPush() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j")
).respond(response().withStatusCode(202));
pg.push(registry, "j");
Expand All @@ -50,7 +50,7 @@ public void testPush() throws IOException {
public void testNon202ResponseThrows() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j")
).respond(response().withStatusCode(500));
pg.push(registry, "j");
Expand All @@ -60,7 +60,7 @@ public void testNon202ResponseThrows() throws IOException {
public void testPushCollector() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j")
).respond(response().withStatusCode(202));
pg.push(gauge, "j");
Expand All @@ -70,7 +70,7 @@ public void testPushCollector() throws IOException {
public void testPushWithGroupingKey() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j/l/v")
).respond(response().withStatusCode(202));
pg.push(registry, "j", groupingKey);
Expand All @@ -80,7 +80,7 @@ public void testPushWithGroupingKey() throws IOException {
public void testPushWithMultiGroupingKey() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j/l/v/l2/v2")
).respond(response().withStatusCode(202));
groupingKey.put("l2", "v2");
Expand All @@ -91,7 +91,7 @@ public void testPushWithMultiGroupingKey() throws IOException {
public void testPushWithGroupingKeyWithSlashes() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/a%2Fb/l/v/l2/v%2F2")
).respond(response().withStatusCode(202));
groupingKey.put("l2", "v/2");
Expand All @@ -102,7 +102,7 @@ public void testPushWithGroupingKeyWithSlashes() throws IOException {
public void testPushCollectorWithGroupingKey() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j/l/v")
).respond(response().withStatusCode(202));
pg.push(gauge, "j", groupingKey);
Expand All @@ -112,7 +112,7 @@ public void testPushCollectorWithGroupingKey() throws IOException {
public void testPushAdd() throws IOException {
mockServerClient.when(
request()
.withMethod("PUT")
.withMethod("POST")
.withPath("/metrics/job/j")
).respond(response().withStatusCode(202));
pg.pushAdd(registry, "j");
Expand All @@ -122,7 +122,7 @@ public void testPushAdd() throws IOException {
public void testPushAddCollector() throws IOException {
mockServerClient.when(
request()
.withMethod("PUT")
.withMethod("POST")
.withPath("/metrics/job/j")
).respond(response().withStatusCode(202));
pg.pushAdd(gauge, "j");
Expand All @@ -132,7 +132,7 @@ public void testPushAddCollector() throws IOException {
public void testPushAddWithGroupingKey() throws IOException {
mockServerClient.when(
request()
.withMethod("PUT")
.withMethod("POST")
.withPath("/metrics/job/j/l/v")
).respond(response().withStatusCode(202));
pg.pushAdd(registry, "j", groupingKey);
Expand All @@ -142,7 +142,7 @@ public void testPushAddWithGroupingKey() throws IOException {
public void testPushAddCollectorWithGroupingKey() throws IOException {
mockServerClient.when(
request()
.withMethod("PUT")
.withMethod("POST")
.withPath("/metrics/job/j/l/v")
).respond(response().withStatusCode(202));
pg.pushAdd(gauge, "j", groupingKey);
Expand Down Expand Up @@ -174,7 +174,7 @@ public void testDeleteWithGroupingKey() throws IOException {
public void testOldPushWithoutInstance() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j/instance/")
).respond(response().withStatusCode(202));
pg.push(registry, "j", "");
Expand All @@ -184,7 +184,7 @@ public void testOldPushWithoutInstance() throws IOException {
public void testOldPushWithInstance() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j/instance/i")
).respond(response().withStatusCode(202));
pg.push(registry, "j", "i");
Expand All @@ -194,7 +194,7 @@ public void testOldPushWithInstance() throws IOException {
public void testOldNon202ResponseThrows() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j/instance/i")
).respond(response().withStatusCode(500));
pg.push(registry,"j", "i");
Expand All @@ -204,7 +204,7 @@ public void testOldNon202ResponseThrows() throws IOException {
public void testOldPushWithSlashes() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/a%2Fb/instance/c%2Fd")
).respond(response().withStatusCode(202));
pg.push(registry, "a/b", "c/d");
Expand All @@ -214,7 +214,7 @@ public void testOldPushWithSlashes() throws IOException {
public void testOldPushCollector() throws IOException {
mockServerClient.when(
request()
.withMethod("POST")
.withMethod("PUT")
.withPath("/metrics/job/j/instance/i")
).respond(response().withStatusCode(202));
pg.push(gauge, "j", "i");
Expand All @@ -224,7 +224,7 @@ public void testOldPushCollector() throws IOException {
public void testOldPushAdd() throws IOException {
mockServerClient.when(
request()
.withMethod("PUT")
.withMethod("POST")
.withPath("/metrics/job/j/instance/i")
).respond(response().withStatusCode(202));
pg.pushAdd(registry, "j", "i");
Expand All @@ -234,7 +234,7 @@ public void testOldPushAdd() throws IOException {
public void testOldPushAddCollector() throws IOException {
mockServerClient.when(
request()
.withMethod("PUT")
.withMethod("POST")
.withPath("/metrics/job/j/instance/i")
).respond(response().withStatusCode(202));
pg.pushAdd(gauge, "j", "i");
Expand Down