Repository: VictoriaMetrics/VictoriaMetrics
Pull request #868 (2020-10-28 17:34:18)

fixes panic at scrape error body formating,
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/864
regression after body reuse improvements

codecov[bot]: # [Codecov](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868?src=pr&el=h1) Report
> Merging [#868](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868?src=pr&el=desc) into [master](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/commit/bca468bb55f0015c6a5d32cafcb1074f833448fe?el=desc) will **increase** coverage by `0.04%`.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868/graphs/tree.svg?width=650&height=150&src=pr&token=YND8dYVcXn)](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #868      +/-   ##
==========================================
+ Coverage   62.88%   62.92%   +0.04%     
==========================================
  Files         189      189              
  Lines       21532    21531       -1     
==========================================
+ Hits        13540    13549       +9     
+ Misses       6710     6700      -10     
  Partials     1282     1282              
```


| [Impacted Files](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [lib/promscrape/client.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868/diff?src=pr&el=tree#diff-bGliL3Byb21zY3JhcGUvY2xpZW50Lmdv) | `0.00% <0.00%> (ø)` | |
| [lib/storage/partition.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868/diff?src=pr&el=tree#diff-bGliL3N0b3JhZ2UvcGFydGl0aW9uLmdv) | `68.38% <0.00%> (-0.52%)` | :arrow_down: |
| [lib/mergeset/table.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868/diff?src=pr&el=tree#diff-bGliL21lcmdlc2V0L3RhYmxlLmdv) | `65.99% <0.00%> (+0.31%)` | :arrow_up: |
| [app/vmselect/promql/aggr\_incremental.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868/diff?src=pr&el=tree#diff-YXBwL3Ztc2VsZWN0L3Byb21xbC9hZ2dyX2luY3JlbWVudGFsLmdv) | `84.88% <0.00%> (+1.55%)` | :arrow_up: |
| [lib/storage/merge.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868/diff?src=pr&el=tree#diff-bGliL3N0b3JhZ2UvbWVyZ2UuZ28=) | `79.48% <0.00%> (+2.56%)` | :arrow_up: |
| [app/vmalert/remotewrite/remotewrite.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868/diff?src=pr&el=tree#diff-YXBwL3ZtYWxlcnQvcmVtb3Rld3JpdGUvcmVtb3Rld3JpdGUuZ28=) | `58.49% <0.00%> (+3.77%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868?src=pr&el=footer). Last update [bca468b...44690dc](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/868?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e3671e5dc..2829ec957 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,7 @@
 * BUGFIX: vmagent: properly handle OpenStack endpoint ending with `v3.0` such as `https://ostack.example.com:5000/v3.0`
   in the same way as Prometheus does. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/728#issuecomment-709914803
 * BUGFIX: Drop trailing data points for time series with a single raw sample. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/748
-
+* BUGFIX: fix panic in vmbackup when no origin fs is specified. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/856
 
 # [v1.44.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.44.0)
 
diff --git a/app/vmbackup/main.go b/app/vmbackup/main.go
index 49bb72874..bbaa2a77a 100644
--- a/app/vmbackup/main.go
+++ b/app/vmbackup/main.go
@@ -10,6 +10,7 @@ import (
 	"github.com/VictoriaMetrics/VictoriaMetrics/lib/backup/actions"
 	"github.com/VictoriaMetrics/VictoriaMetrics/lib/backup/common"
 	"github.com/VictoriaMetrics/VictoriaMetrics/lib/backup/fslocal"
+	"github.com/VictoriaMetrics/VictoriaMetrics/lib/backup/fsnil"
 	"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
 	"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
 	"github.com/VictoriaMetrics/VictoriaMetrics/lib/envflag"
@@ -146,9 +147,9 @@ func newDstFS() (common.RemoteFS, error) {
 	return fs, nil
 }
 
-func newOriginFS() (common.RemoteFS, error) {
+func newOriginFS() (common.OriginFS, error) {
 	if len(*origin) == 0 {
-		return nil, nil
+		return &fsnil.FS{}, nil
 	}
 	fs, err := actions.NewRemoteFS(*origin)
 	if err != nil {
diff --git a/dashboards/victoriametrics.json b/dashboards/victoriametrics.json
index 7cd4f18d5..095fab4f3 100644
--- a/dashboards/victoriametrics.json
+++ b/dashboards/victoriametrics.json
@@ -56,7 +56,7 @@
   "gnetId": 10229,
   "graphTooltip": 0,
   "id": null,
-  "iteration": 1599034965731,
+  "iteration": 1603307754894,
   "links": [
     {
       "icon": "doc",
@@ -925,7 +925,7 @@
       "dashLength": 10,
       "dashes": false,
       "datasource": "$ds",
-      "description": "Shows how many ongoing insertions are taking place.\n* `max` - equal to number of CPU * 2\n* `current` - current number of goroutines busy with inserting rows into storage\n\nWhen `current` hits `max` constantly, it means storage is overloaded and require more CPU.",
+      "description": "Shows how many ongoing insertions (not API /write calls) on disk are taking place, where:\n* `max` - equal to number of CPUs;\n* `current` - current number of goroutines busy with inserting rows into underlying storage.\n\nEvery successful API /write call results into flush on disk. However, these two actions are separated and controlled via different concurrency limiters. The `max` on this panel can't be changed and always equal to number of CPUs. \n\nWhen `current` hits `max` constantly, it means storage is overloaded and requires more CPU.\n\n",
       "fieldConfig": {
         "defaults": {
           "custom": {},
@@ -979,6 +979,7 @@
         {
           "expr": "sum(vm_concurrent_addrows_capacity{job=\"$job\", instance=\"$instance\"})",
           "format": "time_series",
+          "interval": "",
           "intervalFactor": 1,
           "legendFormat": "max",
           "refId": "A"
@@ -995,7 +996,7 @@
       "timeFrom": null,
       "timeRegions": [],
       "timeShift": null,
-      "title": "Concurrent inserts ($instance)",
+      "title": "Concurrent flushes on disk ($instance)",
       "tooltip": {
         "shared": true,
         "sort": 2,
@@ -3293,4 +3294,4 @@
   "title": "VictoriaMetrics",
   "uid": "wNf0q_kZk",
   "version": 1
-}
+}
\ No newline at end of file
diff --git a/deployment/docker/docker-compose.yml b/deployment/docker/docker-compose.yml
index 0f856b515..545e9f689 100644
--- a/deployment/docker/docker-compose.yml
+++ b/deployment/docker/docker-compose.yml
@@ -21,7 +21,9 @@ services:
     image: victoriametrics/victoria-metrics
     ports:
       - 8428:8428
+      - 8428:8428/udp
       - 2003:2003
+      - 2003:2003/udp
       - 4242:4242
     volumes:
       - vmdata:/storage
diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go
index e7f4d0f5e..b607c0a24 100644
--- a/lib/promscrape/client.go
+++ b/lib/promscrape/client.go
@@ -131,7 +131,6 @@ func (c *client) ReadData(dst []byte) ([]byte, error) {
 		}
 		return dst, fmt.Errorf("error when scraping %q: %w", c.scrapeURL, err)
 	}
-	dstLen := len(dst)
 	if ce := resp.Header.Peek("Content-Encoding"); string(ce) == "gzip" {
 		var err error
 		var src []byte
@@ -154,7 +153,7 @@ func (c *client) ReadData(dst []byte) ([]byte, error) {
 	if statusCode != fasthttp.StatusOK {
 		metrics.GetOrCreateCounter(fmt.Sprintf(`vm_promscrape_scrapes_total{status_code="%d"}`, statusCode)).Inc()
 		return dst, fmt.Errorf("unexpected status code returned when scraping %q: %d; expecting %d; response body: %q",
-			c.scrapeURL, statusCode, fasthttp.StatusOK, dst[dstLen:])
+			c.scrapeURL, statusCode, fasthttp.StatusOK, dst)
 	}
 	scrapesOK.Inc()
 	fasthttp.ReleaseResponse(resp)
diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go
index 9595e7833..c174414ce 100644
--- a/lib/promscrape/config.go
+++ b/lib/promscrape/config.go
@@ -663,6 +663,9 @@ func appendScrapeWork(dst []ScrapeWork, swc *scrapeWorkConfig, target string, ex
 	if metricsPathRelabeled == "" {
 		metricsPathRelabeled = "/metrics"
 	}
+	if !strings.HasPrefix(metricsPathRelabeled, "/") {
+		metricsPathRelabeled = "/" + metricsPathRelabeled
+	}
 	paramsRelabeled := getParamsFromLabels(labels, swc.params)
 	optionalQuestion := "?"
 	if len(paramsRelabeled) == 0 || strings.Contains(metricsPathRelabeled, "?") {


Test patch:
diff --git a/lib/promscrape/config_test.go b/lib/promscrape/config_test.go
index e84567b40..d2834c1e7 100644
--- a/lib/promscrape/config_test.go
+++ b/lib/promscrape/config_test.go
@@ -1331,6 +1331,45 @@ scrape_configs:
 			jobNameOriginal:    "snmp",
 		},
 	})
+	f(`
+scrape_configs:
+- job_name: path wo slash
+  static_configs: 
+  - targets: ["foo.bar:1234"]
+  relabel_configs:
+  - replacement: metricspath
+    target_label: __metrics_path__
+`, []ScrapeWork{
+		{
+			ScrapeURL:      "http://foo.bar:1234/metricspath",
+			ScrapeInterval: defaultScrapeInterval,
+			ScrapeTimeout:  defaultScrapeTimeout,
+			Labels: []prompbmarshal.Label{
+				{
+					Name:  "__address__",
+					Value: "foo.bar:1234",
+				},
+				{
+					Name:  "__metrics_path__",
+					Value: "metricspath",
+				},
+				{
+					Name:  "__scheme__",
+					Value: "http",
+				},
+				{
+					Name:  "instance",
+					Value: "foo.bar:1234",
+				},
+				{
+					Name:  "job",
+					Value: "path wo slash",
+				},
+			},
+			jobNameOriginal: "path wo slash",
+			AuthConfig:      &promauth.Config{},
+		},
+	})
 }
 
 var defaultRegexForRelabelConfig = regexp.MustCompile("^(.*)$")