Skip to content

Commit 7ea5029

Browse files
Merge pull request #43 from splunk/42-index-datatype
42 index datatype
2 parents 4c91e57 + d08993b commit 7ea5029

File tree

6 files changed

+107
-0
lines changed

6 files changed

+107
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.6.1 (December 2, 2021)
2+
3+
FEATURES:
4+
5+
* **Schema Change**: Index has `datatype`.
6+
17
## 1.6.0 (November 12, 2021)
28

39
FEATURES:

docs/guides/schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ names. As per the `authorize.conf` specification:
122122
- **homePath** (String) homePath of the index. Defaults to `$SPLUNK_DB/<index name>/db`.
123123
- **coldPath** (String) coldPath of the index. Defaults to `$SPLUNK_DB/<index name>/colddb`.
124124
- **thawedPath** (String) thawedPath of the index. Defaults to `$SPLUNK_DB/<index name>/thaweddb`.
125+
- **datatype** (String, optional) The datatype of the index. Permitted values are `event`, and `metric`.
125126

126127
<a id="lookup"></a>
127128
## Schema for `lookup`

internal/splunkconfig/config/index.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Index struct {
2525
HomePath IndexPath `yaml:"homePath"`
2626
ColdPath IndexPath `yaml:"coldPath"`
2727
ThawedPath IndexPath `yaml:"thawedPath"`
28+
DataType IndexDataType
2829
}
2930

3031
// validate returns an error if the Index is invalid.
@@ -37,6 +38,10 @@ func (index Index) validate() error {
3738
return err
3839
}
3940

41+
if err := index.DataType.validate(); err != nil {
42+
return err
43+
}
44+
4045
return nil
4146
}
4247

@@ -89,6 +94,10 @@ func (index Index) stanzaValues() StanzaValues {
8994
stanzaValues["frozenTimePeriodInSecs"] = fmt.Sprintf("%d", index.FrozenTime.InSeconds())
9095
}
9196

97+
if index.DataType != INDEXDATATYPEUNDEF {
98+
stanzaValues["datatype"] = string(index.DataType)
99+
}
100+
92101
// defaultIndexPath will return a valid IndexPath, so we throw away the ok return value, expecting it will never be false
93102
stanzaValues["homePath"], _ = firstIndexPathString(index.HomePath, defaultIndexPath(index.Name, "db"))
94103
stanzaValues["coldPath"], _ = firstIndexPathString(index.HomePath, defaultIndexPath(index.Name, "colddb"))

internal/splunkconfig/config/index_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ func TestIndex_stanza(t *testing.T) {
115115
},
116116
},
117117
},
118+
{
119+
Index{Name: "index_a", DataType: "event"},
120+
Stanza{
121+
Name: "index_a",
122+
Values: StanzaValues{
123+
"homePath": "$SPLUNK_DB/index_a/db",
124+
"coldPath": "$SPLUNK_DB/index_a/colddb",
125+
"datatype": "event",
126+
"thawedPath": "$SPLUNK_DB/index_a/thaweddb",
127+
},
128+
},
129+
},
118130
}
119131

120132
tests.test(t)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2021 Splunk, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package config
16+
17+
import "fmt"
18+
19+
// IndexDataType represents the value of an Index's "datatype" field.
20+
type IndexDataType string
21+
22+
const (
23+
INDEXDATATYPEUNDEF IndexDataType = ""
24+
INDEXDATATYPEEVENT IndexDataType = "event"
25+
INDEXDATATYPEMETRIC IndexDataType = "metric"
26+
)
27+
28+
// validate returns an error if IndexDataType is invalid. It is invalid if:
29+
// * it isn't one of the defined constants
30+
func (indexDataType IndexDataType) validate() error {
31+
switch indexDataType {
32+
case INDEXDATATYPEUNDEF, INDEXDATATYPEEVENT, INDEXDATATYPEMETRIC:
33+
break
34+
default:
35+
return fmt.Errorf("invalid IndexDataType value: %s", indexDataType)
36+
}
37+
38+
return nil
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2021 Splunk, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package config
16+
17+
import "testing"
18+
19+
func TestIndexDataType_validate(t *testing.T) {
20+
tests := validatorTestCases{
21+
{
22+
validator: IndexDataType(""),
23+
wantError: false,
24+
},
25+
{
26+
validator: IndexDataType("event"),
27+
wantError: false,
28+
},
29+
{
30+
validator: IndexDataType("metric"),
31+
wantError: false,
32+
},
33+
{
34+
validator: IndexDataType("invalid"),
35+
wantError: true,
36+
},
37+
}
38+
39+
tests.test(t)
40+
}

0 commit comments

Comments
 (0)