Skip to content

Commit 2e5417c

Browse files
added http functional test
1 parent 0978873 commit 2e5417c

File tree

3 files changed

+103
-7
lines changed

3 files changed

+103
-7
lines changed

test/framework/functional/framework.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,14 @@ func (f *CollectorFunctionalFramework) addOutputContainers(b *runtime.PodBuilder
437437
}
438438
}
439439
case obs.OutputTypeHTTP:
440-
if err := f.AddVectorHttpOutput(b, output); err != nil {
441-
return err
440+
if output.HTTP.LinePerEvent {
441+
if err := f.AddVLOutput(b, output, nil); err != nil {
442+
return err
443+
}
444+
} else {
445+
if err := f.AddVectorHttpOutput(b, output); err != nil {
446+
return err
447+
}
442448
}
443449
case obs.OutputTypeSplunk:
444450
if err := f.AddSplunkOutput(b, output); err != nil {

test/framework/functional/output_victorialogs.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,27 @@ func (f *CollectorFunctionalFramework) AddVLOutput(b *runtime.PodBuilder, output
1919
log.V(2).Info("Adding output for victorialogs", "name", output.Name)
2020
name := strings.ToLower(output.Name)
2121

22-
esURL, err := url.Parse(output.Elasticsearch.URL)
23-
if err != nil {
24-
return err
22+
port := "9428"
23+
switch output.Type {
24+
case obs.OutputTypeElasticsearch:
25+
u, err := url.Parse(output.Elasticsearch.URL)
26+
if err != nil {
27+
return err
28+
}
29+
port = u.Port()
30+
case obs.OutputTypeHTTP:
31+
u, err := url.Parse(output.HTTP.URL)
32+
if err != nil {
33+
return err
34+
}
35+
port = u.Port()
2536
}
2637

2738
log.V(2).Info("Adding container", "name", name)
28-
log.V(2).Info("Adding VictoriaLogs output container", "name", obs.OutputTypeElasticsearch)
39+
log.V(2).Info("Adding VictoriaLogs output container", "name", output.Type)
2940

3041
cmdArgs := []string{
31-
"-httpListenAddr=:" + esURL.Port(),
42+
"-httpListenAddr=:" + port,
3243
"-storageDataPath=/tmp/logs",
3344
}
3445
if len(args) > 0 {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package http
2+
3+
import (
4+
"sort"
5+
"strings"
6+
"time"
7+
8+
. "github.com/onsi/ginkgo/v2"
9+
. "github.com/onsi/gomega"
10+
11+
obs "github.com/openshift/cluster-logging-operator/api/observability/v1"
12+
"github.com/openshift/cluster-logging-operator/test/framework/functional"
13+
14+
"github.com/openshift/cluster-logging-operator/test/helpers/types"
15+
obstestruntime "github.com/openshift/cluster-logging-operator/test/runtime/observability"
16+
)
17+
18+
var _ = Describe("[Functional][Outputs][HTTP] Logforwarding to VictoriaLogs", func() {
19+
20+
var (
21+
framework *functional.CollectorFunctionalFramework
22+
23+
// Template expected as output Log
24+
outputLogTemplate = functional.NewApplicationLogTemplate()
25+
)
26+
27+
Context("should write to victorialogs", func() {
28+
DescribeTable("with custom headers", func(headers map[string]string) {
29+
outputLogTemplate.ViaqIndexName = "app-write"
30+
framework = functional.NewCollectorFunctionalFramework()
31+
obstestruntime.NewClusterLogForwarderBuilder(framework.Forwarder).
32+
FromInput(obs.InputTypeApplication).
33+
ToHttpOutput(func(output *obs.OutputSpec) {
34+
output.HTTP.URL = "http://0.0.0.0:9428/insert/jsonline"
35+
output.HTTP.LinePerEvent = true
36+
output.HTTP.Headers = headers
37+
})
38+
defer framework.Cleanup()
39+
Expect(framework.Deploy()).To(BeNil())
40+
timestamp := functional.CRIOTime(time.Now())
41+
ukr := "привіт "
42+
jp := "こんにちは "
43+
ch := "你好"
44+
msg := functional.NewCRIOLogMessage(timestamp, ukr+jp+ch, false)
45+
Expect(framework.WriteMessagesToApplicationLog(msg, 10)).To(BeNil())
46+
Expect(framework.WriteMessagesWithNotUTF8SymbolsToLog()).To(BeNil())
47+
requestHeaders := map[string]string{
48+
"AccountID": "0",
49+
"ProjectID": "0",
50+
}
51+
for headerName := range requestHeaders {
52+
if v, ok := headers[headerName]; ok {
53+
requestHeaders[headerName] = v
54+
}
55+
}
56+
raw, err := framework.GetLogsFromVL(string(obs.OutputTypeHTTP), requestHeaders)
57+
Expect(err).To(BeNil(), "Expected no errors reading the logs")
58+
Expect(raw).To(Not(BeEmpty()))
59+
// Parse log line
60+
var logs []map[string]string
61+
err = types.StrictlyParseLogsFromSlice(raw, &logs)
62+
Expect(err).To(BeNil(), "Expected no errors parsing the logs")
63+
Expect(len(logs)).To(Equal(11))
64+
//sort log by time before matching
65+
sort.Slice(logs, func(i, j int) bool {
66+
return strings.Compare(logs[i]["_time"], logs[j]["_time"]) < 0
67+
})
68+
69+
Expect(logs[0]["_msg"]).To(Equal(ukr + jp + ch))
70+
Expect(logs[10]["_msg"]).To(Equal("������������"))
71+
},
72+
Entry("Non-default tenant ID", map[string]string{
73+
"AccountID": "10",
74+
"ProjectID": "10",
75+
"VL-Msg-Field": "message",
76+
}),
77+
)
78+
})
79+
})

0 commit comments

Comments
 (0)