Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove LogPipeline loki output #1437

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions apis/telemetry/v1alpha1/logpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ type Filter struct {
Custom string `json:"custom,omitempty"`
}

// LokiOutput configures an output to the Kyma-internal Loki instance.
type LokiOutput struct {
// Grafana Loki URL.
URL ValueType `json:"url,omitempty"`
// Labels to set for each log record.
Labels map[string]string `json:"labels,omitempty"`
// Attributes to be removed from a log record.
RemoveKeys []string `json:"removeKeys,omitempty"`
}

// HTTPOutput configures an HTTP-based output compatible with the Fluent Bit HTTP output plugin.
type HTTPOutput struct {
// Defines the host of the HTTP receiver.
Expand Down Expand Up @@ -133,8 +123,6 @@ type Output struct {
Custom string `json:"custom,omitempty"`
// Configures an HTTP-based output compatible with the Fluent Bit HTTP output plugin.
HTTP *HTTPOutput `json:"http,omitempty"`
// The grafana-loki output is not supported anymore. For integration with a custom Loki installation, use the `custom` output and follow [Installing a custom Loki stack in Kyma](https://kyma-project.io/#/telemetry-manager/user/integration/loki/README ).
Loki *LokiOutput `json:"grafana-loki,omitempty"`
}

func (i *Input) IsDefined() bool {
Expand All @@ -149,10 +137,6 @@ func (o *Output) IsHTTPDefined() bool {
return o.HTTP != nil && o.HTTP.Host.IsDefined()
}

func (o *Output) IsLokiDefined() bool {
return o.Loki != nil && o.Loki.URL.IsDefined()
}

func (o *Output) IsAnyDefined() bool {
return o.pluginCount() > 0
}
Expand All @@ -169,9 +153,6 @@ func (o *Output) pluginCount() int {
if o.IsHTTPDefined() {
plugins++
}
if o.IsLokiDefined() {
plugins++
}
return plugins
}

Expand Down
16 changes: 0 additions & 16 deletions apis/telemetry/v1alpha1/logpipeline_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,18 @@ func TestLogPipelineOutput(t *testing.T) {
expectedAny: true,
expectedSingle: true,
},
{
name: "loki",
given: Output{Loki: &LokiOutput{URL: ValueType{Value: "localhost"}}},
expectedLoki: true,
expectedAny: true,
expectedSingle: true,
},
{
name: "invalid: none defined",
given: Output{},
expectedAny: false,
expectedSingle: false,
},
{
name: "invalid: multiple defined",
given: Output{Custom: "name: null", Loki: &LokiOutput{URL: ValueType{Value: "localhost"}}},
expectedCustom: true,
expectedLoki: true,
expectedAny: true,
expectedSingle: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.Equal(t, test.expectedCustom, test.given.IsCustomDefined())
require.Equal(t, test.expectedHTTP, test.given.IsHTTPDefined())
require.Equal(t, test.expectedLoki, test.given.IsLokiDefined())
require.Equal(t, test.expectedAny, test.given.IsAnyDefined())
})
}
Expand Down
36 changes: 0 additions & 36 deletions apis/telemetry/v1alpha1/logpipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1alpha1

import (
"fmt"
"net/url"
"regexp"
"strings"

Expand Down Expand Up @@ -31,12 +30,6 @@ func (lp *LogPipeline) validateOutput(deniedOutputPlugins []string) error {
}
}

if output.IsLokiDefined() {
if err := validateLokiOutput(output.Loki); err != nil {
return err
}
}

return validateCustomOutput(deniedOutputPlugins, output.Custom)
}

Expand All @@ -50,20 +43,6 @@ func checkSingleOutputPlugin(output Output) error {
return nil
}

func validateLokiOutput(lokiOutput *LokiOutput) error {
if lokiOutput.URL.Value != "" && !validURL(lokiOutput.URL.Value) {
return fmt.Errorf("invalid hostname '%s'", lokiOutput.URL.Value)
}
if !lokiOutput.URL.IsDefined() && (len(lokiOutput.Labels) != 0 || len(lokiOutput.RemoveKeys) != 0) {
return fmt.Errorf("loki output must have a URL configured")
}
if secretRefAndValueIsPresent(lokiOutput.URL) {
return fmt.Errorf("loki output URL must have either a value or secret key reference")
}
return nil

}

func validateHTTPOutput(httpOutput *HTTPOutput) error {
isValidHostname, err := validHostname(httpOutput.Host.Value)

Expand All @@ -89,21 +68,6 @@ func validateHTTPOutput(httpOutput *HTTPOutput) error {
return nil
}

func validURL(host string) bool {
host = strings.Trim(host, " ")

_, err := url.ParseRequestURI(host)
if err != nil {
return false
}

u, err := url.Parse(host)
if err != nil || u.Scheme == "" || u.Host == "" {
return false
}
return true
}

func validHostname(host string) (bool, error) {
host = strings.Trim(host, " ")
re, err := regexp.Compile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
Expand Down
4 changes: 0 additions & 4 deletions apis/telemetry/v1alpha1/secret_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ func (lp *LogPipeline) GetEnvSecretRefs() []SecretKeyRef {
refs = appendIfSecretRef(refs, output.HTTP.User)
refs = appendIfSecretRef(refs, output.HTTP.Password)
}
if output.IsLokiDefined() {
refs = appendIfSecretRef(refs, output.Loki.URL)
}

return refs
}

Expand Down
64 changes: 0 additions & 64 deletions apis/telemetry/v1alpha1/secret_refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,70 +79,6 @@ func TestLogPipeline_GetSecretRefs(t *testing.T) {
{Name: "creds", Namespace: "default", Key: "password"},
},
},
{
name: "loki output secret refs",
given: LogPipeline{
ObjectMeta: metav1.ObjectMeta{
Name: "loki",
},
Spec: LogPipelineSpec{
Output: Output{
Loki: &LokiOutput{
URL: ValueType{
ValueFrom: &ValueFromSource{
SecretKeyRef: &SecretKeyRef{
Name: "creds", Namespace: "default", Key: "url",
},
},
},
},
},
},
},
expected: []SecretKeyRef{
{Name: "creds", Namespace: "default", Key: "url"},
},
},
{
name: "output secret refs and variables",
given: LogPipeline{
ObjectMeta: metav1.ObjectMeta{
Name: "loki",
},
Spec: LogPipelineSpec{
Output: Output{
Loki: &LokiOutput{
URL: ValueType{
ValueFrom: &ValueFromSource{
SecretKeyRef: &SecretKeyRef{
Name: "creds", Namespace: "default", Key: "url",
},
},
},
},
},
Variables: []VariableRef{
{
Name: "password-1",
ValueFrom: ValueFromSource{
SecretKeyRef: &SecretKeyRef{Name: "secret-1", Key: "password"},
},
},
{
Name: "password-2",
ValueFrom: ValueFromSource{
SecretKeyRef: &SecretKeyRef{Name: "secret-2", Key: "password"},
},
},
},
},
},
expected: []SecretKeyRef{
{Name: "creds", Namespace: "default", Key: "url"},
{Name: "secret-1", Key: "password"},
{Name: "secret-2", Key: "password"},
},
},
}

for _, test := range tests {
Expand Down
33 changes: 0 additions & 33 deletions apis/telemetry/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions apis/telemetry/v1beta1/logpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ type Output struct {
Custom string `json:"custom,omitempty"`
// Configures an HTTP-based output compatible with the Fluent Bit HTTP output plugin.
HTTP *HTTPOutput `json:"http,omitempty"`
// The grafana-loki output is not supported anymore. For integration with a custom Loki installation, use the `custom` output and follow [Installing a custom Loki stack in Kyma](https://kyma-project.io/#/telemetry-manager/user/integration/loki/README ).
Loki *LokiOutput `json:"grafana-loki,omitempty"`
}

// HTTPOutput configures an HTTP-based output compatible with the Fluent Bit HTTP output plugin.
Expand All @@ -134,16 +132,6 @@ type HTTPOutput struct {
Dedot bool `json:"dedot,omitempty"`
}

// LokiOutput configures an output to the Kyma-internal Loki instance.
type LokiOutput struct {
// Grafana Loki URL.
URL ValueType `json:"url,omitempty"`
// Labels to set for each log record.
Labels map[string]string `json:"labels,omitempty"`
// Attributes to be removed from a log record.
RemoveKeys []string `json:"removeKeys,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="has(self.cert) == has(self.key)", message="Can define either both 'cert' and 'key', or neither"
type TLSConfig struct {
// Indicates if TLS is disabled or enabled. Default is `false`.
Expand Down Expand Up @@ -204,10 +192,6 @@ func (o *Output) IsHTTPDefined() bool {
return o.HTTP != nil && o.HTTP.Host.IsDefined()
}

func (o *Output) IsLokiDefined() bool {
return o.Loki != nil && o.Loki.URL.IsDefined()
}

func (o *Output) IsAnyDefined() bool {
return o.pluginCount() > 0
}
Expand All @@ -224,9 +208,6 @@ func (o *Output) pluginCount() int {
if o.IsHTTPDefined() {
plugins++
}
if o.IsLokiDefined() {
plugins++
}
return plugins
}

Expand Down
16 changes: 0 additions & 16 deletions apis/telemetry/v1beta1/logpipeline_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,18 @@ func TestLogPipelineOutput(t *testing.T) {
expectedAny: true,
expectedSingle: true,
},
{
name: "loki",
given: Output{Loki: &LokiOutput{URL: ValueType{Value: "localhost"}}},
expectedLoki: true,
expectedAny: true,
expectedSingle: true,
},
{
name: "invalid: none defined",
given: Output{},
expectedAny: false,
expectedSingle: false,
},
{
name: "invalid: multiple defined",
given: Output{Custom: "name: null", Loki: &LokiOutput{URL: ValueType{Value: "localhost"}}},
expectedCustom: true,
expectedLoki: true,
expectedAny: true,
expectedSingle: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.Equal(t, test.expectedCustom, test.given.IsCustomDefined())
require.Equal(t, test.expectedHTTP, test.given.IsHTTPDefined())
require.Equal(t, test.expectedLoki, test.given.IsLokiDefined())
require.Equal(t, test.expectedAny, test.given.IsAnyDefined())
})
}
Expand Down
Loading
Loading