/Cloud Saver

Cloud Saver

3
v0.1.3

Traefik Cloud Saver Plugin

Traefik Cloud Saver
Automatically scale down idle cloud resources to reduce costs

πŸ’Έ Think of it as "turning the lights off when the room is empty." πŸ’Έ

Build Status Go Report Card License

πŸš€ Features

  • πŸ“Š Real-time traffic monitoring for Traefik services
  • πŸ’€ Automatic instance shutdown during low traffic periods
  • βš™οΈ Configurable thresholds and monitoring windows
  • πŸ”œ Service-specific monitoring with router filtering (coming soon)
  • πŸ“ Detailed debug logging

🌩️Supported Clouds

  • βœ… Google Cloud Platform (GCP)
  • πŸ§ͺ Mock Provider (for testing)
  • πŸ”œ AWS (coming soon)
  • πŸ”œ Azure (coming soon)

πŸ“‘ Table of Contents

πŸ”§ Quick Start

  1. Install the plugin
# Static configuration
experimental:
localPlugins:
traefik_cloud_saver:
moduleName: github.com/danbiagini/traefik-cloud-saver
version: v0.1.0
  1. Configure the plugin
providers:
plugin:
traefik_cloud_saver:
windowSize: 1m
metricsURL: http://localhost:8080/metrics
apiURL: http://localhost:8080/api
trafficThreshold: 1
debug: true
cloudConfig:
type: gcp
region: <your-region>
zone: <your-zone>
credentials:
secret: <path-to-service-account-json-file>
type: service_account

You need to provide a service account json file in the container, for example at /etc/gcp/test_service_account.json, or use a different path, but change the secret path in the above config.

πŸ” How It Works

  1. Traffic Monitoring: Continuously monitors request rates through Traefik's metrics
  2. Threshold Analysis: Compares traffic against configured thresholds
  3. Scale Decision: Triggers scale-down when traffic drops below threshold
  4. Cloud Integration: Executes scaling through cloud provider APIs

πŸ› Troubleshooting

Common Issues

  1. Plugin Not Loading

    • Verify plugin configuration in Traefik
    • Check logs for initialization errors
  2. Scaling Not Working

    • Confirm cloud credentials are valid
    • Check traffic thresholds
    • Enable debug logging

Debug Logging

Enable debug logging in configuration:

debug: true

Logs

The plugin logs to traefik logs, search for traefik-cloud-saver in the logs.

Integration Validator

There is an integration test that can be run to check that the GCE credentials are valid. See the file compute_integration_test.go for details on how to run it.

πŸ› οΈ Development

Prerequisites

  • Go 1.x
  • Docker
  • Access to a cloud provider account

Building

# Install dependencies
make vendor
# Run tests
make test
# Build test container
make build-test-container

πŸ”¬ Testing

Unit Tests

make test

Integration Tests

# Set up GCP credentials first
make integration-test

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“œ License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

Copyright 2024 Dan Biagini

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

πŸ™ Acknowledgments

  • Traefik team for their amazing reverse proxy
  • Contributors and users of this plugin