#environment #detecting #compute #detector #detect #different #apollo

apollo-environment-detector

Library for detecting different compute environments

1 unstable release

0.1.0 Oct 31, 2024

#797 in Network programming

Download history 70/week @ 2024-10-25 54/week @ 2024-11-01 6/week @ 2024-11-08 5/week @ 2024-11-15 4/week @ 2024-11-22 305/week @ 2024-11-29 507/week @ 2024-12-06 644/week @ 2024-12-13 353/week @ 2024-12-20 284/week @ 2024-12-27 507/week @ 2025-01-03 597/week @ 2025-01-10 1025/week @ 2025-01-17 795/week @ 2025-01-24 850/week @ 2025-01-31 884/week @ 2025-02-07

3,699 downloads per month
Used in 3 crates (via apollo-router)

MIT OR Elastic-2.0

46KB
1K SLoC

apollo-environment-detector

CircleCI

This library provides two functions for easily detecting a ComputeEnvironment based on a given weighted threshold.

[dependencies]
apollo-environment-detector = "0.1"

Usage

use apollo_environment_detector::{detect, detect_one, MAX_INDIVIDUAL_WEIGHTING};

// Attempt to detect multiple environments based on a weighting.
let compute_envs = detect(MAX_INDIVIDUAL_WEIGHTING);
println!("{:?}", compute_envs);

// Attempt to detect a single environment based on a weighting.
let compute_env = detect_one(MAX_INDIVIDUAL_WEIGHTING);
println!("{:?}", compute_env);

Detectors

The following environments are able to be detected:

  • Amazon Elastic Compute Cloud (EC2)
  • Amazon Elastic Container Service (ECS)
  • AWS Lambda
  • Kubernetes on AWS
  • Nomad on AWS
  • Azure Containers Apps
  • Azure Container Apps Job
  • Azure Container Instance
  • Kubernetes on Azure
  • Azure VM
  • Nomad on Azure
  • Google Cloud Run (Gen1)
  • Google Cloud Run (Gen2)
  • Google Cloud Run (Job)
  • Google Compute Engine
  • Kubernetes on Google Cloud
  • Nomad on Google Cloud
  • Kubernetes
  • Nomad
  • QEMU

This library currently supports 2 detection methods: SMBIOS and Environment Variables.

SMBIOS

There are currently 3 data points read during detection on both Linux and Windows:

  • bios_vendor
  • product_name
  • sys_vendor

Threshold Weighting

A detection threshold is represented in the form of a u16, which has a max of 65535 (2^16-1) as defined in u16::MAX.

As we supported multiple detectors, the maximum returned total weighting is 2^15 in order to avoid thresholding and overflows when using multiple detectors. This is exposed as a constant MAX_TOTAL_WEIGHTING.

Dependencies

~0–27MB
~296K SLoC