Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topograph model import for use with toposim #15

Merged
merged 10 commits into from
Oct 25, 2024
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,31 @@ systemctl disable topograph.service
systemctl daemon-reload
```

#### Testing the Service
To verify the service is running correctly, you can use the following commands:
#### Verifying Health
To verify the service is healthy, you can use the following command:

```bash
curl http://localhost:49021/healthz
```

#### Using Toposim
To test the service on a simulated cluster, first add the following line to `/etc/topograph/topograph-config.yaml` so that any topology requests are forwarded to toposim.
```bash
forward_service_url: dns:localhost:49025
```

Then run the topograph service with the following commands, choosing any of the available cluster models:
```bash
/usr/local/bin/topograph -c /etc/topograph/topograph-config.yaml -m /etc/topograph/tests/models/<cluster-model>.yaml
```

You must them start the toposim service as such, using the same cluster model:
```bash
/usr/local/bin/topograph -m ./tests/models/<cluster-model>.yaml
```

And you can verify the topology results via the following commands:
```bash
id=$(curl -s -X POST -H "Content-Type: application/json" -d '{"provider":{"name":"test"},"engine":{"name":"test"}}' http://localhost:49021/v1/generate)

curl -s "http://localhost:49021/v1/topology?uid=$id"
Expand Down
17 changes: 14 additions & 3 deletions cmd/topograph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ import (
"k8s.io/klog/v2"

"github.com/NVIDIA/topograph/pkg/config"
"github.com/NVIDIA/topograph/pkg/models"
"github.com/NVIDIA/topograph/pkg/server"
)

var GitTag string

func main() {
var c string
var m string
var version bool
flag.StringVar(&c, "c", "/etc/topograph/topograph-config.yaml", "config file")
flag.StringVar(&m, "m", "", "model file to use when using the test provider")
henryh2 marked this conversation as resolved.
Show resolved Hide resolved
flag.BoolVar(&version, "version", false, "show the version")

klog.InitFlags(nil)
Expand All @@ -47,13 +50,13 @@ func main() {
os.Exit(0)
}

if err := mainInternal(c); err != nil {
if err := mainInternal(c, m); err != nil {
klog.Errorf(err.Error())
os.Exit(1)
}
}

func mainInternal(c string) error {
func mainInternal(c string, m string) error {
cfg, err := config.NewFromFile(c)
if err != nil {
return err
Expand All @@ -63,10 +66,18 @@ func mainInternal(c string) error {
return err
}

var model *models.Model = nil
if m != "" {
model, err = models.NewModelFromFile(m)
if err != nil {
return err
}
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

server.InitHttpServer(ctx, cfg)
server.InitHttpServer(ctx, cfg, model)

var g run.Group
// Signal handler
Expand Down
3 changes: 2 additions & 1 deletion cmd/toposim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/oklog/run"
"k8s.io/klog/v2"

"github.com/NVIDIA/topograph/pkg/models"
"github.com/NVIDIA/topograph/pkg/toposim"
)

Expand All @@ -50,7 +51,7 @@ func mainInternal() error {
return fmt.Errorf("must specify topology model path and listening port")
}

model, err := toposim.NewModelFromFile(path)
model, err := models.NewModelFromFile(path)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/engines/k8s/labeler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (l *testLabeler) AddNodeLabels(_ context.Context, nodeName string, labels m
}

func TestApplyNodeLabels(t *testing.T) {
root, _ := translate.GetTreeTestSet(true)
root, _ := translate.GetTreeTestSet(nil, true)
labeler := &testLabeler{data: make(map[string]map[string]string)}
data := map[string]map[string]string{
"Node201": {"topology.kubernetes.io/network-level-1": "S2", "topology.kubernetes.io/network-level-2": "S1"},
Expand Down
11 changes: 7 additions & 4 deletions pkg/factory/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"

"github.com/NVIDIA/topograph/pkg/common"
"github.com/NVIDIA/topograph/pkg/models"
"github.com/NVIDIA/topograph/pkg/providers/aws"
"github.com/NVIDIA/topograph/pkg/providers/baremetal"
"github.com/NVIDIA/topograph/pkg/providers/cw"
Expand All @@ -48,7 +49,7 @@ func GetProvider(provider string) (common.Provider, *common.HTTPError) {
case common.ProviderBM:
prv, err = baremetal.GetProvider()
case common.ProviderTest:
prv = GetTestProvider()
prv, err = GetTestProvider()
default:
return nil, common.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("unsupported provider %q", provider))
}
Expand All @@ -60,16 +61,18 @@ func GetProvider(provider string) (common.Provider, *common.HTTPError) {
return prv, nil
}

var TestModel *models.Model = nil

type testProvider struct {
tree *common.Vertex
instance2node map[string]string
}

func GetTestProvider() *testProvider {
func GetTestProvider() (*testProvider, error) {
p := &testProvider{}
p.tree, p.instance2node = translate.GetTreeTestSet(false)
p.tree, p.instance2node = translate.GetTreeTestSet(TestModel, false)

return p
return p, nil
}

func (p *testProvider) GetCredentials(_ map[string]string) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/toposim/model.go → pkg/models/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package toposim
package models

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions pkg/toposim/model_test.go → pkg/models/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package toposim
package models

import (
"testing"
Expand All @@ -23,7 +23,7 @@ import (
)

func TestNewModelFromFile(t *testing.T) {
cfg, err := NewModelFromFile("testdata/toposim.yaml")
cfg, err := NewModelFromFile("../../tests/models/medium-h100.yaml")
require.NoError(t, err)

expected := &Model{
Expand Down
Loading
Loading