Skip to content

Commit

Permalink
Merge pull request #1019 from alanconway/rename-es-indexkey-51
Browse files Browse the repository at this point in the history
LOG-1370 Change name of elasticsearch.indexKey to structuredIndexKey
  • Loading branch information
openshift-merge-robot authored May 17, 2021
2 parents 93aeed0 + b3bca2a commit 9c29cb3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
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

0 comments on commit 9c29cb3

Please sign in to comment.