Metadata-Version: 2.4
Name: unacast-modeled-metrics-monitoring
Version: 0.1.0
Summary: A library for monitoring modeled metrics with Google Cloud Monitoring
Author-email: Jan Hajny <jan.hajny@unacast.com>
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: google-auth>=2.24.0
Requires-Dist: google-cloud-monitoring>=2.0.0
Requires-Dist: google-cloud-resource-manager>=1.14.2
Requires-Dist: PyYAML>=6.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: autopep8>=2.0.0; extra == "dev"
Requires-Dist: types-PyYAML>=6.0.0; extra == "dev"
Requires-Dist: types-requests>=2.32.0; extra == "dev"
Dynamic: license-file

# Modeled Metrics Monitoring Library

A Python library for monitoring modeled metrics with Google Cloud Monitoring.

## Overview

This library provides a Python interface for working with Google Cloud Monitoring metric descriptors and writing metrics. It queries the Google Cloud Monitoring API to retrieve metric descriptors.

## Key Features

- **Direct API Integration**: Queries Google Cloud Monitoring API for metric descriptors
- **Type Safety**: Uses Google's protobuf `MetricDescriptor` objects
- **Flexible Metric Writing**: Supports all metric value types (BOOL, INT64, DOUBLE, STRING, DISTRIBUTION)
- **Error Handling**: Comprehensive exception handling for Google Cloud API errors

## Usage

### Development

```bash
# Install in development mode
pip install -e .

# Run the example
python -m modeled_metrics_monitoring.run
```

### Building and Distribution

```bash
# Build the package
./build.sh

# Install the built package
pip install dist/*.whl
```

### Using the Library

```python
from modeled_metrics_monitoring import get_metric_descriptor_by_type, write_metric

# Get a metric descriptor by type
descriptor = get_metric_descriptor_by_type(
    "custom.googleapis.com/contextual-data-monitoring/modeled-metrics-ml-ops/vertex_pipeline/foot_traffic/feature_null_ratio"
)

# Write a metric
write_metric(
    descriptor,
    0.1,
    metric_labels={
        "feature_group_id": "temporal",
        "feature_group_revision": "r0_1",
        "feature_id": "is_weekend"
    }
)

# Or write a metric using the type string directly
write_metric(
    "custom.googleapis.com/contextual-data-monitoring/modeled-metrics-ml-ops/vertex_pipeline/foot_traffic/feature_null_ratio",
    0.1,
    metric_labels={
        "feature_group_id": "temporal",
        "feature_group_revision": "r0_1",
        "feature_id": "is_weekend"
    }
)
```

## Architecture

- **Terraform**: Uses YAML files from `monitoring-metrics-definitions/metric-descriptors/*.yaml` to create metric descriptors in Google Cloud Monitoring
- **Python Library**: Queries Google Cloud Monitoring API directly to retrieve metric descriptors
- **Separation of Concerns**: Terraform handles infrastructure (creating metric descriptors), Python library handles runtime operations (querying and writing metrics)

This approach ensures that the Python library is always working with the current state of metric descriptors in Google Cloud Monitoring, while Terraform manages the infrastructure definitions.
