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

LOG-1370 Change name of elasticsearch.indexKey to structuredIndexKey #1019

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ spec:
properties:
elasticsearch:
properties:
indexKey:
description: IndexKey specifies the metadata key to be used as name of elasticsearch index It takes precedence over IndexName
structuredIndexKey:
description: StructuredIndexKey specifies the metadata key to be used as name of elasticsearch index It takes precedence over StructuredIndexName
type: string
indexName:
description: IndexName specifies the name of elasticsearch schema
structuredIndexName:
description: StructuredIndexName specifies the name of elasticsearch schema
type: string
type: object
fluentdForward:
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/logging/v1/output_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ type Kafka struct {

type FluentdForward struct{}
type Elasticsearch struct {
// IndexKey specifies the metadata key to be used as name of elasticsearch index
// It takes precedence over IndexName
// StructuredIndexKey specifies the metadata key to be used as name of elasticsearch index
// It takes precedence over StructuredIndexName
//
// +optional
IndexKey string `json:"indexKey,omitempty"`
StructuredIndexKey string `json:"structuredIndexKey,omitempty"`

// IndexName specifies the name of elasticsearch schema
// StructuredIndexName specifies the name of elasticsearch schema
//
// +optional
IndexName string `json:"indexName,omitempty"`
StructuredIndexName string `json:"structuredIndexName,omitempty"`
}
4 changes: 2 additions & 2 deletions pkg/generators/forwarding/fluentd/fluent_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ func (conf *outputLabelConf) IsElasticSearchOutput() bool {
return conf.Target.Type == logging.OutputTypeElasticsearch
}

func (conf *outputLabelConf) NeedChangeElasticsearchIndexName() bool {
func (conf *outputLabelConf) NeedChangeElasticsearchStructuredIndexName() bool {
return conf.Target.Type == logging.OutputTypeElasticsearch &&
conf.Target.OutputTypeSpec.Elasticsearch != nil &&
(conf.Target.OutputTypeSpec.Elasticsearch.IndexKey != "" || conf.Target.OutputTypeSpec.Elasticsearch.IndexName != "")
(conf.Target.OutputTypeSpec.Elasticsearch.StructuredIndexKey != "" || conf.Target.OutputTypeSpec.Elasticsearch.StructuredIndexName != "")
}

func generateRubyDigArgs(path string) string {
Expand Down
10 changes: 5 additions & 5 deletions pkg/generators/forwarding/fluentd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,15 +613,15 @@ const pipelineToOutputCopyTemplate = `{{- define "pipelineToOutputCopyTemplate"

const outputLabelConfTemplate = `{{- define "outputLabelConf" -}}
<label {{.LabelName}}>
{{- if (.NeedChangeElasticsearchIndexName)}}
{{- if (.NeedChangeElasticsearchStructuredIndexName)}}
<filter **>
@type record_modifier
<record>
indexFromKey ${record.dig({{.GetKeyVal .Target.OutputTypeSpec.Elasticsearch.IndexKey}})}
hasIndexName "{{.Target.OutputTypeSpec.Elasticsearch.IndexName}}"
viaq_index_name ${if !record['indexFromKey'].nil?; record['indexFromKey']; elsif record['hasIndexName'] != ""; record['hasIndexName']; else record['viaq_index_name']; end;}
indexFromKey ${record.dig({{.GetKeyVal .Target.OutputTypeSpec.Elasticsearch.StructuredIndexKey}})}
hasStructuredIndexName "{{.Target.OutputTypeSpec.Elasticsearch.StructuredIndexName}}"
viaq_index_name ${if !record['indexFromKey'].nil?; record['indexFromKey']; elsif record['hasStructuredIndexName'] != ""; record['hasStructuredIndexName']; else record['viaq_index_name']; end;}
</record>
remove_keys indexFromKey, hasIndexName
remove_keys indexFromKey, hasStructuredIndexName
</filter>
{{- end}}
{{- if .IsElasticSearchOutput}}
Expand Down
26 changes: 13 additions & 13 deletions test/functional/outputs/forward_to_elasticsearch_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = Describe("[Functional][Outputs][ElasticSearch][Index] FluentdForward Out
const (
elasticSearchTag = "7.10.1"
elasticSearchImage = "elasticsearch:" + elasticSearchTag
IndexKey = "indexkey"
StructuredIndexKey = "structuredIndexKey"
IndexValue = "myindex"
AppIndex = "app-write"
)
Expand All @@ -31,7 +31,7 @@ var _ = Describe("[Functional][Outputs][ElasticSearch][Index] FluentdForward Out
return func(b *runtime.PodBuilder) error {
log.V(2).Info("Adding ElasticSearch output container", "name", logging.OutputTypeElasticsearch)
b.AddLabels(map[string]string{
IndexKey: IndexValue,
StructuredIndexKey: IndexValue,
}).
AddContainer(logging.OutputTypeElasticsearch, elasticSearchImage).
AddEnvVar("discovery.type", "single-node").
Expand All @@ -54,18 +54,18 @@ var _ = Describe("[Functional][Outputs][ElasticSearch][Index] FluentdForward Out
})

Context("when sending to ElasticSearch "+elasticSearchTag+" protocol", func() {
It("should send logs to indexName", func() {
IndexName := "myindex"
It("should send logs to structuredIndexName", func() {
StructuredIndexName := "myindex"
functional.NewClusterLogForwarderBuilder(framework.Forwarder).
FromInput(logging.InputNameApplication).
ToOutputWithVisitor(func(spec *logging.OutputSpec) {
spec.Elasticsearch = &logging.Elasticsearch{
IndexName: IndexName,
StructuredIndexName: StructuredIndexName,
}
}, logging.OutputTypeElasticsearch)
Expect(framework.DeployWithVisitor(addElasticSearchContainer)).To(BeNil())
Expect(framework.WritesApplicationLogs(1)).To(BeNil())
raw, err := framework.GetLogsFromElasticSearchIndex(logging.OutputTypeElasticsearch, IndexName)
raw, err := framework.GetLogsFromElasticSearchIndex(logging.OutputTypeElasticsearch, StructuredIndexName)
Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(raw).To(Not(BeEmpty()))

Expand All @@ -80,12 +80,12 @@ var _ = Describe("[Functional][Outputs][ElasticSearch][Index] FluentdForward Out
})
})
Context("when sending to ElasticSearch "+elasticSearchTag+" protocol", func() {
It("should send to k8s label indexKey", func() {
It("should send to k8s label structuredIndexKey", func() {
functional.NewClusterLogForwarderBuilder(framework.Forwarder).
FromInput(logging.InputNameApplication).
ToOutputWithVisitor(func(spec *logging.OutputSpec) {
spec.Elasticsearch = &logging.Elasticsearch{
IndexKey: fmt.Sprintf("kubernetes.labels.%s", IndexKey),
StructuredIndexKey: fmt.Sprintf("kubernetes.labels.%s", StructuredIndexKey),
}
}, logging.OutputTypeElasticsearch)
Expect(framework.DeployWithVisitor(addElasticSearchContainer)).To(BeNil())
Expand All @@ -104,16 +104,16 @@ var _ = Describe("[Functional][Outputs][ElasticSearch][Index] FluentdForward Out
outputLogTemplate.ViaqIndexName = ""
Expect(outputTestLog).To(matchers.FitLogFormatTemplate(outputLogTemplate))
})
It("should send to openshift label indexKey", func() {
It("should send to openshift label structuredIndexKey", func() {
clfb := functional.NewClusterLogForwarderBuilder(framework.Forwarder).
FromInput(logging.InputNameApplication).
ToOutputWithVisitor(func(spec *logging.OutputSpec) {
spec.Elasticsearch = &logging.Elasticsearch{
IndexKey: fmt.Sprintf("openshift.labels.%s", IndexKey),
StructuredIndexKey: fmt.Sprintf("openshift.labels.%s", StructuredIndexKey),
}
}, logging.OutputTypeElasticsearch)
clfb.Forwarder.Spec.Pipelines[0].Labels = map[string]string{
IndexKey: IndexValue,
StructuredIndexKey: IndexValue,
}
Expect(framework.DeployWithVisitor(addElasticSearchContainer)).To(BeNil())

Expand Down Expand Up @@ -154,13 +154,13 @@ var _ = Describe("[Functional][Outputs][ElasticSearch][Index] FluentdForward Out
Expect(outputTestLog).To(matchers.FitLogFormatTemplate(outputLogTemplate))
})
})
Context("if elasticsearch indexKey wrongly configured", func() {
Context("if elasticsearch structuredIndexKey wrongly configured", func() {
It("should send logs to app-write", func() {
functional.NewClusterLogForwarderBuilder(framework.Forwarder).
FromInput(logging.InputNameApplication).
ToOutputWithVisitor(func(spec *logging.OutputSpec) {
spec.Elasticsearch = &logging.Elasticsearch{
IndexKey: "junk",
StructuredIndexKey: "junk",
}
}, logging.OutputTypeElasticsearch)
Expect(framework.DeployWithVisitor(addElasticSearchContainer)).To(BeNil())
Expand Down