Skip to content

Conversation

josecelano
Copy link
Member

Relates to:

This is only a Proof of Concept.

It adds a new REST API endpoint with a new extendable format for metrics:

URL: http://0.0.0.0:1212/api/v1/metrics?token=MyAccessToken

Sample response:

{
  "labeled_metrics": [
    {
      "metric": {
        "name": "announce_requests_received_total",
        "kind": "counter",
        "value": 1
      },
      "labels": {
        "ip_version": "ipv4",
        "protocol": "http",
        "url": "http://0.0.0.0:7070"
      }
    },
    {
      "metric": {
        "name": "scrape_requests_received_total",
        "kind": "counter",
        "value": 1
      },
      "labels": {
        "ip_version": "ipv4",
        "protocol": "http",
        "url": "http://0.0.0.0:7070"
      }
    }
  ]
}

It only supports JSON format for now. It doesn't support Prometheus format like the current stats endpoint:

URL: http://0.0.0.0:1212/api/v1/stats?token=MyAccessToken&format=prometheus

The Prometheus format response should be like the following:

announce_requests_received_total{ ip_version="ipv4", protocol="http", url="http://0.0.0.0:7070"} 1

scrape_requests_received_total{ ip_version="ipv4", protocol="http", url="http://0.0.0.0:7070"} 1

TODO

  • Replace primitive types in the new labeled metrics with new tpyes to enforce constraints. For example, metrics names, labels, metric types, etc.
  • Inject the rigth URL scheme. It's hardcoded now.
  • Implement for UDP metrics. It's only implemented for HTTP tracker metrics. This would require merging labeled metrics.
  • Use a f64 for metric values instead of u64.
  • The metric name and label set pair must be unique in the array of labeled metrics. Enforce constraint.
  • Implement versioning. A given API version must contain a set of labeled metrics. Clients expects some labeled metrics to be included in a API version. We need to initialize the array of metrics with all the expected labeled metrics with the initial value.
  • Review names for fields in the API response. For example rename url to server_url, ...
  • Review what labels we include per metric. For example the "protocol" label can be derived from the URL but it requires parsing the URL and it makes harder to build graphs in Grafana. I guess we should include labels for the type of aggregate date we want to get.

IMPORTANT

@da2ce7 it would be nice to have feedback before continuing working on this approach.

This is only a Prood of Concept.

It adds a new  REST API endpoint with a new format for metrics:

URL: http://0.0.0.0:1212/api/v1/metrics?token=MyAccessToken

Sample response:

```json
{
  "labeled_metrics": [
    {
      "metric": {
        "name": "announce_requests_received_total",
        "kind": "counter",
        "value": 1
      },
      "labels": {
        "ip_version": "ipv4",
        "protocol": "http",
        "url": "http://0.0.0.0:7070"
      }
    },
    {
      "metric": {
        "name": "scrape_requests_received_total",
        "kind": "counter",
        "value": 1
      },
      "labels": {
        "ip_version": "ipv4",
        "protocol": "http",
        "url": "http://0.0.0.0:7070"
      }
    }
  ]
}
```

It only supports JSON format for now. It doesn't support prometheus
format like the current stats endpoint:

URL: http://0.0.0.0:1212/api/v1/stats?token=MyAccessToken&format=prometheus

TODO:

- Replace primitive types in the new labeled metrics with new tpyes to
  enforce constraints. For example, metrics names, labels, metric types, etc.
- Inject the rigth URL scheme. It's hardcoded now.
- Implement for UDP metrics. It's only implemented for HTTP tracker metrics. This would require mergin labeled metrics.
- Use a f64 for metric values instead of u64.
- The metric name and label set pair must be unique in the array of
  labeled metrics. Enforce
  constraint.
- Implement versioning. A given API version must contain a set of
  labeled metrics. Clients expects some labeled metrics to be included
in a API version. We need to initialize the array of metrics with all
the expected labeled metrics with the initial value.
@josecelano
Copy link
Member Author

I have continued with the implementation of the POC here.

@josecelano josecelano closed this Mar 31, 2025
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.

1 participant