Skip to content

Commit

Permalink
【OSCP】 Kuscia 集成引擎 Metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuiguang49 committed Jul 19, 2024
1 parent 5a77f57 commit 0af6c4e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cmd/kuscia/modules/metricexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/secretflow/kuscia/pkg/metricexporter"
"github.com/secretflow/kuscia/pkg/metricexporter/envoyexporter"
"github.com/secretflow/kuscia/pkg/utils/nlog"
"github.com/secretflow/kuscia/pkg/utils/readyz"
)

Expand Down Expand Up @@ -66,7 +67,7 @@ func NewMetricExporter(i *ModuleRuntimeConfigs) (Module, error) {
exporter.metricURLs["app-metrics"] = labelsURL
}

return exporter
return exporter, nil
}

func (exporter *metricExporterModule) Run(ctx context.Context) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (cr *configRender) handleSyncPodContext(ctx *hook.K8sProviderSyncPodContext
}
}

data, err := cr.makeDataMap(ctx.Pod.Annotations,pod.Labels, envs)
data, err := cr.makeDataMap(ctx.Pod.Annotations, pod.Labels, envs)
if err != nil {
return err
}
Expand Down Expand Up @@ -217,7 +217,7 @@ func (cr *configRender) handleMakeMountsContext(ctx *hook.MakeMountsContext) err
envs[env.Name] = env.Value
}

data, err := cr.makeDataMap(ctx.Pod.Annotations,ctx.Pod.Labels envs)
data, err := cr.makeDataMap(ctx.Pod.Annotations, ctx.Pod.Labels, envs)
if err != nil {
return err
}
Expand Down Expand Up @@ -432,4 +432,4 @@ func buildStructMap(value map[string]string) map[string]interface{} {
}

return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func TestBuildStructMap_WithStruct(t *testing.T) {
"TASK_ID": "abc",
"TASK_CLUSTER_DEFINE": string(taskInputConfigBytes),
}
data, err := cr.makeDataMap(map[string]string{}, envs)
data, err := cr.makeDataMap(map[string]string{}, map[string]string{}, envs)
assert.NoError(t, err)
t.Logf("%+v", data)

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/kusciatask/handler/pending_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1226,4 +1226,4 @@ func (h *PendingHandler) submitTaskResourceGroup(trg *kusciaapisv1alpha1.TaskRes
}

return nil
}
}
2 changes: 1 addition & 1 deletion pkg/crd/apis/kuscia/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type IngressPort struct {

type MetricProbe struct {
Path string `json:"path,omitempty"`
Port uint16 `json:"port,omitempty"`
Port uint16 `json:"port,omitempty"`
}

// PodSpec defines the spec info of pod.
Expand Down
5 changes: 2 additions & 3 deletions pkg/metricexporter/metricexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func BuildMetricURL(baseURL string, labels map[string]string) (string, error) {
return fullURL, nil
}


func metricHandler(fullURLs []string, w http.ResponseWriter) {
metricsChan := make(chan []byte, len(fullURLs))
var wg sync.WaitGroup
Expand Down Expand Up @@ -129,7 +128,7 @@ func MetricExporter(ctx context.Context, metricURLs map[string]string, port stri
nlog.Infof("Start to export metrics on port %s...", port)
var fullURLs []string
for _, baseURL := range metricURLs {
fullURLs = append(fullURLs, baseURL)
fullURLs = append(fullURLs, baseURL)
}

metricServer := http.NewServeMux()
Expand All @@ -139,7 +138,7 @@ func MetricExporter(ctx context.Context, metricURLs map[string]string, port stri

go func() {
nlog.Infof("Starting metric server on port %s", port)

if err := http.ListenAndServe("0.0.0.0:"+port, metricServer); err != nil {
nlog.Error("Fail to start the metric exporterserver", err)
}
Expand Down

0 comments on commit 0af6c4e

Please sign in to comment.