Skip to content

Commit

Permalink
make malachite server port configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
cccaoke committed May 16, 2024
1 parent 74b648c commit 16cc4a2
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 23 deletions.
26 changes: 18 additions & 8 deletions cmd/katalyst-agent/app/options/metaserver/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (

const defaultMetricInsurancePeriod = 0 * time.Second

const defaultRodanServerPort = 9102
const (
defaultRodanServerPort = 9102
defaultMalachiteServerPort = 9002
)

type MetricFetcherOptions struct {
MetricInsurancePeriod time.Duration
Expand All @@ -42,10 +45,12 @@ type MetricFetcherOptions struct {
}

type (
MalachiteOptions struct{}
CgroupOptions struct{}
KubeletOptions struct{}
RodanOptions struct {
MalachiteOptions struct {
ServerPort int
}
CgroupOptions struct{}
KubeletOptions struct{}
RodanOptions struct {
ServerPort int
}
)
Expand All @@ -58,9 +63,11 @@ func NewMetricFetcherOptions() *MetricFetcherOptions {
DefaultInterval: time.Second * 5,
ProvisionerIntervalSecs: make(map[string]int),

MalachiteOptions: &MalachiteOptions{},
CgroupOptions: &CgroupOptions{},
KubeletOptions: &KubeletOptions{},
MalachiteOptions: &MalachiteOptions{
ServerPort: defaultMalachiteServerPort,
},
CgroupOptions: &CgroupOptions{},
KubeletOptions: &KubeletOptions{},
RodanOptions: &RodanOptions{
ServerPort: defaultRodanServerPort,
},
Expand All @@ -83,6 +90,8 @@ func (o *MetricFetcherOptions) AddFlags(fss *cliflag.NamedFlagSets) {

fs.IntVar(&o.RodanOptions.ServerPort, "rodan-server-port", o.RodanOptions.ServerPort,
"The rodan metric provisioner server port")
fs.IntVar(&o.MalachiteOptions.ServerPort, "malachite-server-port", o.MalachiteOptions.ServerPort,
"The malachite metric provisioner server port")
}

// ApplyTo fills up config with options
Expand All @@ -97,6 +106,7 @@ func (o *MetricFetcherOptions) ApplyTo(c *metaserver.MetricConfiguration) error
}

c.RodanServerPort = o.RodanOptions.ServerPort
c.MalachiteServerPort = o.MalachiteOptions.ServerPort

return nil
}
4 changes: 3 additions & 1 deletion pkg/config/agent/metaserver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ type MetricConfiguration struct {
*RodanMetricConfiguration
}

type MalachiteMetricConfiguration struct{}
type MalachiteMetricConfiguration struct {
MalachiteServerPort int
}

type CgroupMetricConfiguration struct{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
)

const (
malachiteServicePort = 9002

CgroupResource = "cgroup/groups"
CgroupPathParamKey = "cgroup_user_path"

Expand Down Expand Up @@ -53,7 +51,7 @@ type MalachiteClient struct {
fetcher pod.PodFetcher
}

func NewMalachiteClient(fetcher pod.PodFetcher) *MalachiteClient {
func NewMalachiteClient(fetcher pod.PodFetcher, malachiteServerPort int) *MalachiteClient {
urls := make(map[string]string)
for _, path := range []string{
CgroupResource,
Expand All @@ -62,7 +60,7 @@ func NewMalachiteClient(fetcher pod.PodFetcher) *MalachiteClient {
SystemComputeResource,
SystemMemoryResource,
} {
urls[path] = fmt.Sprintf("http://localhost:%d/api/v1/%s", malachiteServicePort, path)
urls[path] = fmt.Sprintf("http://localhost:%d/api/v1/%s", malachiteServerPort, path)
}

return &MalachiteClient{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestGetCgroupStats(t *testing.T) {
}))
defer server.Close()

malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{})
malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{}, 9002)
malachiteClient.SetURL(map[string]string{
CgroupResource: server.URL,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestGetPodContainerStats(t *testing.T) {
}
fetcher := &pod.PodFetcherStub{PodList: pods}

malachiteClient := NewMalachiteClient(fetcher)
malachiteClient := NewMalachiteClient(fetcher, 9002)
malachiteClient.SetURL(map[string]string{
CgroupResource: server.URL,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestGetSystemComputeStats(t *testing.T) {
server := getSystemTestServer(data)
defer server.Close()

malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{})
malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{}, 9002)
malachiteClient.SetURL(map[string]string{
SystemComputeResource: server.URL,
})
Expand All @@ -109,7 +109,7 @@ func TestGetSystemMemoryStats(t *testing.T) {
server := getSystemTestServer(data)
defer server.Close()

malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{})
malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{}, 9002)
malachiteClient.SetURL(map[string]string{
SystemMemoryResource: server.URL,
})
Expand All @@ -130,7 +130,7 @@ func TestGetSystemIOStats(t *testing.T) {
server := getSystemTestServer(data)
defer server.Close()

malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{})
malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{}, 9002)
malachiteClient.SetURL(map[string]string{
SystemIOResource: server.URL,
})
Expand All @@ -151,7 +151,7 @@ func TestGetSystemNetStats(t *testing.T) {
server := getSystemTestServer(data)
defer server.Close()

malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{})
malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{}, 9002)
malachiteClient.SetURL(map[string]string{
SystemNetResource: server.URL,
})
Expand All @@ -171,7 +171,7 @@ func TestGetSystemNonExistStats(t *testing.T) {
server := getSystemTestServer([]byte{})
defer server.Close()

malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{})
malachiteClient := NewMalachiteClient(&pod.PodFetcherStub{}, 9002)
_, err := malachiteClient.getSystemStats(100)
assert.ErrorContains(t, err, "unknown")
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ const (
)

// NewMalachiteMetricsProvisioner returns the default implementation of MetricsFetcher.
func NewMalachiteMetricsProvisioner(baseConf *global.BaseConfiguration, _ *metaserver.MetricConfiguration,
func NewMalachiteMetricsProvisioner(baseConf *global.BaseConfiguration, metricsConf *metaserver.MetricConfiguration,
emitter metrics.MetricEmitter, fetcher pod.PodFetcher, metricStore *utilmetric.MetricStore,
) types.MetricsProvisioner {
return &MalachiteMetricsProvisioner{
malachiteClient: client.NewMalachiteClient(fetcher),
malachiteClient: client.NewMalachiteClient(fetcher, metricsConf.MalachiteServerPort),
metricStore: metricStore,
emitter: emitter,
baseConf: baseConf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func Test_noneExistMetricsProvisioner(t *testing.T) {
store := utilmetric.NewMetricStore()

var err error
implement := NewMalachiteMetricsProvisioner(&global.BaseConfiguration{}, &metaserver.MetricConfiguration{}, metrics.DummyMetrics{}, &pod.PodFetcherStub{}, store)
implement := NewMalachiteMetricsProvisioner(&global.BaseConfiguration{}, &metaserver.MetricConfiguration{
MalachiteMetricConfiguration: &metaserver.MalachiteMetricConfiguration{
MalachiteServerPort: 9002,
},
}, metrics.DummyMetrics{}, &pod.PodFetcherStub{}, store)

fakeSystemCompute := &malachitetypes.SystemComputeData{
CPU: []malachitetypes.CPU{
Expand Down

0 comments on commit 16cc4a2

Please sign in to comment.