Skip to content

Commit

Permalink
Actually use tls alloy and not yaml. (#2461)
Browse files Browse the repository at this point in the history
* Actually use tls alloy and not yaml.

* remove bad test
  • Loading branch information
mattdurham authored Jan 21, 2025
1 parent 1136b7f commit 419e997
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ Name | Type | Description | Default

### tls_config block

{{< docs/shared lookup="reference/components/tls-config-block.md" source="alloy" version="<ALLOY_VERSION>" >}}
Name | Type | Description | Default | Required
-----------------------|----------|----------------------------------------------------------|---------|---------
`ca_pem` | `string` | CA PEM-encoded text to validate the server with. | | no
`cert_pem` | `string` | Certificate PEM-encoded text for client authentication. | | no
`insecure_skip_verify` | `bool` | Disables validation of the server certificate. | | no
`key_pem` | `secret` | Key PEM-encoded text for client authentication. | | no

## Exported fields

Expand Down
13 changes: 8 additions & 5 deletions internal/component/prometheus/write/queue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/grafana/alloy/syntax/alloytypes"
"github.com/grafana/walqueue/types"
common "github.com/prometheus/common/config"
"github.com/prometheus/common/version"
"github.com/prometheus/prometheus/storage"
)
Expand Down Expand Up @@ -67,9 +66,6 @@ func (r *Arguments) Validate() error {
if conn.FlushInterval < 1*time.Second {
return fmt.Errorf("flush_interval must be greater or equal to 1s, the internal timers resolution is 1s")
}
if conn.BasicAuth != nil && conn.TLSConfig != nil {
return fmt.Errorf("endpoint %s cannot have both BasicAuth and TLSConfig set", conn.Name)
}
}

return nil
Expand All @@ -93,10 +89,17 @@ type EndpointConfig struct {
// How many concurrent queues to have.
Parallelism uint `alloy:"parallelism,attr,optional"`
ExternalLabels map[string]string `alloy:"external_labels,attr,optional"`
TLSConfig *common.TLSConfig `alloy:"tls_config,block,optional"`
TLSConfig *TLSConfig `alloy:"tls_config,block,optional"`
RoundRobin bool `alloy:"enable_round_robin,attr,optional"`
}

type TLSConfig struct {
CA string `alloy:"ca_pem,attr,optional"`
Cert string `alloy:"cert_pem,attr,optional"`
Key alloytypes.Secret `alloy:"key_pem,attr,optional"`
InsecureSkipVerify bool `alloy:"insecure_skip_verify,attr,optional"`
}

var UserAgent = fmt.Sprintf("Alloy/%s", version.Version)

func (cc EndpointConfig) ToNativeType() types.ConnectionConfig {
Expand Down
30 changes: 18 additions & 12 deletions internal/component/prometheus/write/queue/types_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package queue

import (
common "github.com/prometheus/common/config"
"github.com/grafana/alloy/syntax"
"github.com/stretchr/testify/require"
"strings"
"testing"
)

func TestBasicAuthAndTLSBothSetError(t *testing.T) {
args := defaultArgs()
args.Endpoints = make([]EndpointConfig, 1)
args.Endpoints[0] = defaultEndpointConfig()
args.Endpoints[0].Name = "test"
args.Endpoints[0].TLSConfig = &common.TLSConfig{}
args.Endpoints[0].BasicAuth = &BasicAuth{}
err := args.Validate()
require.Error(t, err)
require.True(t, strings.Contains(err.Error(), "cannot have both BasicAuth and TLSConfig"))
func TestParsingTLSConfig(t *testing.T) {
var args Arguments
err := syntax.Unmarshal([]byte(`
endpoint "cloud" {
url = "http://example.com"
basic_auth {
username = 12345
password = "password"
}
tls_config {
insecure_skip_verify = true
}
}
`), &args)

require.NoError(t, err)
}

0 comments on commit 419e997

Please sign in to comment.