Move string functionality to pkg/strutil

This commit is contained in:
Fabian Reinartz 2015-05-28 21:33:48 +02:00
parent f45a5cab60
commit dbc0d30e3e
9 changed files with 28 additions and 28 deletions

View File

@ -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
}

View File

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package utility
package strutil
import (
"fmt"

View File

@ -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
}

View File

@ -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(),
)

View File

@ -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)
}

View File

@ -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 <a href="%s">%s</a> IF <a href="%s">%s</a> 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))
}

View File

@ -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)

View File

@ -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(
`<a href="%s">%s</a>%s = <a href="%s">%s</a>`,
pathPrefix+utility.GraphLinkForExpression(rule.name),
pathPrefix+strutil.GraphLinkForExpression(rule.name),
rule.name,
rule.labels,
pathPrefix+utility.GraphLinkForExpression(ruleExpr),
pathPrefix+strutil.GraphLinkForExpression(ruleExpr),
ruleExpr))
}

View File

@ -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)