-
Notifications
You must be signed in to change notification settings - Fork 72
/
config.go
107 lines (93 loc) · 2.84 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Copyright (C) 2019-2021 vdaas.org vald team <vald@vdaas.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Package setting stores all server application settings
package config
import (
"strings"
"github.com/vdaas/vald/internal/config"
)
// GlobalConfig is type alias of config.GlobalConfig.
type GlobalConfig = config.GlobalConfig
// Operation is operation type of implemented load test.
type Operation uint8
// Operation method definition.
const (
UnknownOperation Operation = iota
Insert
StreamInsert
Search
StreamSearch
)
// OperationMethod converts string to Operation.
func OperationMethod(s string) Operation {
switch strings.ToLower(s) {
case "insert":
return Insert
case "streaminsert":
return StreamInsert
case "search":
return Search
case "streamsearch":
return StreamSearch
default:
return UnknownOperation
}
}
// String converts Operation to string.
func (o Operation) String() string {
switch o {
case Insert:
return "Insert"
case StreamInsert:
return "StreamInsert"
case Search:
return "Search"
case StreamSearch:
return "StreamSearch"
default:
return "Unknown operation"
}
}
// Data represent a application setting data content (config.yaml).
// In K8s environment, this configuration is stored in K8s ConfigMap.
type Data struct {
config.GlobalConfig `json:",inline" yaml:",inline"`
Addr string `json:"addr" yaml:"addr"`
Operation string `json:"operation" yaml:"operation"`
Dataset string `json:"dataset" yaml:"dataset"`
Concurrency int `json:"concurrency" yaml:"concurrency"`
BatchSize int `json:"batch_size" yaml:"batch_size"`
ProgressDuration string `json:"progress_duration" yaml:"progress_duration"`
Client *config.GRPCClient `json:"client" yaml:"client"`
}
// NewConfig returns loaded configuration from file.
func NewConfig(path string) (cfg *Data, err error) {
err = config.Read(path, &cfg)
if err != nil {
return nil, err
}
if cfg != nil {
cfg.Bind()
}
if cfg.Client != nil {
cfg.Client.Bind()
}
cfg.Addr = config.GetActualValue(cfg.Addr)
cfg.Operation = config.GetActualValue(cfg.Operation)
cfg.Dataset = config.GetActualValue(cfg.Dataset)
cfg.ProgressDuration = config.GetActualValue(cfg.ProgressDuration)
return cfg, nil
}