Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

feat: add support for common v2 endpoints (ping/metrics/version/config) #413

Merged
merged 1 commit into from
Sep 17, 2021

Conversation

siggiskulason
Copy link

@siggiskulason siggiskulason commented Sep 8, 2021

feat: add support for common v2 endpoints (ping/metrics/version/config)

This commit adds v2 (Ireland/Jakarta) support for four common endpoints:

  • version
  • metrics
  • ping
  • config

For information about the available commands, use edgex-cli -h

There are a number of ways to use the commands:

  1. edgex-cli version displays version of each active microservice.
    The version commands just shows the version string. The other commands
    use a pretty-printed JSON structure (config) or a table (metrics).
$ edgex-cli version
EdgeX CLI version:  1.0.0-dev.9
core-metadata: 2.0.0-2
core-data: 2.0.0-2
core-command: 2.0.0-2

$ edgex-cli metrics
Service       CpuBusyAvg MemAlloc MemFrees MemLiveObjects MemMallocs MemSys   MemTotalAlloc
core-command  14         1572240  50446    8839           59285      75318280 11463128
core-metadata 14         1757440  56371    9918           66289      75318280 12001840
core-data     14         1691984  56145    9551           65696      75318280 11903936

$ edgex-cli config
core-metadata:
{
    "Clients": {
        "core-data": {
            "Host": "localhost",
            "Port": 59880,
            "Protocol": "http"
        },
...

  1. edgex-cli version -d shows debug output - the URL used and the result
$ edgex-cli ping -d
core-metadata: http://localhost:59881/api/v2/ping: {"apiVersion":"v2","timestamp":"Fri Sep 10 16:17:44 BST 2021"}
core-data: http://localhost:59880/api/v2/ping: {"apiVersion":"v2","timestamp":"Fri Sep 10 16:17:44 BST 2021"}
core-command: http://localhost:59882/api/v2/ping: {"apiVersion":"v2","timestamp":"Fri Sep 10 16:17:44 BST 2021"}
core-scheduler: : Get "http://localhost:59861/api/v2/ping": dial tcp 127.0.0.1:59861: connect: connection refused
core-notification: : Get "http://localhost:59860/api/v2/ping": dial tcp 127.0.0.1:59860: connect: connection refused
device-modbus: : Get "http://localhost:59901/api/v2/ping": dial tcp 127.0.0.1:59901: connect: connection refused
device-camera: : Get "http://localhost:59985/api/v2/ping": dial tcp 127.0.0.1:59985: connect: connection refused
device-mqtt: : Get "http://localhost:59982/api/v2/ping": dial tcp 127.0.0.1:59982: connect: connection refused
device-rest: : Get "http://localhost:59986/api/v2/ping": dial tcp 127.0.0.1:59986: connect: connection refused
rules-engine: : Get "http://localhost:59701/api/v2/ping": dial tcp 127.0.0.1:59701: connect: connection refused
http-export: : Get "http://localhost:59704/api/v2/ping": dial tcp 127.0.0.1:59704: connect: connection refused
mqtt-export: : Get "http://localhost:59703/api/v2/ping": dial tcp 127.0.0.1:59703: connect: connection refused
functional-tests: : Get "http://localhost:59705/api/v2/ping": dial tcp 127.0.0.1:59705: connect: connection refused
push-to-core: : Get "http://localhost:59702/api/v2/ping": dial tcp 127.0.0.1:59702: connect: connection refused
  1. edgex-cli version -j gets the raw JSON output for one service (by default core-data)
$ edgex-cli metrics -j
{"apiVersion":"v2","metrics":{"memAlloc":1755096,"memFrees":1008594,"memLiveObjects":9980,"memMallocs":1018574,"memSys":75580424,"memTotalAlloc":327693144,"cpuBusyAvg":11}}

It's possible to specify the service to use: -m/--metadata, -c/--command, -n/--notification, -s/--scheduler or --data (which is the default). This can also be combined with -j or -d

$ edgex-cli metrics -j -m
{"apiVersion":"v2","metrics":{"memAlloc":1709440,"memFrees":1008937,"memLiveObjects":9468,"memMallocs":1018405,"memSys":75580424,"memTotalAlloc":327792520,"cpuBusyAvg":10}}
$ edgex-cli ping -d -c
core-command: http://localhost:59882/api/v2/ping: {"apiVersion":"v2","timestamp":"Fri Sep 10 16:20:55 BST 2021"}

Help is available with

$ edgex-cli help
$ edgex-cli version --help
$ edgex-cli version --h

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/edgex-cli/blob/master/.github/Contributing.md.

What is the current behavior?

edgex-cli does not currently support the V2 API.

Issue Number:

What is the new behavior?

This PR adds support in edgex-cli for the common V2 endpoints.

Does this PR introduce a breaking change?

  • Yes
  • No

New Imports

  • Yes
  • No

Specific Instructions

Are there any specific instructions or things that should be known prior to reviewing?

Other information

@siggiskulason siggiskulason self-assigned this Sep 8, 2021
@siggiskulason siggiskulason marked this pull request as draft September 8, 2021 11:06
@siggiskulason siggiskulason changed the title feat: Add v2 API support (WIP - do not merge) feat: Add v2 API support (WIP) Sep 8, 2021
@siggiskulason siggiskulason force-pushed the add-v2-features branch 5 times, most recently from 76247c6 to 47cc250 Compare September 10, 2021 15:16
@siggiskulason siggiskulason changed the title feat: Add v2 API support (WIP) feat: add support for common v2 endpoints (ping/metrics/version/config) Sep 15, 2021
@siggiskulason siggiskulason force-pushed the add-v2-features branch 5 times, most recently from 65177ad to 6f5e1c7 Compare September 15, 2021 09:46
@siggiskulason siggiskulason marked this pull request as ready for review September 15, 2021 09:54
Makefile Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
internal/cmd/common.go Outdated Show resolved Hide resolved
internal/cmd/common.go Outdated Show resolved Hide resolved
internal/service/service.go Outdated Show resolved Hide resolved
internal/service/service.go Outdated Show resolved Hide resolved
internal/service/service.go Show resolved Hide resolved
snap/local/runtime-helpers/bin/edgex-cli-wrapper.sh Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@siggiskulason siggiskulason force-pushed the add-v2-features branch 3 times, most recently from 8e20155 to add7721 Compare September 16, 2021 11:30
@siggiskulason
Copy link
Author

Thank you very much @lenny-intel for the helpful comments. I have responded to them inline, updated the code, force-pushed an update and marked the comments as resolved.

Makefile Outdated Show resolved Hide resolved
internal/cmd/common.go Outdated Show resolved Hide resolved
internal/cmd/config.go Outdated Show resolved Hide resolved
internal/cmd/metrics.go Outdated Show resolved Hide resolved
internal/cmd/ping.go Outdated Show resolved Hide resolved
internal/format/format.go Outdated Show resolved Hide resolved
internal/format/format.go Outdated Show resolved Hide resolved
@siggiskulason
Copy link
Author

Hi @lenny-intel - thanks again for your review. I have responded to all your comments and made some changes - I removed the format package and also for metrics added the SDK method to get the metrics - which I then print out in a table, rather than printing out the JSON result. I still print out the config as a JSON for now at least, as that can have an hierarchical structure - and I just get the raw JSON for version/ping. For the other methods I'm now starting to add I'm using the SDK functions. I've force-pushed the changes and marked your comments as resolved.

This commit adds v2 (Ireland/Jakarta) support for four common endpoints:
- version
- metrics
- ping
- config

For information about the available commands, use `edgex-cli -h`

There are a number of ways to use the commands:
1. `edgex-cli version` displays version of each active microservice.
The version commands just shows the version string. The other commands
use a pretty-printed JSON structure.

2. `edgex-cli version -d` shows debug output - the URL used and the result

3. `edgex-cli version -j` gets the raw JSON output for one service (by default core-data)

It's also possible to specify the service to use. : `-m/--metadata`, `-c/--command`,
 `-n/--notification`, `-s/--scheduler` or `--data` (which is the default).
This can also be combined with `-j` or `-d`

Example:
- `$ edgex-cli metrics -j -m`
- `$ edgex-cli ping -d --command`

Help is available with
```
$ edgex-cli help
$ edgex-cli version --help
$ edgex-cli version --h
```

Signed-off-by: Siggi Skulason <siggi.skulason@canonical.com>
Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

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

LGTM

@siggiskulason siggiskulason merged commit 44caba8 into edgexfoundry:main Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants