Skip to content

Design Patterns

This section documents common design patterns and conventions used throughout the Meraki Dashboard Exporter codebase. These patterns provide consistency, maintainability, and help developers understand how to extend the system effectively.

Pattern Categories

Why Patterns Matter

Design patterns in the exporter serve several purposes:

Consistency

  • Predictable Structure: Developers know what to expect
  • Standard Approaches: Common problems have established solutions
  • Reduced Cognitive Load: Less decision-making for routine tasks

Maintainability

  • Easier Updates: Changes follow established patterns
  • Bug Prevention: Tested patterns reduce errors
  • Knowledge Transfer: New developers learn patterns once, apply everywhere

Extensibility

  • Plugin Architecture: New collectors follow existing patterns
  • API Evolution: Patterns adapt to API changes
  • Feature Addition: New features build on proven foundations

Pattern Principles

Error Handling

All API interactions use consistent error handling patterns:

@with_error_handling(
    operation="Description of operation",
    continue_on_error=True,  # or False for critical operations
    error_category=ErrorCategory.API_CLIENT_ERROR
)
async def operation():
    # Implementation

Metric Ownership

Each collector owns and manages its specific metrics:

def _initialize_metrics(self) -> None:
    """Initialize metrics owned by this collector."""
    self._my_metric = self._create_gauge(
        MetricName.MY_METRIC,
        "Description",
        labelnames=[LabelName.ORG_ID]
    )

API Response Validation

All API responses are validated using consistent patterns:

validated_data = validate_response_format(
    response_data,
    expected_type=list,
    operation="getOrganizationDevices"
)

Using Patterns

When developing new features:

  1. Check Existing Patterns: Look for similar functionality
  2. Follow Conventions: Use established naming and structure
  3. Validate Responses: Always validate API data
  4. Handle Errors: Use the error handling decorator
  5. Document Deviations: Explain why you departed from patterns

Pattern Guidelines

  • Patterns should be documented with examples
  • Prefer composition over inheritance
  • Keep patterns simple and focused
  • Update patterns when you find better approaches