Skip to content

Commit

Permalink
Merge pull request #69 from grafana/rename-river-tags
Browse files Browse the repository at this point in the history
Rename river struct tags to alloy
  • Loading branch information
rfratto authored Mar 25, 2024
2 parents eabc6a6 + ae38d8d commit 3ab9c79
Show file tree
Hide file tree
Showing 254 changed files with 2,426 additions and 2,426 deletions.
30 changes: 15 additions & 15 deletions internal/cmd/agentlint/internal/syntaxtags/syntaxtags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ var Analyzer = &analysis.Analyzer{
var noLintRegex = regexp.MustCompile(`//\s*nolint:(\S+)`)

var (
syntaxTagRegex = regexp.MustCompile(`river:"([^"]*)"`)
syntaxTagRegex = regexp.MustCompile(`alloy:"([^"]*)"`)
jsonTagRegex = regexp.MustCompile(`json:"([^"]*)"`)
yamlTagRegex = regexp.MustCompile(`yaml:"([^"]*)"`)
)

// Rules for river tag linting:
// Rules for alloy tag linting:
//
// - No river tags on anonymous fields.
// - No river tags on unexported fields.
// - No empty tags (river:"").
// - Tags must have options (river:"NAME,OPTIONS").
// - No alloy tags on anonymous fields.
// - No alloy tags on unexported fields.
// - No empty tags (alloy:"").
// - Tags must have options (alloy:"NAME,OPTIONS").
// - Options must be one of the following:
// - attr
// - attr,optional
Expand Down Expand Up @@ -79,7 +79,7 @@ func run(p *analysis.Pass) (interface{}, error) {

matches := syntaxTagRegex.FindAllStringSubmatch(s.Tag(i), -1)
if len(matches) == 0 && hasSyntaxTags {
// If this struct has River tags, but this field only has json/yaml
// If this struct has alloy tags, but this field only has json/yaml
// tags, emit an error.
jsonMatches := jsonTagRegex.FindAllStringSubmatch(s.Tag(i), -1)
yamlMatches := yamlTagRegex.FindAllStringSubmatch(s.Tag(i), -1)
Expand All @@ -88,7 +88,7 @@ func run(p *analysis.Pass) (interface{}, error) {
p.Report(analysis.Diagnostic{
Pos: field.Pos(),
Category: "syntaxtags",
Message: "field has yaml or json tags, but no river tags",
Message: "field has yaml or json tags, but no alloy tags",
})
}

Expand All @@ -99,7 +99,7 @@ func run(p *analysis.Pass) (interface{}, error) {
p.Report(analysis.Diagnostic{
Pos: field.Pos(),
Category: "syntaxtags",
Message: "field should not have more than one river tag",
Message: "field should not have more than one alloy tag",
})
}

Expand All @@ -108,22 +108,22 @@ func run(p *analysis.Pass) (interface{}, error) {
p.Report(analysis.Diagnostic{
Pos: field.Pos(),
Category: "syntaxtags",
Message: "river tags may not be given to anonymous fields",
Message: "alloy tags may not be given to anonymous fields",
})
}
if !field.Exported() {
p.Report(analysis.Diagnostic{
Pos: field.Pos(),
Category: "syntaxtags",
Message: "river tags may only be given to exported fields",
Message: "alloy tags may only be given to exported fields",
})
}
if len(nodeField.Names) > 1 {
// Report "a, b, c int `river:"name,attr"`" as invalid usage.
// Report "a, b, c int `alloy:"name,attr"`" as invalid usage.
p.Report(analysis.Diagnostic{
Pos: field.Pos(),
Category: "syntaxtags",
Message: "river tags should not be inserted on field names separated by commas",
Message: "alloy tags should not be inserted on field names separated by commas",
})
}

Expand Down Expand Up @@ -218,13 +218,13 @@ type structInfo struct {

func lintSyntaxTag(ty *types.Var, tag string) (diagnostics []string) {
if tag == "" {
diagnostics = append(diagnostics, "river tag should not be empty")
diagnostics = append(diagnostics, "alloy tag should not be empty")
return
}

parts := strings.SplitN(tag, ",", 2)
if len(parts) != 2 {
diagnostics = append(diagnostics, "river tag is missing options")
diagnostics = append(diagnostics, "alloy tag is missing options")
return
}

Expand Down
10 changes: 5 additions & 5 deletions internal/component/common/config/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
// LabelSelector defines a selector to check to see if a set of Kubernetes
// labels matches a selector.
type LabelSelector struct {
MatchLabels map[string]string `river:"match_labels,attr,optional"`
MatchExpressions []MatchExpression `river:"match_expression,block,optional"`
MatchLabels map[string]string `alloy:"match_labels,attr,optional"`
MatchExpressions []MatchExpression `alloy:"match_expression,block,optional"`
}

// BuildSelector builds a [labels.Selector] from a Flow LabelSelector.
Expand All @@ -32,9 +32,9 @@ func (ls *LabelSelector) BuildSelector() (labels.Selector, error) {
// MatchExpression defines an expression matcher to check to see if some key
// from a Kubernetes resource matches a selector.
type MatchExpression struct {
Key string `river:"key,attr"`
Operator string `river:"operator,attr"`
Values []string `river:"values,attr,optional"`
Key string `alloy:"key,attr"`
Operator string `alloy:"operator,attr"`
Values []string `alloy:"values,attr,optional"`
}

func (me *MatchExpression) buildExpression() metav1.LabelSelectorRequirement {
Expand Down
74 changes: 37 additions & 37 deletions internal/component/common/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const bearerAuth string = "Bearer"

// HTTPClientConfig mirrors config.HTTPClientConfig
type HTTPClientConfig struct {
BasicAuth *BasicAuth `river:"basic_auth,block,optional"`
Authorization *Authorization `river:"authorization,block,optional"`
OAuth2 *OAuth2Config `river:"oauth2,block,optional"`
BearerToken alloytypes.Secret `river:"bearer_token,attr,optional"`
BearerTokenFile string `river:"bearer_token_file,attr,optional"`
ProxyConfig *ProxyConfig `river:",squash"`
TLSConfig TLSConfig `river:"tls_config,block,optional"`
FollowRedirects bool `river:"follow_redirects,attr,optional"`
EnableHTTP2 bool `river:"enable_http2,attr,optional"`
BasicAuth *BasicAuth `alloy:"basic_auth,block,optional"`
Authorization *Authorization `alloy:"authorization,block,optional"`
OAuth2 *OAuth2Config `alloy:"oauth2,block,optional"`
BearerToken alloytypes.Secret `alloy:"bearer_token,attr,optional"`
BearerTokenFile string `alloy:"bearer_token_file,attr,optional"`
ProxyConfig *ProxyConfig `alloy:",squash"`
TLSConfig TLSConfig `alloy:"tls_config,block,optional"`
FollowRedirects bool `alloy:"follow_redirects,attr,optional"`
EnableHTTP2 bool `alloy:"enable_http2,attr,optional"`
}

// SetToDefault implements the river.Defaulter
Expand Down Expand Up @@ -109,9 +109,9 @@ var DefaultHTTPClientConfig = HTTPClientConfig{

// BasicAuth configures Basic HTTP authentication credentials.
type BasicAuth struct {
Username string `river:"username,attr,optional"`
Password alloytypes.Secret `river:"password,attr,optional"`
PasswordFile string `river:"password_file,attr,optional"`
Username string `alloy:"username,attr,optional"`
Password alloytypes.Secret `alloy:"password,attr,optional"`
PasswordFile string `alloy:"password_file,attr,optional"`
}

// Convert converts our type to the native prometheus type
Expand Down Expand Up @@ -139,10 +139,10 @@ func (b *BasicAuth) Validate() error {
}

type ProxyConfig struct {
ProxyURL URL `river:"proxy_url,attr,optional"`
NoProxy string `river:"no_proxy,attr,optional"`
ProxyFromEnvironment bool `river:"proxy_from_environment,attr,optional"`
ProxyConnectHeader Header `river:",squash"`
ProxyURL URL `alloy:"proxy_url,attr,optional"`
NoProxy string `alloy:"no_proxy,attr,optional"`
ProxyFromEnvironment bool `alloy:"proxy_from_environment,attr,optional"`
ProxyConnectHeader Header `alloy:",squash"`
}

func (p *ProxyConfig) Convert() config.ProxyConfig {
Expand Down Expand Up @@ -215,7 +215,7 @@ func (u *URL) Convert() config.URL {
}

type Header struct {
Header map[string][]alloytypes.Secret `river:"proxy_connect_header,attr,optional"`
Header map[string][]alloytypes.Secret `alloy:"proxy_connect_header,attr,optional"`
}

func (h *Header) Convert() config.Header {
Expand All @@ -238,9 +238,9 @@ func (h *Header) Convert() config.Header {

// Authorization sets up HTTP authorization credentials.
type Authorization struct {
Type string `river:"type,attr,optional"`
Credentials alloytypes.Secret `river:"credentials,attr,optional"`
CredentialsFile string `river:"credentials_file,attr,optional"`
Type string `alloy:"type,attr,optional"`
Credentials alloytypes.Secret `alloy:"credentials,attr,optional"`
CredentialsFile string `alloy:"credentials_file,attr,optional"`
}

// Convert converts our type to the native prometheus type
Expand Down Expand Up @@ -301,15 +301,15 @@ func (tv *TLSVersion) UnmarshalText(text []byte) error {

// TLSConfig sets up options for TLS connections.
type TLSConfig struct {
CA string `river:"ca_pem,attr,optional"`
CAFile string `river:"ca_file,attr,optional"`
Cert string `river:"cert_pem,attr,optional"`
CertFile string `river:"cert_file,attr,optional"`
Key alloytypes.Secret `river:"key_pem,attr,optional"`
KeyFile string `river:"key_file,attr,optional"`
ServerName string `river:"server_name,attr,optional"`
InsecureSkipVerify bool `river:"insecure_skip_verify,attr,optional"`
MinVersion TLSVersion `river:"min_version,attr,optional"`
CA string `alloy:"ca_pem,attr,optional"`
CAFile string `alloy:"ca_file,attr,optional"`
Cert string `alloy:"cert_pem,attr,optional"`
CertFile string `alloy:"cert_file,attr,optional"`
Key alloytypes.Secret `alloy:"key_pem,attr,optional"`
KeyFile string `alloy:"key_file,attr,optional"`
ServerName string `alloy:"server_name,attr,optional"`
InsecureSkipVerify bool `alloy:"insecure_skip_verify,attr,optional"`
MinVersion TLSVersion `alloy:"min_version,attr,optional"`
}

// Convert converts our type to the native prometheus type
Expand Down Expand Up @@ -358,14 +358,14 @@ func (t *TLSConfig) Validate() error {

// OAuth2Config sets up the OAuth2 client.
type OAuth2Config struct {
ClientID string `river:"client_id,attr,optional"`
ClientSecret alloytypes.Secret `river:"client_secret,attr,optional"`
ClientSecretFile string `river:"client_secret_file,attr,optional"`
Scopes []string `river:"scopes,attr,optional"`
TokenURL string `river:"token_url,attr,optional"`
EndpointParams map[string]string `river:"endpoint_params,attr,optional"`
ProxyConfig *ProxyConfig `river:",squash"`
TLSConfig *TLSConfig `river:"tls_config,block,optional"`
ClientID string `alloy:"client_id,attr,optional"`
ClientSecret alloytypes.Secret `alloy:"client_secret,attr,optional"`
ClientSecretFile string `alloy:"client_secret_file,attr,optional"`
Scopes []string `alloy:"scopes,attr,optional"`
TokenURL string `alloy:"token_url,attr,optional"`
EndpointParams map[string]string `alloy:"endpoint_params,attr,optional"`
ProxyConfig *ProxyConfig `alloy:",squash"`
TLSConfig *TLSConfig `alloy:"tls_config,block,optional"`
}

// Convert converts our type to the native prometheus type
Expand Down
6 changes: 3 additions & 3 deletions internal/component/common/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

// ClientArguments controls how to connect to a Kubernetes cluster.
type ClientArguments struct {
APIServer commoncfg.URL `river:"api_server,attr,optional"`
KubeConfig string `river:"kubeconfig_file,attr,optional"`
HTTPClientConfig commoncfg.HTTPClientConfig `river:",squash"`
APIServer commoncfg.URL `alloy:"api_server,attr,optional"`
KubeConfig string `alloy:"kubeconfig_file,attr,optional"`
HTTPClientConfig commoncfg.HTTPClientConfig `alloy:",squash"`
}

// DefaultClientArguments holds default values for Arguments.
Expand Down
10 changes: 5 additions & 5 deletions internal/component/common/kubernetes/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
)

type LabelSelector struct {
MatchLabels map[string]string `river:"match_labels,attr,optional"`
MatchExpressions []MatchExpression `river:"match_expression,block,optional"`
MatchLabels map[string]string `alloy:"match_labels,attr,optional"`
MatchExpressions []MatchExpression `alloy:"match_expression,block,optional"`
}

type MatchExpression struct {
Key string `river:"key,attr"`
Operator string `river:"operator,attr"`
Values []string `river:"values,attr,optional"`
Key string `alloy:"key,attr"`
Operator string `alloy:"operator,attr"`
Values []string `alloy:"values,attr,optional"`
}

func ConvertSelectorToListOptions(selector LabelSelector) (labels.Selector, error) {
Expand Down
36 changes: 18 additions & 18 deletions internal/component/common/net/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ const (
type ServerConfig struct {
// HTTP configures the HTTP dskit. Note that despite the block being present or not,
// the dskit is always started.
HTTP *HTTPConfig `river:"http,block,optional"`
HTTP *HTTPConfig `alloy:"http,block,optional"`

// GRPC configures the gRPC dskit. Note that despite the block being present or not,
// the dskit is always started.
GRPC *GRPCConfig `river:"grpc,block,optional"`
GRPC *GRPCConfig `alloy:"grpc,block,optional"`

// GracefulShutdownTimeout configures a timeout to gracefully shut down the server.
GracefulShutdownTimeout time.Duration `river:"graceful_shutdown_timeout,attr,optional"`
GracefulShutdownTimeout time.Duration `alloy:"graceful_shutdown_timeout,attr,optional"`
}

// HTTPConfig configures the HTTP dskit started by dskit.Server.
type HTTPConfig struct {
ListenAddress string `river:"listen_address,attr,optional"`
ListenPort int `river:"listen_port,attr,optional"`
ConnLimit int `river:"conn_limit,attr,optional"`
ServerReadTimeout time.Duration `river:"server_read_timeout,attr,optional"`
ServerWriteTimeout time.Duration `river:"server_write_timeout,attr,optional"`
ServerIdleTimeout time.Duration `river:"server_idle_timeout,attr,optional"`
ListenAddress string `alloy:"listen_address,attr,optional"`
ListenPort int `alloy:"listen_port,attr,optional"`
ConnLimit int `alloy:"conn_limit,attr,optional"`
ServerReadTimeout time.Duration `alloy:"server_read_timeout,attr,optional"`
ServerWriteTimeout time.Duration `alloy:"server_write_timeout,attr,optional"`
ServerIdleTimeout time.Duration `alloy:"server_idle_timeout,attr,optional"`
}

// Into applies the configs from HTTPConfig into a dskit.Into.
Expand All @@ -58,15 +58,15 @@ func (h *HTTPConfig) Into(c *dskit.Config) {

// GRPCConfig configures the gRPC dskit started by dskit.Server.
type GRPCConfig struct {
ListenAddress string `river:"listen_address,attr,optional"`
ListenPort int `river:"listen_port,attr,optional"`
ConnLimit int `river:"conn_limit,attr,optional"`
MaxConnectionAge time.Duration `river:"max_connection_age,attr,optional"`
MaxConnectionAgeGrace time.Duration `river:"max_connection_age_grace,attr,optional"`
MaxConnectionIdle time.Duration `river:"max_connection_idle,attr,optional"`
ServerMaxRecvMsg int `river:"server_max_recv_msg_size,attr,optional"`
ServerMaxSendMsg int `river:"server_max_send_msg_size,attr,optional"`
ServerMaxConcurrentStreams uint `river:"server_max_concurrent_streams,attr,optional"`
ListenAddress string `alloy:"listen_address,attr,optional"`
ListenPort int `alloy:"listen_port,attr,optional"`
ConnLimit int `alloy:"conn_limit,attr,optional"`
MaxConnectionAge time.Duration `alloy:"max_connection_age,attr,optional"`
MaxConnectionAgeGrace time.Duration `alloy:"max_connection_age_grace,attr,optional"`
MaxConnectionIdle time.Duration `alloy:"max_connection_idle,attr,optional"`
ServerMaxRecvMsg int `alloy:"server_max_recv_msg_size,attr,optional"`
ServerMaxSendMsg int `alloy:"server_max_send_msg_size,attr,optional"`
ServerMaxConcurrentStreams uint `alloy:"server_max_concurrent_streams,attr,optional"`
}

// Into applies the configs from GRPCConfig into a dskit.Into.
Expand Down
2 changes: 1 addition & 1 deletion internal/component/common/net/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// testArguments mimics an arguments type used by a component, applying the defaults to ServerConfig
// from it's UnmarshalRiver implementation, since the block is squashed.
type testArguments struct {
Server *ServerConfig `river:",squash"`
Server *ServerConfig `alloy:",squash"`
}

func (t *testArguments) UnmarshalRiver(f func(v interface{}) error) error {
Expand Down
14 changes: 7 additions & 7 deletions internal/component/common/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ func (re Regexp) String() string {

// Config describes a relabelling step to be applied on a target.
type Config struct {
SourceLabels []string `river:"source_labels,attr,optional"`
Separator string `river:"separator,attr,optional"`
Regex Regexp `river:"regex,attr,optional"`
Modulus uint64 `river:"modulus,attr,optional"`
TargetLabel string `river:"target_label,attr,optional"`
Replacement string `river:"replacement,attr,optional"`
Action Action `river:"action,attr,optional"`
SourceLabels []string `alloy:"source_labels,attr,optional"`
Separator string `alloy:"separator,attr,optional"`
Regex Regexp `alloy:"regex,attr,optional"`
Modulus uint64 `alloy:"modulus,attr,optional"`
TargetLabel string `alloy:"target_label,attr,optional"`
Replacement string `alloy:"replacement,attr,optional"`
Action Action `alloy:"action,attr,optional"`
}

// DefaultRelabelConfig sets the default values of fields when decoding a RelabelConfig block.
Expand Down
6 changes: 3 additions & 3 deletions internal/component/component_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type HealthComponent interface {
// River.
type Health struct {
// The specific health value.
Health HealthType `river:"state,attr"`
Health HealthType `alloy:"state,attr"`

// An optional message to describe the health; useful to say why a component
// is unhealthy.
Message string `river:"message,attr,optional"`
Message string `alloy:"message,attr,optional"`

// An optional time to indicate when the component last modified something
// which updated its health.
UpdateTime time.Time `river:"update_time,attr,optional"`
UpdateTime time.Time `alloy:"update_time,attr,optional"`
}

// HealthType holds the health value for a component.
Expand Down
Loading

0 comments on commit 3ab9c79

Please sign in to comment.