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

[specific ci=Group23-Vic-Machine-Service] syslog support added to VCH create and inspect API #6582

Merged

Conversation

AngieCris
Copy link
Contributor

@AngieCris AngieCris commented Oct 18, 2017

Fixes #6476

syslog support is now added to vic-machine create API and inspect API.

Details

  1. vic-machine create API
    POST request body includes a syslog_addr field of type string that specifies the syslog server address.
    syslog_addr must have format transport://host[:port], where transport is udp or tcp (ipv6 is not officially supported yet)
    (For example: tcp://127.0.0.1:4444)

An example of vic-machine create API request body:

{
	"name": "vch-test-1",
	"storage":{
		"image_stores":["ds://datastore1"]
	},
	"network":{
		"bridge":{
			"ip_range":"172.16.0.0/12",
			"port_group":{"name":"bridge"}
		},
		"public":{
			"port_group":{"name":"vm-network"}
		},
		"management":{
			"port_group":{"name":"management"}
		}
	},
	"auth":{
		"no_tls":true
	},
	"syslog_addr": "tcp://127.0.0.1:4444"
}
  1. vic-machine inspect API
    The response body of POST request now includes a field syslog_addr field of type string that includes the syslog server address that the user is specified when the VCH is first created.

Example vic-machine inspect GET response body:

{
  "auth": {
    "client": {
      "certificate_authorities": []
    }
  },
  "compute": {
    "cpu": {
      "shares": {
        "level": "normal"
      }
    },
    "memory": {
      "shares": {
        "level": "normal"
      }
    },
    "resource": {
      "id": "resgroup-v35"
    }
  },
  "endpoint": {
    "cpu": {
      "sockets": 1
    },
    "memory": {
      "units": "MiB",
      "value": 2048
    },
    "operations_credentials": {}
  },
  "name": "vch-test-1",
  "network": {
    "bridge": {
      "ip_range": "172.16.0.0/12",
      "port_group": {
        "id": "dvportgroup-23"
      }
    },
    "client": {
      "nameservers": [],
      "port_group": {
        "id": "dvportgroup-22"
      }
    },
    "container": [],
    "management": {
      "nameservers": [],
      "port_group": {
        "id": "dvportgroup-21"
      }
    },
    "public": {
      "nameservers": [],
      "port_group": {
        "id": "dvportgroup-22"
      }
    }
  },
  "registry": {
    "blacklist": null,
    "certificate_authorities": [],
    "insecure": [],
    "whitelist": []
  },
  "runtime": {
    "admin_portal": "https://10.160.213.153:2378",
    "docker_host": "10.160.213.153:2375",
    "power_state": "poweredOn",
    "upgrade_status": "Up to date"
  },
  "storage": {
    "base_image_size": {
      "units": "KiB",
      "value": 8000000
    },
    "image_stores": [
      "ds://datastore1/vch-test-1"
    ],
    "volume_stores": []
  },
  "syslog_addr": "tcp://127.0.0.1:4444",
  "version": "v1.2.0-rc1-0-a3b3132"
}

Remaining work
Pending integration tests that checks if syslog server configuration on create and inspect, and unit tests.
Will be integrated after create API test and inspect API test are ready.
(tracking story: #6018 )

@andrewtchin
Copy link
Contributor

Are there any unit or integration tests required for this?

@AngieCris
Copy link
Contributor Author

AngieCris commented Oct 18, 2017

@andrewtchin yes but not implemented yet. Since it's part of VCH create and inspect APIs (part of create API handler input and inspect API output), I would expect the tests be included in the create API and inspect API tests (I'm not sure how to test this separately

Copy link
Contributor

@mdharamadas1 mdharamadas1 left a comment

Choose a reason for hiding this comment

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

lgtm, pls make sure to track somewhere to add integration test for this later as in desc.

"syslog_addr": {
"type": "string",
"format": "uri",
"pattern": "^(tc|ud)p.*"
Copy link
Member

Choose a reason for hiding this comment

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

The documentation on SysLogConfig (in container_vm.go) says "Network can be udp, tcp, udp6, or tcp6". I think we should add the optional "6" to this regex.

Copy link
Contributor Author

@AngieCris AngieCris Oct 19, 2017

Choose a reason for hiding this comment

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

actually from the output of vic-machine-linux create -x | grep syslog:

--syslog-address value                           Address of the syslog server to send Virtual Container Host logs to. Must be in the format transport://host[:port], where transport is udp or tcp.

It seems like only "udp" or "tcp" transport is supported.
I modified the swagger tried with address tcp6://127.0.0.1:4444, it won't go into vchConfig, so even if build succeeds, inspect won't give it as output.

Copy link
Contributor Author

@AngieCris AngieCris Oct 19, 2017

Choose a reason for hiding this comment

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

https://github.com/vmware/vic/blob/master/lib/install/validate/validator.go#L860
Here in validator, only udp and tcp transport goes into config. It doesn't accept anything else
Not sure if it's a bug...
@zjs

Copy link
Contributor Author

@AngieCris AngieCris Oct 20, 2017

Choose a reason for hiding this comment

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

confirmed with @hmahmood that ipv6 is not officially supported by syslogs yet. So we'll go with ^(tc|ud)p for now

@@ -79,7 +80,7 @@ func (h *VCHCreate) Handle(params operations.PostTargetTargetVchParams, principa

validator, err := validateTarget(params.HTTPRequest.Context(), d)
if err != nil {
return operations.NewPostTargetTargetVchDefault(400).WithPayload(&models.Error{Message: err.Error()})
return operations.NewPostTargetTargetVchDefault(http.StatusBadRequest).WithPayload(&models.Error{Message: err.Error()})
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a really good change. Can you file an issue so that we remember to clean this up in the rest of the handlers?

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 can do it in this pr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixes done

}
}
}

if len(vch.SyslogAddr) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Other places in this handler, we seem to be checking != "". I don't know which pattern is better, but I think it would be good to be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

!= "" makes more sense.
I was still in the java mindset that strings cannot be directly compared with equals

if err := c.ProcessSyslog(); err != nil {
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error processing syslog server address: %s", err))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't you write a simple unit test to verify these new code paths?

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 part of the create API handler and we haven't figured out a pattern to do unit tests on swagger handlers yet.
The new code path validates a field in http GET request JSON, and it's very hard to test it separately from all the other fields related to vch create params.
We're planning to integrate this in unit tests for create API as a whole (the tracking story is: #6018)

@AngieCris AngieCris merged commit 7008981 into vmware:feature/vic-machine-service Oct 24, 2017
zjs pushed a commit that referenced this pull request Oct 25, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit that referenced this pull request Oct 31, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit that referenced this pull request Nov 6, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit that referenced this pull request Nov 6, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit that referenced this pull request Nov 6, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit to zjs/vic that referenced this pull request Nov 7, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit to zjs/vic that referenced this pull request Nov 7, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit that referenced this pull request Nov 15, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit that referenced this pull request Nov 16, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
zjs pushed a commit that referenced this pull request Nov 20, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
AngieCris added a commit to AngieCris/vic that referenced this pull request Nov 20, 2017
* syslog support added to VCH create API

* syslog addr added to inspect output

* syslog_addr format changed in swagger

* use status code in http package

* empty syslog_addr string checking

* swagger format changed for syslog_addr

* roll back in swagger: only tcp and udp are accepted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants