Skip to content

ESD-889: Add telemetry to Port, MCR, MVE, VXC, and IX services - #150

Open
Phil-Browne wants to merge 20 commits into
mainfrom
feature/ESD-889-service-telemetry
Open

ESD-889: Add telemetry to Port, MCR, MVE, VXC, and IX services#150
Phil-Browne wants to merge 20 commits into
mainfrom
feature/ESD-889-service-telemetry

Conversation

@Phil-Browne

@Phil-Browne Phil-Browne commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Adds GetVXCTelemetry, GetPortTelemetry, GetMCRTelemetry, GetMVETelemetry, and GetIXTelemetry to their respective services, backed by the /v2/product/{type}/{uid}/telemetry endpoints. All methods share the same parameter shape (metric types, optional time range or day count) and reuse the existing ServiceTelemetryResponse type. Validation and fetching are shared with the existing NAT Gateway telemetry via a common helper.

Valid metric types per service (documented, not enforced client-side; the API rejects an invalid type):

  • VXC: A_BITS, B_BITS, A_PACKETS, B_PACKETS
  • Port: BITS, PACKETS, ERRORS, OPTICAL, OPTICAL_100G, SUBSCRIBED_SPEED, SERVICE_COUNT
  • MCR: BITS, PACKETS, ERRORS, SPEED, BYTES_RATE, BYTES_VOLUME, OPTICAL, OPTICAL_100G
  • MVE: BITS, PACKETS, ERRORS
  • IX: BITS, PACKETS, ROUTES_IMPORTED, ROUTES_FILTERED, BM_BYTES, BM_PACKETS, UU_BYTES, UU_PACKETS

A null value in a [timestamp, value] sample tuple decodes as zero rather than failing the whole series. The API emits null when a metric has no reading at a timestamp, and its own aggregation reads null as zero, so one gap no longer empties a response.

Sharing the validation helper also tightens NAT Gateway telemetry: it now rejects a from after to and a range over 180 days, neither of which the old NAT-specific validator checked. Existing NAT Gateway behavior is otherwise unchanged.

Part of ESD-889.

@Phil-Browne Phil-Browne changed the title ESD-889: Add telemetry to Port, MCR, MVE, and IX services ESD-889: Add telemetry to VXC, Port, MCR, MVE, and IX services Apr 25, 2026
@Phil-Browne Phil-Browne changed the title ESD-889: Add telemetry to VXC, Port, MCR, MVE, and IX services ESD-898: Add telemetry to Port, MCR, MVE, and IX services Apr 25, 2026
@Phil-Browne
Phil-Browne requested a review from Copilot April 26, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class SDK support for retrieving telemetry metrics for additional Megaport product types (VXC, Port, MCR, MVE, IX) via the /v2/product/{type}/{uid}/telemetry endpoints, reusing the shared ServiceTelemetryResponse model.

Changes:

  • Introduces Get*Telemetry request types + validation errors for VXC/Port/MCR/MVE/IX.
  • Adds Get*Telemetry methods to each corresponding service interface + implementation to call the telemetry endpoints with shared query parameters (type, days or from/to).
  • Adds unit tests covering happy-path responses and parameter validation for each service.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
vxc_types.go Adds GetVXCTelemetryRequest and VXC telemetry validation errors.
vxc.go Adds GetVXCTelemetry to VXCService, plus request validation and endpoint call.
vxc_test.go Adds tests for VXC telemetry retrieval and validation.
port_types.go Adds GetPortTelemetryRequest and Port telemetry validation errors.
port.go Adds GetPortTelemetry to PortService, plus request validation and endpoint call.
port_test.go Adds tests for Port telemetry retrieval, from/to variant, and validation.
mve_types.go Adds GetMVETelemetryRequest and MVE telemetry validation errors.
mve.go Adds GetMVETelemetry to MVEService, plus request validation and endpoint call.
mve_test.go Adds tests for MVE telemetry retrieval, from/to variant, and validation.
mcr_types.go Adds GetMCRTelemetryRequest and MCR telemetry validation errors.
mcr.go Adds GetMCRTelemetry to MCRService, plus request validation and endpoint call.
mcr_test.go Adds tests for MCR telemetry retrieval, from/to variant, and validation.
ix_types.go Adds GetIXTelemetryRequest and IX telemetry validation errors.
ix.go Adds GetIXTelemetry to IXService, plus request validation and endpoint call.
ix_test.go Adds tests for IX telemetry retrieval, from/to variant, and validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mcr_test.go Outdated
Comment thread vxc.go Outdated
Comment thread port.go Outdated
Comment thread mcr.go Outdated
Comment thread vxc_test.go
Comment thread vxc.go Outdated
Comment thread mve.go Outdated
Comment thread ix.go Outdated
Comment thread port_test.go Outdated
Comment thread mve_test.go Outdated
- Add nil-request guard to all five validate functions (VXC, Port, MCR,
  MVE, IX) with new Err*TelemetryRequestRequired sentinel errors; avoids
  nil-pointer dereference when caller passes nil
- Use PRODUCT_* constants in telemetry URL paths instead of hardcoded
  strings to prevent drift if path segments change
- Add To-without-From validation test to all five service test suites
- Add nil-request validation test to all five service test suites
- Add TestGetVXCTelemetryFromTo happy-path test for the from/to time
  range query parameters

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mve.go
Comment thread mcr.go
Comment thread ix.go
Comment thread nat_gateway_types.go Outdated
Comment thread vxc.go
Comment thread port.go
ServiceTelemetryResponse, TelemetryTimeFrame, TelemetryMetricData,
TelemetrySample, TelemetryUnit, and the TelemetrySample.UnmarshalJSON
method were defined in nat_gateway_types.go but are used by Port, MCR,
MVE, VXC, and IX services. Move them to shared_types.go so their
cross-service scope is clear and they are easy to discover.
@Phil-Browne

Copy link
Copy Markdown
Contributor Author

Addressing Copilot review feedback

Breaking interface changes (intentional): Adding GetPortTelemetry, GetMCRTelemetry, GetMVETelemetry, GetIXTelemetry, and GetVXCTelemetry to their respective exported service interfaces is a breaking change. This is intentional — the SDK is pre-v1 and the methods belong on the primary service interfaces alongside existing operations. Consumers implementing/mocking these interfaces will need to add the new method. A separate telemetry interface would add unnecessary fragmentation for a pre-v1 library.

Shared telemetry types moved to shared_types.go: ServiceTelemetryResponse, TelemetryTimeFrame, TelemetryMetricData, TelemetrySample, TelemetryUnit, and TelemetrySample.UnmarshalJSON have been moved from nat_gateway_types.go to shared_types.go. They are now co-located with other cross-service shared types, making them easy to discover. nat_gateway_types.go retains only NAT-Gateway-specific types.

All unit tests pass after the refactor.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vxc.go Outdated
Comment thread port.go Outdated
Comment thread mve.go Outdated
Comment thread mcr.go Outdated
Comment thread ix.go Outdated
@Phil-Browne

Copy link
Copy Markdown
Contributor Author

Addressed Copilot feedback: added resp.Body close on error path in all five GetXTelemetry functions (GetVXCTelemetry, GetPortTelemetry, GetMVETelemetry, GetMCRTelemetry, GetIXTelemetry).

client.Do does not close the body before returning an error (it leaves the body open after CheckResponse fails), so the guard is a real fix. The pattern applied:

if err != nil {
    if resp != nil && resp.Body != nil {
        resp.Body.Close()
    }
    return nil, err
}
defer resp.Body.Close()

Commit: 6ddc966. All unit tests pass.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ix.go
Comment thread shared_types.go Outdated
Comment thread mcr.go
@Phil-Browne

Copy link
Copy Markdown
Contributor Author

Acknowledging Copilot's flags on GetIXTelemetry (IXService) and GetMCRTelemetry (MCRService) as breaking interface changes.

These additions are intentional. The SDK is pre-v1, and adding methods to interfaces is an accepted practice at this stage — consistent with the same decision made for GetPortTelemetry, GetVXCTelemetry, and GetMVETelemetry in this same PR. Any implementors of these interfaces are internal to the SDK itself, so there is no external breakage in practice.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Phil-Browne
Phil-Browne marked this pull request as ready for review April 26, 2026 17:55
@Phil-Browne
Phil-Browne requested review from a team and mola-dev and removed request for a team May 28, 2026 12:42
@Phil-Browne Phil-Browne reopened this May 29, 2026
…ce-telemetry

# Conflicts:
#	ix.go
#	ix_test.go
#	mcr_test.go
#	port_test.go
#	vxc_test.go
Replace six near-identical validate+fetch implementations with a shared
validateTelemetryRequest/fetchTelemetry pair, keeping each service's
public sentinel errors. Also validate that from precedes to and the
range stays within the API's 180-day limit, name the service in
sentinel messages, complete the documented metric types for Port and
IX, drop a stray omitempty on the response-only PeerUID field, and
replace deprecated reflect.Ptr with reflect.Pointer.
@Phil-Browne Phil-Browne changed the title ESD-898: Add telemetry to Port, MCR, MVE, and IX services ESD-889: Add telemetry to Port, MCR, MVE, VXC, and IX services Jul 15, 2026
Every telemetry test mocked a 2xx response, so the non-2xx and
malformed-JSON paths in the shared fetchTelemetry helper were
untested. Add one API-error test per service plus one malformed-JSON
test covering the shared decode path.

The per-service "valid values" doc comments read as if the SDK
enforces membership; it only checks Types is non-empty. Note that the
list isn't validated client-side rather than adding validation that
would restate the upstream contract.
A null value in a [timestamp, value] tuple failed the decode of the
whole series, so one gap in a metric emptied the response. The API emits
null when a metric has no reading at a timestamp, and its own
aggregation reads that as zero, so the decode now matches.

Adds sample decode tests, including a null in the middle of a series,
and aligns the VXC Types doc comment with its siblings.
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.

2 participants