Replace name "LogViewerUIConfig" with "LogViewerConfig"

pull/3806/head
Alirie Gray 2018-07-03 11:44:39 -07:00 committed by Jared Scheib
parent c33d4aa856
commit 2319ac3ff8
10 changed files with 1092 additions and 226 deletions

View File

@ -36,8 +36,8 @@ func (s *ConfigStore) Initialize(ctx context.Context) error {
Auth: chronograf.AuthConfig{
SuperAdminNewUsers: false,
},
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "time",
Position: 0,

View File

@ -24,8 +24,8 @@ func TestConfig_Get(t *testing.T) {
Auth: chronograf.AuthConfig{
SuperAdminNewUsers: false,
},
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "time",
Position: 0,
@ -172,8 +172,8 @@ func TestConfig_Update(t *testing.T) {
Auth: chronograf.AuthConfig{
SuperAdminNewUsers: false,
},
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "time",
Position: 1,
@ -280,8 +280,8 @@ func TestConfig_Update(t *testing.T) {
Auth: chronograf.AuthConfig{
SuperAdminNewUsers: false,
},
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "time",
Position: 1,

View File

@ -716,7 +716,7 @@ func UnmarshalOrganizationPB(data []byte, o *Organization) error {
// MarshalConfig encodes a config to binary protobuf format.
func MarshalConfig(c *chronograf.Config) ([]byte, error) {
columns := make([]*LogViewerUIColumn, len(c.LogViewer.Columns))
columns := make([]*LogViewerColumn, len(c.LogViewer.Columns))
for i, column := range c.LogViewer.Columns {
encodings := make([]*ColumnEncoding, len(column.Encodings))
@ -728,7 +728,7 @@ func MarshalConfig(c *chronograf.Config) ([]byte, error) {
}
}
columns[i] = &LogViewerUIColumn{
columns[i] = &LogViewerColumn{
Name: column.Name,
Position: column.Position,
Encodings: encodings,
@ -738,7 +738,7 @@ func MarshalConfig(c *chronograf.Config) ([]byte, error) {
Auth: &AuthConfig{
SuperAdminNewUsers: c.Auth.SuperAdminNewUsers,
},
LogViewer: &LogViewerUIConfig{
LogViewer: &LogViewerConfig{
Columns: columns,
},
})
@ -761,10 +761,10 @@ func UnmarshalConfig(data []byte, c *chronograf.Config) error {
c.Auth.SuperAdminNewUsers = pb.Auth.SuperAdminNewUsers
if pb.LogViewer == nil {
return fmt.Errorf("Log Viewer UI config is nil")
return fmt.Errorf("Log Viewer config is nil")
}
columns := make([]chronograf.LogViewerUIColumn, len(pb.LogViewer.Columns))
columns := make([]chronograf.LogViewerColumn, len(pb.LogViewer.Columns))
for i, c := range pb.LogViewer.Columns {
columns[i].Name = c.Name

File diff suppressed because it is too large Load Diff

View File

@ -208,18 +208,18 @@ message Organization {
message Config {
AuthConfig Auth = 1; // Auth is the configuration for options that auth related
LogViewerUIConfig LogViewer = 2; // LogViewerUI is the configuration for the Log Viewer UI
LogViewerConfig LogViewer = 2; // LogViewer is the configuration for the Log Viewer
}
message AuthConfig {
bool SuperAdminNewUsers = 1; // SuperAdminNewUsers configuration option that specifies which users will auto become super admin
}
message LogViewerUIConfig {
repeated LogViewerUIColumn Columns = 1; // Columns is the array of columns in the log viewer UI
message LogViewerConfig {
repeated LogViewerColumn Columns = 1; // Columns is the array of columns in the log viewer
}
message LogViewerUIColumn {
message LogViewerColumn {
string Name = 1; // Name is the unique identifier of the log viewer column
int32 Position = 2; // Position is the position of the column in the log viewer's array of columns
repeated ColumnEncoding Encodings = 3; // Encodings is the array of encoded properties associated with a log viewer column

View File

@ -739,8 +739,8 @@ type OrganizationsStore interface {
// Config is the global application Config for parameters that can be set via
// API, with different sections, such as Auth
type Config struct {
Auth AuthConfig `json:"auth"`
LogViewer LogViewerUIConfig `json:"logViewer"`
Auth AuthConfig `json:"auth"`
LogViewer LogViewerConfig `json:"logViewer"`
}
// AuthConfig is the global application config section for auth parameters
@ -748,13 +748,13 @@ type AuthConfig struct {
SuperAdminNewUsers bool `json:"superAdminNewUsers"`
}
// LogViewerUIConfig is the config sections for log viewer section of the application
type LogViewerUIConfig struct {
Columns []LogViewerUIColumn `json:"columns"`
// LogViewerConfig is the config sections for log viewer section of the application
type LogViewerConfig struct {
Columns []LogViewerColumn `json:"columns"`
}
// LogViewerUIColumn is a specific column of the log viewer UI
type LogViewerUIColumn struct {
// LogViewerColumn is a specific column of the log viewer UI
type LogViewerColumn struct {
Name string `json:"name"`
Position int32 `json:"position"`
Encodings []ColumnEncoding `json:"encodings"`

View File

@ -36,17 +36,17 @@ func newAuthConfigResponse(config chronograf.Config) *authConfigResponse {
}
}
type logViewerUIResponse struct {
type logViewerResponse struct {
Links selfLinks `json:"links"`
chronograf.LogViewerUIConfig
chronograf.LogViewerConfig
}
func newLogViewerUIConfigResponse(config chronograf.Config) *logViewerUIResponse {
return &logViewerUIResponse{
func newLogViewerConfigResponse(config chronograf.Config) *logViewerResponse {
return &logViewerResponse{
Links: selfLinks{
Self: "/chronograf/v1/config/logviewer",
},
LogViewerUIConfig: config.LogViewer,
LogViewerConfig: config.LogViewer,
}
}
@ -69,8 +69,8 @@ func (s *Service) Config(w http.ResponseWriter, r *http.Request) {
encodeJSON(w, http.StatusOK, res, s.Logger)
}
// LogViewerUIConfig retrieves the log viewer UI section of the global application configuration
func (s *Service) LogViewerUIConfig(w http.ResponseWriter, r *http.Request) {
// LogViewerConfig retrieves the log viewer UI section of the global application configuration
func (s *Service) LogViewerConfig(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
config, err := s.Store.Config(ctx).Get(ctx)
@ -84,21 +84,21 @@ func (s *Service) LogViewerUIConfig(w http.ResponseWriter, r *http.Request) {
return
}
res := newLogViewerUIConfigResponse(*config)
res := newLogViewerConfigResponse(*config)
encodeJSON(w, http.StatusOK, res, s.Logger)
}
// ReplaceLogViewerUIConfig replaces the log viewer UI section of the global application configuration
func (s *Service) ReplaceLogViewerUIConfig(w http.ResponseWriter, r *http.Request) {
// ReplaceLogViewerConfig replaces the log viewer UI section of the global application configuration
func (s *Service) ReplaceLogViewerConfig(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var logViewerUIConfig chronograf.LogViewerUIConfig
if err := json.NewDecoder(r.Body).Decode(&logViewerUIConfig); err != nil {
var logViewerConfig chronograf.LogViewerConfig
if err := json.NewDecoder(r.Body).Decode(&logViewerConfig); err != nil {
invalidJSON(w, s.Logger)
return
}
if err := validLogViewerUIConfig(logViewerUIConfig); err != nil {
if err := validLogViewerConfig(logViewerConfig); err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
}
@ -112,9 +112,9 @@ func (s *Service) ReplaceLogViewerUIConfig(w http.ResponseWriter, r *http.Reques
Error(w, http.StatusBadRequest, "Configuration object was nil", s.Logger)
return
}
config.LogViewer = logViewerUIConfig
config.LogViewer = logViewerConfig
res := newLogViewerUIConfigResponse(*config)
res := newLogViewerConfigResponse(*config)
if err := s.Store.Config(ctx).Update(ctx, config); err != nil {
unknownErrorWithMessage(w, err, s.Logger)
return
@ -173,14 +173,14 @@ func (s *Service) ReplaceAuthConfig(w http.ResponseWriter, r *http.Request) {
encodeJSON(w, http.StatusOK, res, s.Logger)
}
// validLogViewerUIConfig ensures that the request body log viewer UI config is valid
// validLogViewerConfig ensures that the request body log viewer UI config is valid
// to be valid, it must: not be empty, have at least one column, not have multiple
// columns with the same name or position value, each column must have a visbility
// of either "visible" or "hidden" and if a column is of type severity, it must have
// at least one severity format of type icon, text, or both
func validLogViewerUIConfig(cfg chronograf.LogViewerUIConfig) error {
func validLogViewerConfig(cfg chronograf.LogViewerConfig) error {
if len(cfg.Columns) == 0 {
return fmt.Errorf("Invalid log viewer UI config: must have at least 1 column")
return fmt.Errorf("Invalid log viewer config: must have at least 1 column")
}
nameMatcher := map[string]bool{}
@ -193,11 +193,11 @@ func validLogViewerUIConfig(cfg chronograf.LogViewerUIConfig) error {
// check that each column has a unique value for the name and position properties
if _, ok := nameMatcher[clm.Name]; ok {
return fmt.Errorf("Invalid log viewer UI config: Duplicate column name %s", clm.Name)
return fmt.Errorf("Invalid log viewer config: Duplicate column name %s", clm.Name)
}
nameMatcher[clm.Name] = true
if _, ok := positionMatcher[clm.Position]; ok {
return fmt.Errorf("Invalid log viewer UI config: Multiple columns with same position value")
return fmt.Errorf("Invalid log viewer config: Multiple columns with same position value")
}
positionMatcher[clm.Position] = true
@ -205,7 +205,7 @@ func validLogViewerUIConfig(cfg chronograf.LogViewerUIConfig) error {
if e.Type == "visibility" {
visibility++
if !(e.Value == "visible" || e.Value == "hidden") {
return fmt.Errorf("Invalid log viewer UI config: invalid visibility in column %s", clm.Name)
return fmt.Errorf("Invalid log viewer config: invalid visibility in column %s", clm.Name)
}
}
@ -219,12 +219,12 @@ func validLogViewerUIConfig(cfg chronograf.LogViewerUIConfig) error {
}
if visibility != 1 {
return fmt.Errorf("Invalid log viewer UI config: missing visibility encoding in column %s", clm.Name)
return fmt.Errorf("Invalid log viewer config: missing visibility encoding in column %s", clm.Name)
}
if clm.Name == "severity" {
if iconCount+textCount == 0 || iconCount > 1 || textCount > 1 {
return fmt.Errorf("Invalid log viewer UI config: invalid number of severity format encodings in column %s", clm.Name)
return fmt.Errorf("Invalid log viewer config: invalid number of severity format encodings in column %s", clm.Name)
}
}
}

View File

@ -35,8 +35,8 @@ func TestConfig(t *testing.T) {
Auth: chronograf.AuthConfig{
SuperAdminNewUsers: false,
},
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "severity",
Position: 0,
@ -242,7 +242,7 @@ func TestReplaceAuthConfig(t *testing.T) {
}
}
func TestLogViewerUIConfig(t *testing.T) {
func TestLogViewerConfig(t *testing.T) {
type fields struct {
ConfigStore chronograf.ConfigStore
}
@ -262,8 +262,8 @@ func TestLogViewerUIConfig(t *testing.T) {
fields: fields{
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "severity",
Position: 0,
@ -309,7 +309,7 @@ func TestLogViewerUIConfig(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "http://any.url", nil)
s.LogViewerUIConfig(w, r)
s.LogViewerConfig(w, r)
resp := w.Result()
content := resp.Header.Get("Content-Type")
@ -328,7 +328,7 @@ func TestLogViewerUIConfig(t *testing.T) {
}
}
func TestReplaceLogViewerUIConfig(t *testing.T) {
func TestReplaceLogViewerConfig(t *testing.T) {
type fields struct {
ConfigStore chronograf.ConfigStore
}
@ -352,8 +352,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
fields: fields{
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "severity",
Position: 0,
@ -379,8 +379,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
},
},
args: args{
payload: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
payload: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "severity",
Position: 1,
@ -433,8 +433,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
fields: fields{
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "severity",
Position: 0,
@ -460,14 +460,14 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
},
},
args: args{
payload: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{},
payload: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{},
},
},
wants: wants{
statusCode: 400,
contentType: "application/json",
body: `{"code":400,"message":"Invalid log viewer UI config: must have at least 1 column"}`,
body: `{"code":400,"message":"Invalid log viewer config: must have at least 1 column"}`,
},
},
{
@ -475,8 +475,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
fields: fields{
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "procid",
Position: 0,
@ -493,8 +493,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
},
},
args: args{
payload: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
payload: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "procid",
Position: 0,
@ -521,7 +521,7 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
wants: wants{
statusCode: 400,
contentType: "application/json",
body: `{"code":400,"message":"Invalid log viewer UI config: Duplicate column name procid"}`,
body: `{"code":400,"message":"Invalid log viewer config: Duplicate column name procid"}`,
},
},
{
@ -529,8 +529,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
fields: fields{
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "procid",
Position: 0,
@ -547,8 +547,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
},
},
args: args{
payload: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
payload: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "procid",
Position: 0,
@ -575,7 +575,7 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
wants: wants{
statusCode: 400,
contentType: "application/json",
body: `{"code":400,"message":"Invalid log viewer UI config: Multiple columns with same position value"}`,
body: `{"code":400,"message":"Invalid log viewer config: Multiple columns with same position value"}`,
},
},
{
@ -583,8 +583,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
fields: fields{
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
LogViewer: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
LogViewer: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "severity",
Position: 0,
@ -606,8 +606,8 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
},
},
args: args{
payload: chronograf.LogViewerUIConfig{
Columns: []chronograf.LogViewerUIColumn{
payload: chronograf.LogViewerConfig{
Columns: []chronograf.LogViewerColumn{
{
Name: "severity",
Position: 1,
@ -634,7 +634,7 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
wants: wants{
statusCode: 400,
contentType: "application/json",
body: `{"code":400,"message":"Invalid log viewer UI config: missing visibility encoding in column severity"}`,
body: `{"code":400,"message":"Invalid log viewer config: missing visibility encoding in column severity"}`,
},
},
}
@ -653,7 +653,7 @@ func TestReplaceLogViewerUIConfig(t *testing.T) {
buf, _ := json.Marshal(tt.args.payload)
r.Body = ioutil.NopCloser(bytes.NewReader(buf))
s.ReplaceLogViewerUIConfig(w, r)
s.ReplaceLogViewerConfig(w, r)
resp := w.Result()
content := resp.Header.Get("Content-Type")

View File

@ -313,8 +313,8 @@ func NewMux(opts MuxOpts, service Service) http.Handler {
// Global application config for Chronograf
router.GET("/chronograf/v1/config", EnsureSuperAdmin(service.Config))
router.GET("/chronograf/v1/config/logviewer", EnsureViewer(service.LogViewerUIConfig))
router.PUT("/chronograf/v1/config/logviewer", EnsureEditor(service.ReplaceLogViewerUIConfig))
router.GET("/chronograf/v1/config/logviewer", EnsureViewer(service.LogViewerConfig))
router.PUT("/chronograf/v1/config/logviewer", EnsureEditor(service.ReplaceLogViewerConfig))
router.GET("/chronograf/v1/config/auth", EnsureSuperAdmin(service.AuthConfig))
router.PUT("/chronograf/v1/config/auth", EnsureSuperAdmin(service.ReplaceAuthConfig))

View File

@ -2876,7 +2876,7 @@
"schema": {
"oneOf": [
{
"$ref": "#/definitions/LogViewerUIConfig"
"$ref": "#/definitions/LogViewerConfig"
},
{
"$ref": "#/definitions/AuthConfig"
@ -2920,7 +2920,7 @@
"schema": {
"oneOf": [
{
"$ref": "#/definitions/LogViewerUIConfig"
"$ref": "#/definitions/LogViewerConfig"
},
{
"$ref": "#/definitions/AuthConfig"
@ -2932,11 +2932,11 @@
],
"responses": {
"200": {
"description": "Returns an object with the updated UI settings for a specific section",
"description": "Returns an object with the updated settings for a specific section",
"schema": {
"oneOf": [
{
"$ref": "#/definitions/LogViewerUIConfig"
"$ref": "#/definitions/LogViewerConfig"
}
]
}
@ -5144,7 +5144,7 @@
}
}
},
"LogViewerUIColumn": {
"LogViewerColumn": {
"description": "Contains the settings for the log viewer page UI",
"type": "object",
"required": [
@ -5215,7 +5215,7 @@
]
}
},
"LogViewerUIConfig": {
"LogViewerConfig": {
"description": "Contains the settings for the log viewer page UI",
"type": "object",
"required": ["columns"],
@ -5224,7 +5224,7 @@
"description": "Defines the order, names, and visibility of columns in the log viewer table",
"type": "array",
"items": {
"$ref": "#/definitions/LogViewerUIColumn"
"$ref": "#/definitions/LogViewerColumn"
}
}
},