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

many features and improvements #22

Merged
merged 5 commits into from
Jul 2, 2024
Merged

many features and improvements #22

merged 5 commits into from
Jul 2, 2024

Conversation

aajkl
Copy link
Contributor

@aajkl aajkl commented Jul 1, 2024

  1. support ceph rbd
  2. support ovn
  3. support cloud-init
  4. merge eru agent
  5. many other improvements and bugfix

aajkl added 2 commits July 1, 2024 13:28
1. support ceph rbd
2. support ovn
3. support cloud-init
4. merge eru agent
5. many other improvements and bugfix
@@ -5,13 +5,13 @@ import (

"github.com/BurntSushi/toml"

"github.com/projecteru2/yavirt/pkg/errors"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, why not wraps the cockroachdb/errors within yavirt/pkg/errors, then don't need to change anything from upper pkgs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using upstream package directly is enough and adding a thin wrapper is needless. actually I just want to unify the log and errors pkg of core,yavirt and some components developed by me.

labels[parts[0]] = parts[1]
}
go func() {
// Core need to connect to the local grpc server, so sleep 30s here to wait local grpc server up
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sending a ping packet to be more graceful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping what? local machine? sleeping 30s is enough here, it is more simple and works well

logger.Error(ctx, err, "failed to add node")
return
}
if e.Code() == 1031 && strings.Contains(e.Message(), "node already exists") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defines a var for (hardcoded) 1031 should be a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I'll fix this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these code numbers are from core, I just don't want to import too many dependencies, but I just read code and it's ok to import core here.

}
}

f1 := utils.CheckHTTP(ctx, g.ID, httpChecker, healthCheck.HTTPCode, timeout)
Copy link
Contributor

@anrs anrs Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about shortcut here for saving cpu/bandwidth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is specified by user and when checker list is empty, checkHTTP do nothing

func (e *MetricsCollector) Collect(ch chan<- prometheus.Metric) {
for _, v := range e.wrkStatusCache.Items() {
wrkStatus, _ := v.Object.(*types.WorkloadStatus)
if !wrkStatus.Running {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer to check wrkStatus if is nil in the first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a check here, actually wrkStatus never be nil here

logger.Warn(ctx, "service is not healthy")
return
}
if err := m.store.CheckHealth(ctx); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about

m.mCol.coreHealthy.Store(m.store.CheckHealth(ctx) == nil)

for removing the if/else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I'll add a log message

tick := time.NewTicker(time.Duration(m.config.HealthCheck.Interval) * time.Second)
defer tick.Stop()

_ = utils.Pool.Submit(func() { m.checkAllWorkloads(ctx) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove _ = part from the statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing _= will cause a lint issue

for {
select {
case <-tick.C:
_ = utils.Pool.Submit(func() { m.checkAllWorkloads(ctx) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can remove the _ = part

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}

for _, workloadID := range workloadIDs {
ID := workloadID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add comment to explain why we define a new var here.
(im not sure if is fixed the bug in golang higher version, if so, we can remove the new var)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is copied from agent, https://github.com/projecteru2/agent/blob/master/manager/workload/health_check.go#L41 I also don't know why defining a new var, I'll delete this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't be deleted because of https://go.dev/blog/loopvar-preview

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, just use for idx := range workloadIDs and define a new var in loop, so it's not that strange.


for _, workloadID := range workloadIDs {
ID := workloadID
_ = utils.Pool.Submit(func() { m.checkOneWorkload(ctx, ID) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont need to _ = part


m.wrkStatusCache.Set(workloadStatus.ID, workloadStatus, 0)

if err = m.setWorkloadStatus(ctx, workloadStatus); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer to a brand-new err := here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, this is also from agent

"github.com/projecteru2/yavirt/internal/utils"
"github.com/projecteru2/yavirt/internal/utils/notify/bison"
"github.com/samber/lo"
"google.golang.org/grpc/status"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer to group/separate pkgs from 3rd and yavirt

log.Debugf(ctx, "[recycle] notifier: %v", notifier)
if notifier != nil {
msgList := []string{
"<font color=#00CC33 size=10>delete dangling successfully </font>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about defining a template snippet here?


coreIDs, err := fetchWorkloads()
if err != nil {
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to log the err but not found kind

continue
}
coreMap := map[string]struct{}{}
for _, id := range coreIDs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we utilize the lo.Map

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lo.Map returns slice and here is a map and i think for-loop is more intuitive here

}
}

func Setup(ctx context.Context, cfg *configs.Config, t *testing.T) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer to call this Setup and pass the store instance from unit test files

defer cm.mu.Unlock()
for resName, rawParams := range capacity {
switch resName {
case "cpumem":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strongly rec constants rather than literal in the switch/case

if ans != nil {
return
}
cm.fetchResources()
Copy link
Contributor

@anrs anrs Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to fetchResourcesWithLock or FetchResources (with lock implicitly)
i'd like to the former and

func (cm *CoreResourcesManager) GetCpumem() (ans *cpumemtypes.NodeResource) {
  cm.mu.Lock()
  defer cm.mu.Unlock()
  ...
}

only once

if err := json.Unmarshal([]byte(gpuNameJSON), &gpuNameMap); err != nil {
return err
}
// merge name map from config to gpuNameMap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lo.Map would help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for-loop is very intuitive here, using functional style code here don't have any advantages.

DefaultGW CloudInitGateway `json:"-"`
}

func initTpls() (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about func init() then we can remove all the if xxx == nil from the func

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or sync.Once(initTpls)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like init, I always run initialization code explicitly, sync.Once seems good

@aajkl aajkl force-pushed the master branch 2 times, most recently from fc7746f to 28a6c2f Compare July 1, 2024 12:38
@anrs
Copy link
Contributor

anrs commented Jul 2, 2024

@aajkl can be merged after lint fixing

@aajkl
Copy link
Contributor Author

aajkl commented Jul 2, 2024

@anrs done

@CMGS CMGS merged commit 377de40 into projecteru2:master Jul 2, 2024
2 checks passed
CMGS pushed a commit that referenced this pull request Jul 2, 2024
* many features and improvements
1. support ceph rbd
2. support ovn
3. support cloud-init
4. merge eru agent
5. many other improvements and bugfix

* fix lint and ut issues

* fix review issues

* don't return when check imageHub failed

* remove fmt.Printf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants