-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prior config refactoring before adding prometheus config (#511)
- Merged the different Config structs (from handler.Config, server.Config and loki.Config) in a dedicated config package - Add names to table-based tests - A few linter fixes (e.g. space after comments)
- Loading branch information
Showing
22 changed files
with
384 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package config | ||
|
||
// TODO: move this file in a new netobserv-libs repo ? (Same in FLP) | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// Duration is a wrapper of time.Duration that allows json marshaling. | ||
type Duration struct { | ||
time.Duration | ||
} | ||
|
||
func (d Duration) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(d.String()) | ||
} | ||
|
||
func (d *Duration) UnmarshalJSON(b []byte) error { | ||
var v interface{} | ||
if err := json.Unmarshal(b, &v); err != nil { | ||
return err | ||
} | ||
switch value := v.(type) { | ||
case float64: | ||
d.Duration = time.Duration(value) | ||
return nil | ||
case string: | ||
var err error | ||
d.Duration, err = time.ParseDuration(value) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
default: | ||
return fmt.Errorf("invalid duration %v", value) | ||
} | ||
} | ||
|
||
func (d Duration) MarshalYAML() (interface{}, error) { | ||
return d.String(), nil | ||
} | ||
|
||
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
var durationStr string | ||
err := unmarshal(&durationStr) | ||
if err != nil { | ||
return err | ||
} | ||
d.Duration, err = time.ParseDuration(durationStr) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package config | ||
|
||
import "github.com/netobserv/network-observability-console-plugin/pkg/utils" | ||
|
||
type Loki struct { | ||
URL string `yaml:"url" json:"url"` | ||
Labels []string `yaml:"labels" json:"labels"` | ||
StatusURL string `yaml:"statusUrl,omitempty" json:"statusUrl,omitempty"` | ||
Timeout Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"` | ||
TenantID string `yaml:"tenantID,omitempty" json:"tenantID,omitempty"` | ||
TokenPath string `yaml:"tokenPath,omitempty" json:"tokenPath,omitempty"` | ||
SkipTLS bool `yaml:"skipTls,omitempty" json:"skipTls,omitempty"` | ||
CAPath string `yaml:"caPath,omitempty" json:"caPath,omitempty"` | ||
StatusSkipTLS bool `yaml:"statusSkipTls,omitempty" json:"statusSkipTls,omitempty"` | ||
StatusCAPath string `yaml:"statusCaPath,omitempty" json:"statusCaPath,omitempty"` | ||
StatusUserCertPath string `yaml:"statusUserCertPath,omitempty" json:"statusUserCertPath,omitempty"` | ||
StatusUserKeyPath string `yaml:"statusUserKeyPath,omitempty" json:"statusUserKeyPath,omitempty"` | ||
UseMocks bool `yaml:"useMocks,omitempty" json:"useMocks,omitempty"` | ||
ForwardUserToken bool `yaml:"forwardUserToken,omitempty" json:"forwardUserToken,omitempty"` | ||
AuthCheck string `yaml:"authCheck,omitempty" json:"authCheck,omitempty"` | ||
labelsMap map[string]struct{} | ||
} | ||
|
||
func (l *Loki) GetStatusURL() string { | ||
if l.StatusURL != "" { | ||
return l.StatusURL | ||
} | ||
return l.URL | ||
} | ||
|
||
func (l *Loki) IsLabel(key string) bool { | ||
if l.labelsMap == nil { | ||
l.labelsMap = utils.GetMapInterface(l.Labels) | ||
} | ||
_, isLabel := l.labelsMap[key] | ||
return isLabel | ||
} |
Oops, something went wrong.