diff --git a/config/config.go b/config/config.go
index 273377ab6..3dcc99f0a 100644
--- a/config/config.go
+++ b/config/config.go
@@ -12,7 +12,7 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
- "github.com/prometheus/prometheus/utility"
+ "github.com/prometheus/prometheus/pkg/strutil"
)
var (
@@ -479,7 +479,7 @@ func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal(&s); err != nil {
return err
}
- dur, err := utility.StringToDuration(s)
+ dur, err := strutil.StringToDuration(s)
if err != nil {
return err
}
@@ -489,5 +489,5 @@ func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
// MarshalYAML implements the yaml.Marshaler interface.
func (d Duration) MarshalYAML() (interface{}, error) {
- return utility.DurationToString(time.Duration(d)), nil
+ return strutil.DurationToString(time.Duration(d)), nil
}
diff --git a/utility/strconv.go b/pkg/strutil/strconv.go
similarity index 99%
rename from utility/strconv.go
rename to pkg/strutil/strconv.go
index 0ebfa1587..99b1e48a5 100644
--- a/utility/strconv.go
+++ b/pkg/strutil/strconv.go
@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package utility
+package strutil
import (
"fmt"
diff --git a/promql/parse.go b/promql/parse.go
index 653535162..e0aeff6a0 100644
--- a/promql/parse.go
+++ b/promql/parse.go
@@ -21,8 +21,8 @@ import (
"time"
clientmodel "github.com/prometheus/client_golang/model"
+ "github.com/prometheus/prometheus/pkg/strutil"
"github.com/prometheus/prometheus/storage/metric"
- "github.com/prometheus/prometheus/utility"
)
type parser struct {
@@ -982,7 +982,7 @@ func (p *parser) checkType(node Node) (typ ExprType) {
}
func parseDuration(ds string) (time.Duration, error) {
- dur, err := utility.StringToDuration(ds)
+ dur, err := strutil.StringToDuration(ds)
if err != nil {
return 0, err
}
diff --git a/promql/printer.go b/promql/printer.go
index 3e4f29b77..df72c47ef 100644
--- a/promql/printer.go
+++ b/promql/printer.go
@@ -21,8 +21,8 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
+ "github.com/prometheus/prometheus/pkg/strutil"
"github.com/prometheus/prometheus/storage/metric"
- "github.com/prometheus/prometheus/utility"
)
func (matrix Matrix) String() string {
@@ -145,7 +145,7 @@ func (node *AlertStmt) String() string {
s := fmt.Sprintf("ALERT %s", node.Name)
s += fmt.Sprintf("\n\tIF %s", node.Expr)
if node.Duration > 0 {
- s += fmt.Sprintf("\n\tFOR %s", utility.DurationToString(node.Duration))
+ s += fmt.Sprintf("\n\tFOR %s", strutil.DurationToString(node.Duration))
}
if len(node.Labels) > 0 {
s += fmt.Sprintf("\n\tWITH %s", node.Labels)
@@ -207,7 +207,7 @@ func (node *MatrixSelector) String() string {
Name: node.Name,
LabelMatchers: node.LabelMatchers,
}
- return fmt.Sprintf("%s[%s]", vecSelector.String(), utility.DurationToString(node.Range))
+ return fmt.Sprintf("%s[%s]", vecSelector.String(), strutil.DurationToString(node.Range))
}
func (node *NumberLiteral) String() string {
@@ -260,7 +260,7 @@ func (node *AlertStmt) DotGraph() string {
%#p -> %x;
%s
}`,
- node, node.Name, utility.DurationToString(node.Duration),
+ node, node.Name, strutil.DurationToString(node.Duration),
node, reflect.ValueOf(node.Expr).Pointer(),
node.Expr.DotGraph(),
)
diff --git a/promql/test.go b/promql/test.go
index 3de3066ac..d0389065b 100644
--- a/promql/test.go
+++ b/promql/test.go
@@ -24,12 +24,11 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
+ "github.com/prometheus/prometheus/pkg/strutil"
+ "github.com/prometheus/prometheus/pkg/testutil"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/storage/metric"
- "github.com/prometheus/prometheus/utility"
-
- "github.com/prometheus/prometheus/pkg/testutil"
)
var (
@@ -91,7 +90,7 @@ func (t *Test) parseLoad(lines []string, i int) (int, *loadCmd, error) {
}
parts := patLoad.FindStringSubmatch(lines[i])
- gap, err := utility.StringToDuration(parts[1])
+ gap, err := strutil.StringToDuration(parts[1])
if err != nil {
return i, nil, raise(i, "invalid step definition %q: %s", parts[1], err)
}
@@ -132,7 +131,7 @@ func (t *Test) parseEval(lines []string, i int) (int, *evalCmd, error) {
return i, nil, perr
}
- offset, err := utility.StringToDuration(at)
+ offset, err := strutil.StringToDuration(at)
if err != nil {
return i, nil, raise(i, "invalid step definition %q: %s", parts[1], err)
}
diff --git a/rules/alerting.go b/rules/alerting.go
index 4e3d94b79..e8313d6f9 100644
--- a/rules/alerting.go
+++ b/rules/alerting.go
@@ -22,6 +22,7 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
+ "github.com/prometheus/prometheus/pkg/strutil"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/utility"
)
@@ -201,7 +202,7 @@ func (rule *AlertingRule) DotGraph() string {
%#p -> %x;
%s
}`,
- &rule, rule.name, utility.DurationToString(rule.holdDuration),
+ &rule, rule.name, strutil.DurationToString(rule.holdDuration),
&rule, reflect.ValueOf(rule.Vector).Pointer(),
rule.Vector.DotGraph(),
)
@@ -209,7 +210,7 @@ func (rule *AlertingRule) DotGraph() string {
}
func (rule *AlertingRule) String() string {
- return fmt.Sprintf("ALERT %s IF %s FOR %s WITH %s", rule.name, rule.Vector, utility.DurationToString(rule.holdDuration), rule.Labels)
+ return fmt.Sprintf("ALERT %s IF %s FOR %s WITH %s", rule.name, rule.Vector, strutil.DurationToString(rule.holdDuration), rule.Labels)
}
// HTMLSnippet returns an HTML snippet representing this alerting rule.
@@ -220,11 +221,11 @@ func (rule *AlertingRule) HTMLSnippet(pathPrefix string) template.HTML {
}
return template.HTML(fmt.Sprintf(
`ALERT %s IF %s FOR %s WITH %s`,
- pathPrefix+utility.GraphLinkForExpression(alertMetric.String()),
+ pathPrefix+strutil.GraphLinkForExpression(alertMetric.String()),
rule.name,
- pathPrefix+utility.GraphLinkForExpression(rule.Vector.String()),
+ pathPrefix+strutil.GraphLinkForExpression(rule.Vector.String()),
rule.Vector,
- utility.DurationToString(rule.holdDuration),
+ strutil.DurationToString(rule.holdDuration),
rule.Labels))
}
diff --git a/rules/manager.go b/rules/manager.go
index e52f72e32..a197d07f2 100644
--- a/rules/manager.go
+++ b/rules/manager.go
@@ -28,10 +28,10 @@ import (
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/notification"
+ "github.com/prometheus/prometheus/pkg/strutil"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/template"
- "github.com/prometheus/prometheus/utility"
)
// Constants for instrumentation.
@@ -213,7 +213,7 @@ func (m *Manager) queueAlertNotifications(rule *AlertingRule, timestamp clientmo
Value: aa.Value,
ActiveSince: aa.ActiveSince.Time(),
RuleString: rule.String(),
- GeneratorURL: m.prometheusURL + strings.TrimLeft(utility.GraphLinkForExpression(rule.Vector.String()), "/"),
+ GeneratorURL: m.prometheusURL + strings.TrimLeft(strutil.GraphLinkForExpression(rule.Vector.String()), "/"),
})
}
m.notificationHandler.SubmitReqs(notifications)
diff --git a/rules/recording.go b/rules/recording.go
index ea4be24d6..272463872 100644
--- a/rules/recording.go
+++ b/rules/recording.go
@@ -20,8 +20,8 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
+ "github.com/prometheus/prometheus/pkg/strutil"
"github.com/prometheus/prometheus/promql"
- "github.com/prometheus/prometheus/utility"
)
// A RecordingRule records its vector expression into new timeseries.
@@ -89,9 +89,9 @@ func (rule RecordingRule) HTMLSnippet(pathPrefix string) template.HTML {
ruleExpr := rule.vector.String()
return template.HTML(fmt.Sprintf(
`%s%s = %s`,
- pathPrefix+utility.GraphLinkForExpression(rule.name),
+ pathPrefix+strutil.GraphLinkForExpression(rule.name),
rule.name,
rule.labels,
- pathPrefix+utility.GraphLinkForExpression(ruleExpr),
+ pathPrefix+strutil.GraphLinkForExpression(ruleExpr),
ruleExpr))
}
diff --git a/template/template.go b/template/template.go
index cb158d609..d310f0de0 100644
--- a/template/template.go
+++ b/template/template.go
@@ -27,8 +27,8 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
+ "github.com/prometheus/prometheus/pkg/strutil"
"github.com/prometheus/prometheus/promql"
- "github.com/prometheus/prometheus/utility"
)
// A version of vector that's easier to use from templates.
@@ -152,8 +152,8 @@ func NewTemplateExpander(text string, name string, data interface{}, timestamp c
},
"match": regexp.MatchString,
"title": strings.Title,
- "graphLink": utility.GraphLinkForExpression,
- "tableLink": utility.TableLinkForExpression,
+ "graphLink": strutil.GraphLinkForExpression,
+ "tableLink": strutil.TableLinkForExpression,
"sortByLabel": func(label string, v queryResult) queryResult {
sorter := queryResultByLabelSorter{v[:], label}
sort.Stable(sorter)